Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Generator to Evolution #364

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ profilingData*

# ignore macos DS_Store files
.DS_Store

# Python cache
__pycache__/

# Generator survey example
generator/examples/survey/
186 changes: 186 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Update Main",
"dependsOrder": "sequence",
"dependsOn": [
"Git Checkout Main",
"Git Pull Origin Main",
"Yarn Reset Submodules",
"Yarn Install Dependencies",
"Yarn Compile",
"Yarn Migrate"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Start Dev Terminals",
"type": "shell",
"command": "",
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn": [
"Compile Dev",
"Build Dev",
"Start"
]
},
{
"label": "Start Dev Admin Terminals",
"type": "shell",
"dependsOn": [
"Compile Dev",
"Build Dev Admin",
"Start Admin"
],
"group": {
"kind": "build",
"isDefault": true
},
"command": "yarn build:admin:dev && yarn start:admin --port 8082"
},
{
"label": "Compile Dev",
"type": "shell",
"command": "yarn",
"args": [
"compile:dev"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Build Dev",
"type": "shell",
"command": "yarn",
"args": [
"build:dev"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Build Dev Admin",
"type": "shell",
"command": "yarn",
"args": [
"build:admin:dev"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Start",
"type": "shell",
"command": "yarn",
"args": [
"start"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Start Admin",
"type": "shell",
"command": "yarn",
"args": [
"start:admin",
"--port",
"8082"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Git Checkout Main",
"type": "shell",
"command": "git",
"args": [
"checkout",
"main"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Git Pull Origin Main",
"type": "shell",
"command": "git",
"args": [
"pull",
"origin",
"main"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Yarn Reset Submodules",
"type": "shell",
"command": "yarn",
"args": [
"reset-submodules"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Yarn Install Dependencies",
"type": "shell",
"command": "yarn",
"args": [
"install"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Yarn Compile",
"type": "shell",
"command": "yarn",
"args": [
"compile"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "Yarn Migrate",
"type": "shell",
"command": "yarn",
"args": [
"migrate"
],
"group": {
"kind": "build",
"isDefault": false
}
}
]
}
20 changes: 14 additions & 6 deletions generator/generator.md → generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ The Generator is designed to simplify and expedite your workflow. It allows for

To run this script, follow these steps:

1. Copy `generateSurveyExample.xlsx` to your project.
1. Install all the Python dependencies from `requirements.txt`

```bash
pip install -r <path/to/evolution>/generator/requirements.txt
```

<!-- TODO: Create a new section titled "Start your own survey" and move steps 2 and 3 into that section -->

2. Copy `generateSurveyExample.xlsx` to your project.

For Windows users:

Expand All @@ -45,7 +53,7 @@ To run this script, follow these steps:
cp ./evolution/generator/example/generateSurveyExample.xlsx ./survey/src/survey/references/generateSurveyExample.xlsx
```

2. Copy `generatorConfig.yaml` to your project.
3. Copy `generatorConfig.yaml` to your project.

For Windows users:

Expand All @@ -61,7 +69,7 @@ To run this script, follow these steps:
cp ./evolution/generator/example/generatorConfig.yaml ./survey/src/survey/config/generatorConfig.yaml
```

3. Navigate to the root folder of your project and run the following command:
4. Navigate to the root folder of your project and run the following command:

```bash
yarn generateSurvey
Expand Down Expand Up @@ -135,7 +143,7 @@ export const end_email: inputTypes.InputString = {
...defaultInputBase.inputStringBase,
path: 'end.email',
label: (t: TFunction) => t('end:end.email'),
conditional: customConditionals.hasAcceptGivingEmailConditional,
conditional: conditionals.hasAcceptGivingEmailConditional,
validations: validations.emailValidation
};
```
Expand Down Expand Up @@ -175,10 +183,10 @@ In this example, we are creating a conditional named `hasDrivingLicenseCondition
The corresponding TypeScript code for this conditional is shown below:

```typescript
// customConditionals.tsx
// conditionals.tsx
export const hasDrivingLicenseConditional: Conditional = (interview, path) => {
const relativePath = path.substring(0, path.lastIndexOf(".")); // Remove the last key from the path
return checkConditionals({
return createConditionals({
interview,
conditionals: [
{
Expand Down
28 changes: 28 additions & 0 deletions generator/common/customWidgets.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2024, Polytechnique Montreal and contributors
*
* This file is licensed under the MIT License.
* License text available at https://opensource.org/licenses/MIT
*/
import { TFunction } from 'i18next';
import { getI18nContext } from 'evolution-interviewer/lib/client/config/i18nextExtra.config';
import defaultConditional from 'evolution-common/lib/services/surveyGenerator/common/defaultConditional';
import * as inputTypes from 'evolution-common/lib/services/surveyGenerator/types/inputTypes';
import * as validations from './validations';

export const home_postalCode: inputTypes.InputString = {
type: 'question',
inputType: 'string',
path: 'home.postalCode',
datatype: 'string',
twoColumns: false,
textTransform: 'uppercase',
containsHtml: true,
label: (t: TFunction) => t('home:home.postalCode', { context: getI18nContext() }),
validations: validations.postalCodeValidation,
conditional: defaultConditional,
inputFilter: (value) => {
// Only accept postal code from Quebec
return value.replace(/[^a-zA-Z0-9]/g, '').substring(0, 6);
}
};
Loading
Loading