Skip to content

Commit

Permalink
feat: add VTL formula for primary table dimension (#857)
Browse files Browse the repository at this point in the history
* feat: add VTL formula for primary table dimension

* fix: do not save isFixedLength for non_dynamic table

* test: fix tests

* test: add new tests

* refactor : remove unused table props 'totalLabel' & 'showTotalLabel'

see b7e4a97

* refactor :  remove unused table props 'totalLabel' & 'showTotalLabel'

see b7e4a97

* refactor : update form structure

* fix: uppercase in model variables + rename min/max

* test : update current tests & add new tests

* fix: wrong field label for linesNbCalculation

* chore: remove commented code
  • Loading branch information
QRuhier authored Nov 7, 2024
1 parent 811813d commit 9532e22
Show file tree
Hide file tree
Showing 15 changed files with 789 additions and 240 deletions.
7 changes: 6 additions & 1 deletion src/actions/metadata.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DIMENSION_LENGTH } from '../constants/pogues-constants';
import {
getUnitsList,
getSeries,
Expand All @@ -9,6 +10,7 @@ import {
getNomenclature,
} from '../utils/remote-api';

const { NON_DYNAMIC } = DIMENSION_LENGTH;
export const LOAD_METADATA_SUCCESS = 'LOAD_METADATA_SUCCESS';
export const LOAD_METADATA_FAILURE = 'LOAD_METADATA_FAILURE';
const LOAD_SERIES = 'LOAD_SERIES';
Expand Down Expand Up @@ -212,7 +214,10 @@ const isQuestionLoop = component => {
component.type === 'QuestionType' &&
((component.questionType === 'TABLE' &&
component.ResponseStructure.Dimension.some(
dim => dim.dimensionType === 'PRIMARY' && dim.dynamic !== '0',
dim =>
dim.dimensionType === 'PRIMARY' &&
dim.dynamic !== '0' &&
dim.dynamic !== NON_DYNAMIC,
)) ||
component.questionType === 'PAIRING')
);
Expand Down
24 changes: 8 additions & 16 deletions src/constants/dictionary.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,14 @@ const dictionary = {
fr: 'Liste',
en: 'List',
},
minMax: {
fr: 'Min/Max',
en: 'Min/max',
},
linesNbCalculation: {
fr: 'Calcul du nombre de lignes',
en: 'Calculation of number of lines',
},
minRowNb: {
fr: 'Nombre de lignes min.',
en: 'Number of lines min.',
Expand All @@ -883,22 +891,6 @@ const dictionary = {
fr: 'Nombre de lignes max.',
en: 'Number of lines max.',
},
rowTotal: {
fr: 'Ajouter la ligne "Total"',
en: 'Add the "Total" row',
},
rowTotalLabel: {
fr: 'Libellé de la ligne "Total"',
en: 'Label of the "Total" row',
},
columnTotal: {
fr: 'Ajouter la colonne "Total"',
en: 'Add the "Total" column',
},
columnTotalLabel: {
fr: 'Libellé de la colonne "Total"',
en: 'Label of the "Total" column',
},
addScndAxis: {
fr: 'Ajouter un axe secondaire',
en: 'Add a secondary axis',
Expand Down
6 changes: 6 additions & 0 deletions src/constants/pogues-constants.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export const DIMENSION_FORMATS = {
BOOL: 'BOOL',
};

export const DIMENSION_LENGTH = {
NON_DYNAMIC: 'NON_DYNAMIC',
DYNAMIC_LENGTH: 'DYNAMIC_LENGTH',
FIXED_LENGTH: 'FIXED_LENGTH',
};

export const QUESTION_TYPE_ENUM = {
SIMPLE: 'SIMPLE',
SINGLE_CHOICE: 'SINGLE_CHOICE',
Expand Down
90 changes: 42 additions & 48 deletions src/model/formToState/component-new-edit/response-format-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ import cloneDeep from 'lodash.clonedeep';
import merge from 'lodash.merge';
import { verifyVariable } from '../../../utils/utils';

import { Factory as CodesListFactory } from '../..';
import { Factory as CodesListFactory } from '../codes-lists/codes-list';
import {
DATATYPE_NAME,
DATATYPE_VIS_HINT,
DEFAULT_CODES_LIST_SELECTOR_PATH,
DIMENSION_FORMATS,
DIMENSION_LENGTH,
DIMENSION_TYPE,
QUESTION_TYPE_ENUM,
UI_BEHAVIOUR,
} from '../../../constants/pogues-constants';

const { PRIMARY, SECONDARY, MEASURE, LIST_MEASURE } = DIMENSION_TYPE;
const { LIST, CODES_LIST } = DIMENSION_FORMATS;
const { DYNAMIC_LENGTH, FIXED_LENGTH } = DIMENSION_LENGTH;
const { SIMPLE, SINGLE_CHOICE } = QUESTION_TYPE_ENUM;
const { DATE, NUMERIC, TEXT, BOOLEAN, DURATION } = DATATYPE_NAME;
const { RADIO } = DATATYPE_VIS_HINT;
Expand Down Expand Up @@ -80,24 +82,28 @@ export const defaultMeasureForm = {
},
};

const defaultPrimaryListState = {
type: DYNAMIC_LENGTH,
[DYNAMIC_LENGTH]: {
minLines: 0,
maxLines: 0,
},
[FIXED_LENGTH]: {
fixedLength: '',
},
};

export const defaultState = {
[PRIMARY]: {
showTotalLabel: '0',
totalLabel: '',
type: LIST,
[LIST]: {
numLinesMin: 0,
numLinesMax: 0,
},
[LIST]: defaultPrimaryListState,
[CODES_LIST]: {
// [DEFAULT_CODES_LIST_SELECTOR_PATH]: cloneDeep(CodesListDefaultState),
},
},
[SECONDARY]: {
// [DEFAULT_CODES_LIST_SELECTOR_PATH]: cloneDeep(CodesListDefaultState),
showSecondaryAxis: false,
showTotalLabel: '0',
totalLabel: '',
},
[LIST_MEASURE]: {
...defaultMeasureState,
Expand All @@ -107,17 +113,23 @@ export const defaultState = {
};

export function formToStatePrimary(form, codesListPrimary) {
const { showTotalLabel, totalLabel, type, [type]: primaryForm } = form;
const { type, [type]: primaryForm } = form;

const state = {
showTotalLabel,
totalLabel,
type,
};

if (type === LIST) {
const { numLinesMin, numLinesMax } = primaryForm;
state[LIST] = { numLinesMin, numLinesMax };
const {
type: listType,
[listType]: { minLines, maxLines, fixedLength },
} = primaryForm;

state[LIST] = {
type: listType,
[listType]:
listType === DYNAMIC_LENGTH ? { minLines, maxLines } : { fixedLength },
};
} else {
const { [DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListForm } = primaryForm;
state[CODES_LIST] = {
Expand All @@ -132,14 +144,10 @@ export function formToStatePrimary(form, codesListPrimary) {
export function formToStateSecondary(form, codesListSecondary) {
const {
showSecondaryAxis,
showTotalLabel,
totalLabel,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: codesListForm,
} = form;
return {
showSecondaryAxis,
showTotalLabel,
totalLabel,
[DEFAULT_CODES_LIST_SELECTOR_PATH]:
codesListSecondary.formToStateComponent(codesListForm),
};
Expand Down Expand Up @@ -210,11 +218,9 @@ export function formToState(form, transformers) {
}

export function stateToFormPrimary(currentState, codesListPrimary) {
const { showTotalLabel, totalLabel, type, [LIST]: listState } = currentState;
const { type, [LIST]: listState } = currentState;

return {
showTotalLabel,
totalLabel,
type,
[LIST]: { ...listState },
[CODES_LIST]: {
Expand All @@ -225,11 +231,9 @@ export function stateToFormPrimary(currentState, codesListPrimary) {
}

export function stateToFormSecondary(currentState, codesListSecondary) {
const { showSecondaryAxis, showTotalLabel, totalLabel } = currentState;
const { showSecondaryAxis } = currentState;
return {
showSecondaryAxis,
showTotalLabel,
totalLabel,
[DEFAULT_CODES_LIST_SELECTOR_PATH]:
codesListSecondary.stateComponentToForm(),
};
Expand Down Expand Up @@ -426,34 +430,28 @@ const Factory = (initialState = {}, codesListsStore) => {
getNormalizedValues: form => {
// Values ready to be validated
const {
[PRIMARY]: {
type: typePrimary,
[typePrimary]: primary,
showTotalLabel: showTotalLabelPrimary,
totalLabel: totalLabelPrimary,
},
[SECONDARY]: {
showSecondaryAxis,
showTotalLabel: showTotalLabelSecondary,
totalLabel: totalLabelSecondary,
...others
},
[PRIMARY]: { type: typePrimary, [typePrimary]: primary },
[SECONDARY]: { showSecondaryAxis, ...others },
[MEASURE]: measure,
[LIST_MEASURE]: { measures: listMeasures, ...listMeasuresInput },
} = form;

// Normalized primary axis values

const normalized = {
[PRIMARY]: {
const normalized = {};

if (typePrimary === CODES_LIST) {
normalized[PRIMARY] = {
type: typePrimary,
showTotalLabel: showTotalLabelPrimary,
[typePrimary]: primary,
},
};

if (showTotalLabelPrimary === '1') {
normalized[PRIMARY].totalLabel = totalLabelPrimary;
};
}
if (typePrimary === LIST) {
const { type: listType, [listType]: listContent } = primary;
normalized[PRIMARY] = {
type: typePrimary,
[typePrimary]: { type: listType, [listType]: listContent },
};
}

if (typePrimary === CODES_LIST && showSecondaryAxis) {
Expand All @@ -462,11 +460,7 @@ const Factory = (initialState = {}, codesListsStore) => {
normalized[SECONDARY] = {
...others,
showSecondaryAxis,
showTotalLabelSecondary,
};
if (showTotalLabelSecondary === '1') {
normalized[SECONDARY].totalLabel = totalLabelSecondary;
}

// Normalized measure axis values

Expand Down
11 changes: 9 additions & 2 deletions src/model/transformations/collected-variable.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,10 @@ describe('collected variable tranformations', () => {
},
],
PRIMARY: {
LIST: { numLinesMin: 4, numLinesMax: 2 },
LIST: {
DYNAMIC_LENGTH: { minLines: 2, maxLines: 4 },
type: 'DYNAMIC_LENGTH',
},
type: 'LIST',
},
},
Expand Down Expand Up @@ -983,7 +986,11 @@ describe('collected variable tranformations', () => {
},
],
PRIMARY: {
LIST: { numLinesMin: 4, numLinesMax: 2 },
LIST: {
DYNAMIC_LENGTH: { minLines: 0, maxLines: 0 },
FIXED_LENGTH: { fixedLength: '' },
type: 'DYNAMIC_LENGTH',
},
type: 'LIST',
},
},
Expand Down
26 changes: 18 additions & 8 deletions src/model/transformations/dimension.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import {
DIMENSION_TYPE,
DIMENSION_LENGTH,
DEFAULT_CODES_LIST_SELECTOR_PATH,
} from '../../constants/pogues-constants';

const { PRIMARY, SECONDARY, MEASURE } = DIMENSION_TYPE;
const { DYNAMIC_LENGTH, FIXED_LENGTH, NON_DYNAMIC } = DIMENSION_LENGTH;

export function stateToRemote(state) {
const {
type,
[DEFAULT_CODES_LIST_SELECTOR_PATH]: CodesListState,
numLinesMin,
numLinesMax,
showTotalLabel,
totalLabel,
fixedLength,
minLines,
maxLines,
label: Label,
} = state;
const model = {
Expand All @@ -21,9 +22,19 @@ export function stateToRemote(state) {

if (type === PRIMARY || type === SECONDARY) {
if (CodesListState) model.CodeListReference = CodesListState.id;
if (showTotalLabel && totalLabel) model.totalLabel = totalLabel;
if (numLinesMin !== undefined && numLinesMax !== undefined)
model.dynamic = `${numLinesMin}-${numLinesMax}`;
}

if (type === PRIMARY) {
if (fixedLength !== undefined) {
model.dynamic = FIXED_LENGTH;
model.FixedLength = fixedLength;
} else if (minLines !== undefined && maxLines !== undefined) {
model.MinLines = minLines;
model.MaxLines = maxLines;
model.dynamic = DYNAMIC_LENGTH;
} else {
model.dynamic = NON_DYNAMIC;
}
}

if (type === MEASURE && Label) {
Expand All @@ -32,7 +43,6 @@ export function stateToRemote(state) {

return {
dimensionType: '',
dynamic: '0',
...model,
};
}
Loading

0 comments on commit 9532e22

Please sign in to comment.