Skip to content

Commit

Permalink
feat: Add extendedVarType management for ScenarioParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
jreynard-code committed Oct 26, 2021
1 parent 50cbc1d commit 2b2b8bb
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
26 changes: 26 additions & 0 deletions doc/scenarioParameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,32 @@ const PARAMETERS = {
};
```

### Improve mapping between varTypes and factories

You may have to define a specific input component regarding a specific parameter.
To do this, you can add a property to your parameter configuration:
- `extendedVarType` (optional): define extra information on varType to enhance mapping between varType <-> InputFactory

Example:

```
const PARAMETERS = {
initial_stock_dataset: {
connectorId: 'C-xxxxxxxxxx',
defaultFileTypeFilter: '.zip,.csv,.json,.xls,.xlsx',
description: 'Initial stock dataset part'
extendedVarType: 'TABLE'
},
};
```

After that, you'll have to handle this `extendedVarType` properly by defining:
- a conversion method in `ConversionFromString.js` file
- a conversion method in `ConversionToString.js` file
- an entry in `CUSTOM_VAR_TYPES_EXTENSION` constant in `DefaultValues.js` file
- an entry in `CUSTOM_VAR_TYPES_FACTORIES_MAPPING` constant in `FactoriesMapping.js` file
- define your own `inputComponentsFactories`

### Configure input components for Cypress tests

If you want to add Cypress tests for your solution and test the scenario parameters input components, you can add a
Expand Down
11 changes: 11 additions & 0 deletions src/utils/ConfigUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ export const addTranslationLabels = (config) => {
_addTranslationParametersLabels(config);
};

const buildExtendedVarType = (varType, extension) => {
if (varType) {
if (extension) {
return varType + '-' + extension;
}
return varType;
}
return undefined;
};

export const ConfigUtils = {
addTranslationLabels,
buildExtendedVarType,
};
25 changes: 25 additions & 0 deletions src/utils/__test__/ConfigUtils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Cosmo Tech.
// Licensed under the MIT license.

import { ConfigUtils } from '../ConfigUtils';

describe('buildExtendedVarType with possible values', () => {
test.each`
varType | extension | expectedRes
${null} | ${null} | ${undefined}
${null} | ${undefined} | ${undefined}
${null} | ${''} | ${undefined}
${null} | ${'extension'} | ${undefined}
${''} | ${null} | ${undefined}
${''} | ${undefined} | ${undefined}
${''} | ${''} | ${undefined}
${''} | ${'extension'} | ${undefined}
${'varType'} | ${null} | ${'varType'}
${'varType'} | ${undefined} | ${'varType'}
${'varType'} | ${''} | ${'varType'}
${'varType'} | ${'extension'} | ${'varType-extension'}
`('if "$varType" and "$extension" then "$expectedRes"', ({ varType, extension, expectedRes }) => {
const res = ConfigUtils.buildExtendedVarType(varType, extension);
expect(res).toStrictEqual(expectedRes);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@

import { DATASET_ID_VARTYPE } from '../../../services/config/ApiConstants';
import { VAR_TYPES_FACTORIES_MAPPING } from '../FactoriesMapping';
import { ConfigUtils } from '../../ConfigUtils';

const create = (t, datasets, parameterData, parametersState, setParametersState, editMode) => {
const varTypeFactory = VAR_TYPES_FACTORIES_MAPPING[parameterData.varType];
const parameterVarType = ConfigUtils.buildExtendedVarType(parameterData.varType, parameterData.extendedVarType);

const varTypeFactory = VAR_TYPES_FACTORIES_MAPPING[parameterVarType];

if (varTypeFactory === undefined) {
console.warn('No factory defined for varType ' + parameterData.varType);
console.warn('No factory defined for varType ' + parameterVarType);
return null;
}
if (varTypeFactory === null) {
return null;
}

if (parameterData.varType === DATASET_ID_VARTYPE) {
if (parameterVarType === DATASET_ID_VARTYPE) {
return varTypeFactory.create(t, datasets, parameterData, parametersState, setParametersState, editMode);
}
return varTypeFactory.create(t, parameterData, parametersState, setParametersState, editMode);
Expand Down

0 comments on commit 2b2b8bb

Please sign in to comment.