@centreon/ui 24.4.36 → 24.4.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Button/Icon/index.stories.tsx +1 -1
- package/src/Button/Icon/index.tsx +1 -1
- package/src/InputField/Select/IconPopover/index.tsx +1 -1
- package/src/Listing/ActionBar/index.tsx +1 -2
- package/src/Panel/index.tsx +1 -1
- package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.cypress.spec.tsx +23 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ContactSwitch.tsx +9 -1
- package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.styles.ts +8 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/useShareInput.tsx +4 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/models.ts +1 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/storiesData.ts +1 -0
- package/src/components/Form/index.ts +2 -2
- package/src/components/Form/AccessRights/AccessRights.resource.ts +0 -45
- package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +0 -59
- package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +0 -21
- package/src/components/Form/AccessRights/AccessRightsForm.tsx +0 -67
- package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +0 -80
- package/src/components/Form/AccessRights/Input/AddAction.tsx +0 -31
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +0 -54
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +0 -72
- package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +0 -22
- package/src/components/Form/AccessRights/Input/ContactInputField.tsx +0 -105
- package/src/components/Form/AccessRights/Input/RoleInputField.tsx +0 -29
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +0 -97
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +0 -71
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +0 -51
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +0 -116
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +0 -118
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +0 -26
- package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +0 -28
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +0 -18
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +0 -41
- package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -54
- package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +0 -18
- package/src/components/Form/AccessRights/common/GroupLabel.tsx +0 -15
- package/src/components/Form/AccessRights/common/Input.styles.ts +0 -48
- package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +0 -11
- package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +0 -57
- package/src/components/Form/AccessRights/index.ts +0 -3
- package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +0 -531
- package/src/components/Form/AccessRights/useAccessRightsForm.tsx +0 -282
- package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +0 -41
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.stories.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.styles.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.styles.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/useActions.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/Item.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.styles.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListItemSkeleton.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListSkeleton.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/RemoveAccessRight.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/StateChip.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/useItem.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Provider.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Stats/Stats.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/atoms.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.styles.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/useAccessRightsInitValues.ts +0 -0
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
import { ReactElement, ReactNode, useEffect, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
atom,
|
|
5
|
-
createStore,
|
|
6
|
-
Provider,
|
|
7
|
-
useAtom,
|
|
8
|
-
useAtomValue,
|
|
9
|
-
useSetAtom,
|
|
10
|
-
useStore
|
|
11
|
-
} from 'jotai';
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
ContactAccessRightResource,
|
|
15
|
-
ContactAccessRightStateResource,
|
|
16
|
-
ContactGroupResource,
|
|
17
|
-
ContactResource,
|
|
18
|
-
RoleResource
|
|
19
|
-
} from './AccessRights.resource';
|
|
20
|
-
import {
|
|
21
|
-
createInitialState,
|
|
22
|
-
sortOnAddedStateFirstAndContactName
|
|
23
|
-
} from './useAccessRightsForm.utils';
|
|
24
|
-
|
|
25
|
-
/** state */
|
|
26
|
-
|
|
27
|
-
type loadingState = 'idle' | 'loading';
|
|
28
|
-
|
|
29
|
-
const loadingStatusAtom = atom<loadingState>('idle');
|
|
30
|
-
|
|
31
|
-
type formOptions = {
|
|
32
|
-
contacts: Array<ContactResource | ContactGroupResource>;
|
|
33
|
-
roles: Array<RoleResource>;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const formOptionsAtom = atom<formOptions>({
|
|
37
|
-
contacts: [],
|
|
38
|
-
roles: []
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const contactAccessRightsAtom = atom<Array<ContactAccessRightStateResource>>(
|
|
42
|
-
[]
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
type StateStats = {
|
|
46
|
-
added: number;
|
|
47
|
-
removed: number;
|
|
48
|
-
updated: number;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const contactAccessRightsStateAtom = atom<{
|
|
52
|
-
isDirty: boolean;
|
|
53
|
-
isLoading: boolean;
|
|
54
|
-
stats: StateStats;
|
|
55
|
-
}>((get) => ({
|
|
56
|
-
isDirty: get(contactAccessRightsAtom).some(
|
|
57
|
-
({ state }) => state !== 'unchanged'
|
|
58
|
-
),
|
|
59
|
-
isLoading: get(loadingStatusAtom) === 'loading',
|
|
60
|
-
stats: {
|
|
61
|
-
added: get(contactAccessRightsAtom).filter(({ state }) => state === 'added')
|
|
62
|
-
.length,
|
|
63
|
-
removed: get(contactAccessRightsAtom).filter(
|
|
64
|
-
({ state }) => state === 'removed'
|
|
65
|
-
).length,
|
|
66
|
-
updated: get(contactAccessRightsAtom).filter(
|
|
67
|
-
({ state }) => state === 'updated'
|
|
68
|
-
).length
|
|
69
|
-
}
|
|
70
|
-
}));
|
|
71
|
-
|
|
72
|
-
type callbacks = {
|
|
73
|
-
onSubmit?: (values: Array<ContactAccessRightStateResource>) => void;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const callbacksAtom = atom<callbacks>({});
|
|
77
|
-
|
|
78
|
-
/** provider */
|
|
79
|
-
|
|
80
|
-
export type AccessRightsFormProviderProps = {
|
|
81
|
-
children: ReactNode;
|
|
82
|
-
initialValues?: Array<ContactAccessRightResource>;
|
|
83
|
-
loadingStatus?: loadingState;
|
|
84
|
-
onSubmit?: callbacks['onSubmit'];
|
|
85
|
-
options?: formOptions;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const AccessRightsFormProvider = ({
|
|
89
|
-
children,
|
|
90
|
-
initialValues,
|
|
91
|
-
options,
|
|
92
|
-
loadingStatus = 'idle',
|
|
93
|
-
onSubmit
|
|
94
|
-
}: AccessRightsFormProviderProps): ReactElement => {
|
|
95
|
-
const store = useRef(createStore()).current;
|
|
96
|
-
|
|
97
|
-
const setLoadingStatus = useSetAtom(loadingStatusAtom, { store });
|
|
98
|
-
const setFormOptions = useSetAtom(formOptionsAtom, { store });
|
|
99
|
-
const setContactAccessRights = useSetAtom(contactAccessRightsAtom, { store });
|
|
100
|
-
const setCallbacks = useSetAtom(callbacksAtom, { store });
|
|
101
|
-
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
setLoadingStatus(loadingStatus);
|
|
104
|
-
}, [loadingStatus]);
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
108
|
-
options && setFormOptions(options);
|
|
109
|
-
}, [options]);
|
|
110
|
-
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
113
|
-
onSubmit && setCallbacks({ onSubmit });
|
|
114
|
-
}, [onSubmit]);
|
|
115
|
-
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
setContactAccessRights(
|
|
118
|
-
initialValues ? createInitialState(initialValues) : []
|
|
119
|
-
);
|
|
120
|
-
}, [initialValues]);
|
|
121
|
-
|
|
122
|
-
return <Provider store={store}>{children}</Provider>;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/** hook */
|
|
126
|
-
|
|
127
|
-
type UseAccessRightsForm = {
|
|
128
|
-
addContactAccessRight: (
|
|
129
|
-
contactAccessRight: ContactAccessRightResource
|
|
130
|
-
) => void;
|
|
131
|
-
contactAccessRights: Array<ContactAccessRightStateResource>;
|
|
132
|
-
isDirty: boolean;
|
|
133
|
-
isLoading: boolean;
|
|
134
|
-
options: formOptions;
|
|
135
|
-
removeContactAccessRight: (
|
|
136
|
-
contactAccessRight: ContactAccessRightResource,
|
|
137
|
-
restore?: boolean
|
|
138
|
-
) => void;
|
|
139
|
-
stats: StateStats;
|
|
140
|
-
submit: () => void;
|
|
141
|
-
updateContactAccessRight: (
|
|
142
|
-
contactAccessRight: ContactAccessRightResource
|
|
143
|
-
) => void;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
const useAccessRightsForm = (): UseAccessRightsForm => {
|
|
147
|
-
const store = useStore();
|
|
148
|
-
|
|
149
|
-
const [contactAccessRights, setContactAccessRights] = useAtom(
|
|
150
|
-
contactAccessRightsAtom,
|
|
151
|
-
{ store }
|
|
152
|
-
);
|
|
153
|
-
const { isLoading, isDirty, stats } = useAtomValue(
|
|
154
|
-
contactAccessRightsStateAtom,
|
|
155
|
-
{ store }
|
|
156
|
-
);
|
|
157
|
-
const options = useAtomValue(formOptionsAtom, { store });
|
|
158
|
-
const callbacks = useAtomValue(callbacksAtom, { store });
|
|
159
|
-
|
|
160
|
-
const addContactAccessRight = (
|
|
161
|
-
contactAccessRight: ContactAccessRightResource
|
|
162
|
-
): void =>
|
|
163
|
-
setContactAccessRights((prev) => {
|
|
164
|
-
const isContactAlreadyAdded = prev.some(
|
|
165
|
-
({ contactAccessRight: c }) =>
|
|
166
|
-
c.contact?.id === contactAccessRight.contact?.id
|
|
167
|
-
);
|
|
168
|
-
|
|
169
|
-
return isContactAlreadyAdded
|
|
170
|
-
? prev
|
|
171
|
-
: [
|
|
172
|
-
...prev,
|
|
173
|
-
{
|
|
174
|
-
contactAccessRight,
|
|
175
|
-
state: 'added',
|
|
176
|
-
stateHistory: []
|
|
177
|
-
} as ContactAccessRightStateResource
|
|
178
|
-
].sort(sortOnAddedStateFirstAndContactName);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
const removeContactAccessRight = (
|
|
182
|
-
contactAccessRight: ContactAccessRightResource,
|
|
183
|
-
restore = false
|
|
184
|
-
): void =>
|
|
185
|
-
setContactAccessRights((prev) => {
|
|
186
|
-
const contactAccessRightIndex = prev.findIndex(
|
|
187
|
-
({ contactAccessRight: prevContactAccessRight }) =>
|
|
188
|
-
prevContactAccessRight.contact?.id === contactAccessRight.contact?.id
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
if (contactAccessRightIndex === -1) {
|
|
192
|
-
return prev;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const { stateHistory } = prev[contactAccessRightIndex];
|
|
196
|
-
|
|
197
|
-
if (restore) {
|
|
198
|
-
return [
|
|
199
|
-
...prev.slice(0, contactAccessRightIndex),
|
|
200
|
-
{
|
|
201
|
-
...prev[contactAccessRightIndex],
|
|
202
|
-
state: stateHistory[stateHistory.length - 1],
|
|
203
|
-
stateHistory: [...stateHistory, prev[contactAccessRightIndex].state]
|
|
204
|
-
} as ContactAccessRightStateResource,
|
|
205
|
-
...prev.slice(contactAccessRightIndex + 1)
|
|
206
|
-
];
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (
|
|
210
|
-
prev[contactAccessRightIndex].state === 'added' ||
|
|
211
|
-
stateHistory[0] === 'added'
|
|
212
|
-
) {
|
|
213
|
-
return [
|
|
214
|
-
...prev.slice(0, contactAccessRightIndex),
|
|
215
|
-
...prev.slice(contactAccessRightIndex + 1)
|
|
216
|
-
];
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return [
|
|
220
|
-
...prev.slice(0, contactAccessRightIndex),
|
|
221
|
-
{
|
|
222
|
-
...prev[contactAccessRightIndex],
|
|
223
|
-
state: 'removed',
|
|
224
|
-
stateHistory: [...stateHistory, prev[contactAccessRightIndex].state]
|
|
225
|
-
} as ContactAccessRightStateResource,
|
|
226
|
-
...prev.slice(contactAccessRightIndex + 1)
|
|
227
|
-
];
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const updateContactAccessRight = (
|
|
231
|
-
contactAccessRight: ContactAccessRightResource
|
|
232
|
-
): void =>
|
|
233
|
-
setContactAccessRights((prev) => {
|
|
234
|
-
const contactAccessRightIndex = prev.findIndex(
|
|
235
|
-
({ contactAccessRight: prevContactAccessRight }) =>
|
|
236
|
-
prevContactAccessRight.contact?.id === contactAccessRight.contact?.id
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
if (contactAccessRightIndex === -1) {
|
|
240
|
-
return prev;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const { stateHistory } = prev[contactAccessRightIndex];
|
|
244
|
-
|
|
245
|
-
const isAdded =
|
|
246
|
-
prev[contactAccessRightIndex].state === 'added' ||
|
|
247
|
-
stateHistory[0] === 'added';
|
|
248
|
-
const isUpdated =
|
|
249
|
-
prev[contactAccessRightIndex].state === 'updated' ||
|
|
250
|
-
stateHistory.findIndex((state) => state === 'updated') <
|
|
251
|
-
stateHistory.findIndex((state) => state === 'unchanged');
|
|
252
|
-
|
|
253
|
-
// eslint-disable-next-line no-nested-ternary
|
|
254
|
-
const state = isAdded ? 'added' : isUpdated ? 'unchanged' : 'updated';
|
|
255
|
-
|
|
256
|
-
return [
|
|
257
|
-
...prev.slice(0, contactAccessRightIndex),
|
|
258
|
-
{
|
|
259
|
-
contactAccessRight,
|
|
260
|
-
state,
|
|
261
|
-
stateHistory: [...stateHistory, prev[contactAccessRightIndex].state]
|
|
262
|
-
} as ContactAccessRightStateResource,
|
|
263
|
-
...prev.slice(contactAccessRightIndex + 1)
|
|
264
|
-
];
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const submit = (): void => callbacks.onSubmit?.(contactAccessRights);
|
|
268
|
-
|
|
269
|
-
return {
|
|
270
|
-
addContactAccessRight,
|
|
271
|
-
contactAccessRights,
|
|
272
|
-
isDirty,
|
|
273
|
-
isLoading,
|
|
274
|
-
options,
|
|
275
|
-
removeContactAccessRight,
|
|
276
|
-
stats,
|
|
277
|
-
submit,
|
|
278
|
-
updateContactAccessRight
|
|
279
|
-
};
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
export { AccessRightsFormProvider, useAccessRightsForm };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ContactAccessRightStateResource } from './AccessRights.resource';
|
|
2
|
-
|
|
3
|
-
export const sortOnContactName = (
|
|
4
|
-
a: ContactAccessRightStateResource,
|
|
5
|
-
b: ContactAccessRightStateResource
|
|
6
|
-
): number =>
|
|
7
|
-
a.contactAccessRight.contact?.name.localeCompare(
|
|
8
|
-
b.contactAccessRight.contact?.name ?? ''
|
|
9
|
-
) || 0;
|
|
10
|
-
|
|
11
|
-
export const sortOnAddedStateFirstAndContactName = (
|
|
12
|
-
a: ContactAccessRightStateResource,
|
|
13
|
-
b: ContactAccessRightStateResource
|
|
14
|
-
): number => {
|
|
15
|
-
if (a.state === 'added' && b.state !== 'added') {
|
|
16
|
-
return -1;
|
|
17
|
-
}
|
|
18
|
-
if (a.state !== 'added' && b.state === 'added') {
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
a.contactAccessRight.contact?.name.localeCompare(
|
|
24
|
-
b.contactAccessRight.contact?.name ?? ''
|
|
25
|
-
) || 0
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const createInitialState = (
|
|
30
|
-
values
|
|
31
|
-
): Array<ContactAccessRightStateResource> =>
|
|
32
|
-
values
|
|
33
|
-
?.map(
|
|
34
|
-
(contactAccessRight) =>
|
|
35
|
-
({
|
|
36
|
-
contactAccessRight,
|
|
37
|
-
state: 'unchanged',
|
|
38
|
-
stateHistory: []
|
|
39
|
-
}) as ContactAccessRightStateResource
|
|
40
|
-
)
|
|
41
|
-
.sort(sortOnAddedStateFirstAndContactName);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.styles.tsx
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|