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

feat: dynamic unit on input number #803

Merged
merged 12 commits into from
Dec 18, 2024
8 changes: 8 additions & 0 deletions src/constants/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,18 @@ const dictionary = {
en: 'Please respect the date format',
fr: 'Merci de respecter le format de la date',
},
dynamicUnit: {
en: 'Custom unit of measure',
fr: 'Unité de mesure personnalisée',
},
unit: {
en: 'Unit of measure',
fr: 'Unité de mesure',
},
dynamicUnitFormula: {
en: 'Formula of the unit of measure',
fr: "Formule de l'unité de mesure",
},
unitEmptySelect: {
en: 'Select an unit of measure',
fr: 'Sélectionnez une unité de mesure',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const VTLEditor = ({
label,
input,
required,
disabled,
setDisableValidation,
}) => {
const [errors, setErrors] = useState([]);
Expand Down Expand Up @@ -61,7 +62,9 @@ const VTLEditor = ({
{required && <span className="ctrl-required">*</span>}
</label>
<div>
<div className="editor-container">
<div
className={`editor-container ${disabled ? 'editor-disabled' : ''}`}
>
<AntlrEditor
script={value}
setScript={localOnChange}
Expand All @@ -79,12 +82,14 @@ const VTLEditor = ({
lineDecorationsWidth: 0,
lineNumbersMinChars: 0,
renderLineHighlight: 'none',
readOnly: disabled,
}}
/>
</div>
</div>
<div style={{ color: 'red', display: 'inline-block' }}>
{value &&
!disabled &&
errors.map(({ line, column, message }) => (
<div key={`${line}_${column}`} style={{ marginBottom: '20px' }}>
<div>{`Ligne : ${line} - Colonne : ${column}`}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const defaultForm = {
minimum: '',
maximum: '',
decimals: '',
isDynamicUnit: false,
unit: '',
},
[DATE]: {
Expand Down
1 change: 1 addition & 0 deletions src/model/formToState/component-new-edit/typage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const defaultTypageForm = {
minimum: '',
maximum: '',
decimals: '',
isDynamicUnit: false,
unit: '',
},
[DATE]: {
Expand Down
5 changes: 5 additions & 0 deletions src/model/transformations/calculated-variable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export function remoteToStore(remote = []) {
Maximum: maximum,
Decimals: decimals,
Unit: unit,
IsDynamicUnit: isDynamicUnit,
Format: format,
},
} = cv;
Expand All @@ -43,6 +44,7 @@ export function remoteToStore(remote = []) {
maximum,
decimals,
unit,
isDynamicUnit,
format,
},
},
Expand All @@ -66,6 +68,7 @@ export function storeToRemote(store) {
minimum: Minimum,
maximum: Maximum,
decimals: Decimals,
isDynamicUnit: IsDynamicUnit,
unit: Unit,
format: Format,
},
Expand All @@ -88,6 +91,8 @@ export function storeToRemote(store) {
if (Maximum !== undefined) model.Datatype.Maximum = Maximum;
if (Decimals !== undefined) model.Datatype.Decimals = Decimals;
if (Unit !== undefined) model.Datatype.Unit = Unit;
if (IsDynamicUnit !== undefined)
model.Datatype.IsDynamicUnit = IsDynamicUnit;
if (Format !== undefined) model.Datatype.Format = Format;
if (Scope) model.Scope = Scope;
return model;
Expand Down
142 changes: 70 additions & 72 deletions src/model/transformations/calculated-variable.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../constants/pogues-constants';
import { remoteToStore, storeToRemote } from './calculated-variable';

const { TEXT } = DATATYPE_NAME;
const { TEXT, NUMERIC } = DATATYPE_NAME;

const { CALCULATED } = VARIABLES_TYPES;

Expand All @@ -22,11 +22,6 @@ describe('calculated variables tranformations', () => {
Datatype: {
MaxLength: 2,
Pattern: '',
Minimum: '',
Maximum: '',
Decimals: '',
Unit: '',
Format: '',
type: 'TextDatatypeType',
typeName: TEXT,
},
Expand All @@ -38,15 +33,13 @@ describe('calculated variables tranformations', () => {
Formula: 'formula 2',
Scope: 'jbcggtca',
Datatype: {
MaxLength: 2,
Pattern: '',
Minimum: '',
Maximum: '',
Minimum: '1',
Maximum: '10',
Decimals: '',
Unit: '',
Format: '',
type: 'TextDatatypeType',
typeName: TEXT,
IsDynamicUnit: false,
Unit: 'euro',
type: 'NumericDatatypeType',
typeName: NUMERIC,
},
},
{
Expand All @@ -55,15 +48,13 @@ describe('calculated variables tranformations', () => {
Name: 'name 3',
Formula: 'formula 3',
Datatype: {
MaxLength: 3,
Pattern: '',
Minimum: '',
Maximum: '',
Decimals: '',
Unit: '',
Format: '',
type: 'TextDatatypeType',
typeName: TEXT,
Minimum: '1',
Maximum: '10',
Decimals: '2',
IsDynamicUnit: true,
Unit: 'my formula',
type: 'NumericDatatypeType',
typeName: NUMERIC,
},
},
];
Expand All @@ -79,11 +70,6 @@ describe('calculated variables tranformations', () => {
[TEXT]: {
maxLength: 2,
pattern: '',
minimum: '',
maximum: '',
decimals: '',
unit: '',
format: '',
},
},
2: {
Expand All @@ -92,15 +78,13 @@ describe('calculated variables tranformations', () => {
name: 'name 2',
formula: 'formula 2',
scope: 'jbcggtca',
type: TEXT,
[TEXT]: {
maxLength: 2,
pattern: '',
minimum: '',
maximum: '',
type: NUMERIC,
[NUMERIC]: {
minimum: '1',
maximum: '10',
decimals: '',
unit: '',
format: '',
isDynamicUnit: false,
unit: 'euro',
},
},
3: {
Expand All @@ -109,15 +93,13 @@ describe('calculated variables tranformations', () => {
name: 'name 3',
formula: 'formula 3',
scope: '',
type: TEXT,
[TEXT]: {
maxLength: 3,
pattern: '',
minimum: '',
maximum: '',
decimals: '',
unit: '',
format: '',
type: NUMERIC,
[NUMERIC]: {
minimum: '1',
maximum: '10',
decimals: '2',
isDynamicUnit: true,
unit: 'my formula',
},
},
});
Expand Down Expand Up @@ -145,31 +127,27 @@ describe('calculated variables tranformations', () => {
Name: 'name 2',
Formula: 'formula 2',
Datatype: {
MaxLength: 3,
Pattern: '',
Minimum: '',
Maximum: '',
Minimum: '1',
Maximum: '10',
Decimals: '',
Unit: '',
Format: '',
type: 'TextDatatypeType',
typeName: TEXT,
IsDynamicUnit: false,
Unit: 'euro',
type: 'NumericDatatypeType',
typeName: NUMERIC,
},
},
{
Label: 'label 3',
Name: 'name 3',
Formula: 'formula 3',
Datatype: {
MaxLength: 3,
Pattern: '',
Minimum: '',
Maximum: '',
Decimals: '',
Unit: '',
Format: '',
type: 'TextDatatypeType',
typeName: TEXT,
Minimum: '1',
Maximum: '10',
Decimals: '2',
IsDynamicUnit: true,
Unit: 'my formula',
type: 'NumericDatatypeType',
typeName: NUMERIC,
},
},
];
Expand All @@ -194,16 +172,28 @@ describe('calculated variables tranformations', () => {
name: 'name 2',
formula: 'formula 2',
scope: 'jbcggtca',
type: TEXT,
[TEXT]: { maxLength: 2 },
type: NUMERIC,
[NUMERIC]: {
minimum: '1',
maximum: '10',
decimals: '',
isDynamicUnit: false,
unit: 'euro',
},
},
3: {
id: '3',
label: 'label 3',
name: 'name 3',
formula: 'formula 3',
type: TEXT,
[TEXT]: { maxLength: 3 },
type: NUMERIC,
[NUMERIC]: {
minimum: '1',
maximum: '10',
decimals: '2',
isDynamicUnit: true,
unit: 'my formula',
},
},
};

Expand All @@ -228,9 +218,13 @@ describe('calculated variables tranformations', () => {
type: CALCULATED,
Scope: 'jbcggtca',
Datatype: {
MaxLength: 2,
type: 'TextDatatypeType',
typeName: TEXT,
Minimum: '1',
Maximum: '10',
Decimals: '',
IsDynamicUnit: false,
Unit: 'euro',
type: 'NumericDatatypeType',
typeName: NUMERIC,
},
},
{
Expand All @@ -240,9 +234,13 @@ describe('calculated variables tranformations', () => {
Formula: 'formula 3',
type: CALCULATED,
Datatype: {
MaxLength: 3,
type: 'TextDatatypeType',
typeName: TEXT,
Minimum: '1',
Maximum: '10',
Decimals: '2',
IsDynamicUnit: true,
Unit: 'my formula',
type: 'NumericDatatypeType',
typeName: NUMERIC,
},
},
]);
Expand Down
3 changes: 3 additions & 0 deletions src/model/transformations/collected-variable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export function storeToRemote(store, componentsStore) {
maximum: Maximum,
decimals: Decimals,
format: Format,
isDynamicUnit: IsDynamicUnit,
unit: Unit,
miyears: Miyears,
mimonths: Mimonths,
Expand Down Expand Up @@ -296,6 +297,8 @@ export function storeToRemote(store, componentsStore) {
if (Maximum !== undefined) model.Datatype.Maximum = Maximum;
}
if (Decimals !== undefined) model.Datatype.Decimals = Decimals;
if (IsDynamicUnit !== undefined)
model.Datatype.IsDynamicUnit = IsDynamicUnit;
if (Unit !== undefined) model.Datatype.Unit = Unit;
if (Format !== undefined) {
if (typeName === DATATYPE_NAME.DATE) {
Expand Down
Loading
Loading