- dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid }));
- dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files: createTree() }));
- const collection = await services.collectionService.get(uuid);
- dispatch(loadDetailsPanel(collection.uuid));
- dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection }));
- dispatch(resourcesActions.SET_RESOURCES([collection]));
- dispatch<any>(loadCollectionFiles(collection.uuid));
- return collection;
- };
-
-export const createCollectionTag = (data: TagProperty) =>
- async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- const item = getState().collectionPanel.item;
- const uuid = item ? item.uuid : '';
- try {
- if (item) {
- const key = data.keyID || data.key;
- const value = data.valueID || data.value;
- item.properties = addProperty(item.properties, key, value);
- const updatedCollection = await services.collectionService.update(
- uuid, {
- properties: {...item.properties}
- }
- );
- item.properties = updatedCollection.properties;
- dispatch(resourcesActions.SET_RESOURCES([updatedCollection]));
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Tag has been successfully added.", hideDuration: 2000, kind: SnackbarKind.SUCCESS }));
- return updatedCollection;
- }
- return;
- } catch (e) {
- dispatch(snackbarActions.OPEN_SNACKBAR({ message: e.errors[0], hideDuration: 2000, kind: SnackbarKind.ERROR }));
- return;
+ const { collectionPanel: { item } } = getState();
+ let collection: CollectionResource | null = null;
+ if (!item || item.uuid !== uuid || forceReload) {
+ collection = await services.collectionService.get(uuid);
+ dispatch(collectionPanelActions.SET_COLLECTION(collection));
+ dispatch(resourcesActions.SET_RESOURCES([collection]));
+ } else {
+ collection = item;