Skip to content

Commit 3e0e94e

Browse files
authored
Refactor duplication endpoint (#411)
* Refactor duplication endpoint * Update .gitignore to exclude .vscode --------- Signed-off-by: TOURI ANIS <[email protected]>
1 parent 9b3930d commit 3e0e94e

File tree

6 files changed

+166
-348
lines changed

6 files changed

+166
-348
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@
1818

1919
# jest
2020
/coverage
21+
22+
# vs code
23+
/.vscode

src/components/directory-content.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ const DirectoryContent = () => {
131131
nameItem,
132132
descriptionItem,
133133
sourceItemUuid,
134-
parentDirectoryUuid
134+
parentDirectoryUuid,
135+
specificTypeItem
135136
) => {
136137
dispatch(
137138
setSelectionForCopy({
@@ -140,6 +141,7 @@ const DirectoryContent = () => {
140141
nameItem: nameItem,
141142
descriptionItem: descriptionItem,
142143
parentDirectoryUuid: parentDirectoryUuid,
144+
specificTypeItem: specificTypeItem,
143145
})
144146
);
145147
},
@@ -160,7 +162,8 @@ const DirectoryContent = () => {
160162
event.data.nameItem,
161163
event.data.descriptionItem,
162164
event.data.sourceItemUuid,
163-
event.data.parentDirectoryUuid
165+
event.data.parentDirectoryUuid,
166+
event.data.specificTypeItem
164167
);
165168
}
166169
};

src/components/menus/content-contextual-menu.jsx

Lines changed: 72 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,9 @@ import { DialogsId } from '../../utils/UIconstants';
3030
import {
3131
createFilter,
3232
deleteElements,
33-
duplicateCase,
34-
duplicateContingencyList,
35-
duplicateFilter,
36-
duplicateModification,
37-
duplicateParameter,
38-
duplicateStudy,
33+
duplicateElement,
3934
elementExists,
4035
fetchAppsAndUrls,
41-
fetchElementsInfos,
42-
getNameCandidate,
4336
moveElementsToDirectory,
4437
newScriptFromFilter,
4538
newScriptFromFiltersContingencyList,
@@ -114,7 +107,8 @@ const ContentContextualMenu = (props) => {
114107
nameItem,
115108
descriptionItem,
116109
sourceItemUuid,
117-
parentDirectoryUuid
110+
parentDirectoryUuid,
111+
specificType
118112
) => {
119113
dispatch(
120114
setSelectionForCopy({
@@ -123,6 +117,7 @@ const ContentContextualMenu = (props) => {
123117
nameItem: nameItem,
124118
descriptionItem: descriptionItem,
125119
parentDirectoryUuid: parentDirectoryUuid,
120+
specificType,
126121
})
127122
);
128123
},
@@ -134,21 +129,24 @@ const ContentContextualMenu = (props) => {
134129
nameItem,
135130
descriptionItem,
136131
sourceItemUuid,
137-
parentDirectoryUuid
132+
parentDirectoryUuid,
133+
sprecificTypeItem
138134
) {
139135
dispatchSelectionForCopy(
140136
typeItem,
141137
nameItem,
142138
descriptionItem,
143139
sourceItemUuid,
144-
parentDirectoryUuid
140+
parentDirectoryUuid,
141+
sprecificTypeItem
145142
);
146143
broadcastChannel.postMessage({
147144
typeItem: typeItem,
148145
nameItem: nameItem,
149146
descriptionItem: descriptionItem,
150147
sourceItemUuid: sourceItemUuid,
151148
parentDirectoryUuid: parentDirectoryUuid,
149+
specificTypeItem: sprecificTypeItem,
152150
});
153151

154152
handleCloseDialog();
@@ -177,7 +175,6 @@ const ContentContextualMenu = (props) => {
177175
case ElementType.SECURITY_ANALYSIS_PARAMETERS:
178176
case ElementType.SENSITIVITY_PARAMETERS:
179177
case ElementType.LOADFLOW_PARAMETERS:
180-
case ElementType.CONTINGENCY_LIST:
181178
console.info(
182179
activeElement.type +
183180
' with uuid ' +
@@ -194,6 +191,24 @@ const ContentContextualMenu = (props) => {
194191
selectedDirectory.elementUuid
195192
);
196193
break;
194+
case ElementType.CONTINGENCY_LIST:
195+
console.info(
196+
activeElement.type +
197+
' with uuid ' +
198+
activeElement.elementUuid +
199+
' from directory ' +
200+
selectedDirectory.elementUuid +
201+
' selected for copy'
202+
);
203+
copyElement(
204+
activeElement.type,
205+
activeElement.elementName,
206+
activeElement.description,
207+
activeElement.elementUuid,
208+
selectedDirectory.elementUuid,
209+
activeElement.specificMetadata.type
210+
);
211+
break;
197212

198213
default:
199214
handleLastError(
@@ -204,96 +219,51 @@ const ContentContextualMenu = (props) => {
204219
};
205220
const duplicateItem = () => {
206221
if (activeElement) {
207-
getNameCandidate(
208-
selectedDirectory.elementUuid,
209-
activeElement.elementName,
210-
activeElement.type
211-
)
212-
.then((newItemName) => {
213-
switch (activeElement.type) {
214-
case ElementType.CASE:
215-
duplicateCase(
216-
newItemName,
217-
activeElement.description,
218-
activeElement.elementUuid,
219-
selectedDirectory.elementUuid
220-
).catch((error) => {
221-
handleDuplicateError(error.message);
222-
});
223-
break;
224-
case ElementType.CONTINGENCY_LIST:
225-
fetchElementsInfos([activeElement.elementUuid])
226-
.then((res) => {
227-
duplicateContingencyList(
228-
res[0].specificMetadata.type,
229-
newItemName,
230-
activeElement.description,
231-
activeElement.elementUuid,
232-
selectedDirectory.elementUuid
233-
).catch((error) => {
234-
handleDuplicateError(error.message);
235-
});
236-
})
237-
.catch((error) => {
238-
handleLastError(error.message);
239-
});
240-
break;
241-
case ElementType.STUDY:
242-
duplicateStudy(
243-
newItemName,
244-
activeElement.description,
245-
activeElement.elementUuid,
246-
selectedDirectory.elementUuid
247-
).catch((error) => {
248-
handleDuplicateError(error.message);
249-
});
250-
break;
251-
case ElementType.FILTER:
252-
duplicateFilter(
253-
newItemName,
254-
activeElement.description,
255-
activeElement.elementUuid,
256-
selectedDirectory.elementUuid
257-
).catch((error) => {
258-
handleDuplicateError(error.message);
259-
});
260-
break;
261-
case ElementType.MODIFICATION:
262-
duplicateModification(
263-
newItemName,
264-
activeElement.description,
265-
activeElement.elementUuid,
266-
selectedDirectory.elementUuid
267-
).catch((error) => {
268-
handleDuplicateError(error.message);
269-
});
270-
break;
271-
case ElementType.VOLTAGE_INIT_PARAMETERS:
272-
case ElementType.SENSITIVITY_PARAMETERS:
273-
case ElementType.SECURITY_ANALYSIS_PARAMETERS:
274-
case ElementType.LOADFLOW_PARAMETERS:
275-
duplicateParameter(
276-
newItemName,
277-
activeElement.type,
278-
activeElement.elementUuid,
279-
selectedDirectory.elementUuid,
280-
activeElement.description
281-
).catch((error) => {
282-
handleDuplicateError(error.message);
283-
});
284-
break;
285-
default:
286-
handleLastError(
287-
intl.formatMessage({
288-
id: 'unsupportedItem',
289-
})
290-
);
291-
}
292-
})
293-
.catch((error) => {
294-
handleDuplicateError(error.message);
295-
})
296-
.finally(() => handleCloseDialog());
222+
switch (activeElement.type) {
223+
case ElementType.CASE:
224+
case ElementType.STUDY:
225+
case ElementType.FILTER:
226+
case ElementType.MODIFICATION:
227+
duplicateElement(
228+
activeElement.elementUuid,
229+
undefined,
230+
activeElement.type
231+
).catch((error) => {
232+
handleDuplicateError(error.message);
233+
});
234+
break;
235+
case ElementType.CONTINGENCY_LIST:
236+
duplicateElement(
237+
activeElement.elementUuid,
238+
undefined,
239+
activeElement.type,
240+
selectedElements[0].specificMetadata.type
241+
).catch((error) => {
242+
handleDuplicateError(error.message);
243+
});
244+
break;
245+
case ElementType.VOLTAGE_INIT_PARAMETERS:
246+
case ElementType.SENSITIVITY_PARAMETERS:
247+
case ElementType.SECURITY_ANALYSIS_PARAMETERS:
248+
case ElementType.LOADFLOW_PARAMETERS:
249+
duplicateElement(
250+
activeElement.elementUuid,
251+
undefined,
252+
ElementType.PARAMETERS,
253+
activeElement.type
254+
).catch((error) => {
255+
handleDuplicateError(error.message);
256+
});
257+
break;
258+
default: {
259+
handleLastError(
260+
intl.formatMessage({
261+
id: 'unsupportedItem',
262+
})
263+
);
264+
}
265+
}
266+
handleCloseDialog();
297267
}
298268
};
299269

0 commit comments

Comments
 (0)