-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcolumns-definitions.ts
More file actions
81 lines (77 loc) · 2.7 KB
/
columns-definitions.ts
File metadata and controls
81 lines (77 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Copyright (c) 2026, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { Parameters, ColumnsDef, ID, NAME, DESCRIPTION, ACTIVATED } from '../parameter-table';
import { ElementType } from '../../../../utils';
import { CONTINGENCY_LISTS_INFOS, CONTINGENCY_LISTS } from '../constants';
import * as yup from 'yup';
import { IdName, ContingencyListsInfos } from './types';
export const COLUMNS_DEFINITIONS_CONTINGENCY_LISTS_INFOS: ColumnsDef[] = [
{
label: 'ContingencyLists',
dataKey: CONTINGENCY_LISTS,
initialValue: [],
editable: true,
directoryItems: true,
elementType: ElementType.CONTINGENCY_LIST,
titleId: 'ContingencyListsSelection',
},
{
label: 'description',
dataKey: DESCRIPTION,
initialValue: '',
editable: true,
descriptionItems: true,
width: '8rem',
},
{
label: 'Active',
dataKey: ACTIVATED,
initialValue: true,
checkboxItems: true,
editable: true,
width: '4rem',
},
];
export const ParamContingencyLists: Parameters = {
columnsDef: COLUMNS_DEFINITIONS_CONTINGENCY_LISTS_INFOS,
name: CONTINGENCY_LISTS_INFOS,
};
export const getContingencyListsInfosFormSchema = () => {
return yup
.object()
.shape({
[CONTINGENCY_LISTS_INFOS]: yup.array().of(
yup.object().shape({
[CONTINGENCY_LISTS]: yup
.array()
.of(
yup.object().shape({
[ID]: yup.string().required(),
[NAME]: yup.string().required(),
})
)
.required()
.min(1, 'FieldIsRequired'),
[DESCRIPTION]: yup.string(),
[ACTIVATED]: yup.boolean().required(),
})
),
})
.required();
};
export const toFormValuesContingencyListsInfos = (contingencyListsInfos: ContingencyListsInfos[]) => {
return {
[CONTINGENCY_LISTS_INFOS]: contingencyListsInfos?.map((contingencyListInfos: ContingencyListsInfos) => ({
[CONTINGENCY_LISTS]: contingencyListInfos[CONTINGENCY_LISTS]?.map((c: IdName) => ({
[NAME]: c[NAME],
[ID]: c[ID],
})),
[DESCRIPTION]: contingencyListInfos[DESCRIPTION],
[ACTIVATED]: contingencyListInfos[ACTIVATED],
})),
};
};