From: Pawel Kowalczyk Date: Mon, 6 May 2019 10:06:59 +0000 (+0200) Subject: check-for-collections-with-same-content-adress X-Git-Tag: 1.4.0~11^2~10 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/ada23a4054724d0d6be4ee88efb22daecd86001f check-for-collections-with-same-content-adress Feature #15020 Arvados-DCO-1.1-Signed-off-by: Pawel Kowalczyk --- diff --git a/src/store/collection-panel/collection-panel-action.ts b/src/store/collection-panel/collection-panel-action.ts index cd426471..76a40dcb 100644 --- a/src/store/collection-panel/collection-panel-action.ts +++ b/src/store/collection-panel/collection-panel-action.ts @@ -7,7 +7,7 @@ import { loadCollectionFiles } from "./collection-panel-files/collection-panel-f import { CollectionResource } from '~/models/collection'; import { collectionPanelFilesAction } from "./collection-panel-files/collection-panel-files-actions"; import { createTree } from "~/models/tree"; -import { RootState } from "../store"; +import { RootState } from "~/store/store"; import { ServiceRepository } from "~/services/services"; import { TagProperty } from "~/models/tag"; import { snackbarActions } from "../snackbar/snackbar-actions"; @@ -15,9 +15,12 @@ import { resourcesActions } from "~/store/resources/resources-actions"; import { unionize, ofType, UnionOf } from '~/common/unionize'; import { SnackbarKind } from '~/store/snackbar/snackbar-actions'; import { navigateTo } from '~/store/navigation/navigation-action'; +import { FilterBuilder } from "~/services/api/filter-builder"; +import { loadDetailsPanel } from '~/store/details-panel/details-panel-action'; export const collectionPanelActions = unionize({ SET_COLLECTION: ofType(), + SET_NUMBER_OF_COLLECTIONS_WITH_SAME_PDH: ofType(), LOAD_COLLECTION: ofType<{ uuid: string }>(), LOAD_COLLECTION_SUCCESS: ofType<{ item: CollectionResource }>() }); @@ -31,6 +34,13 @@ export const loadCollectionPanel = (uuid: string) => dispatch(collectionPanelActions.LOAD_COLLECTION({ uuid })); dispatch(collectionPanelFilesAction.SET_COLLECTION_FILES({ files: createTree() })); const collection = await services.collectionService.get(uuid); + const collectionsByPDH = await services.collectionService.list({ + filters: new FilterBuilder() + .addEqual('portableDataHash', collection.portableDataHash) + .getFilters() + }); + dispatch(collectionPanelActions.SET_NUMBER_OF_COLLECTIONS_WITH_SAME_PDH(collectionsByPDH.itemsAvailable)); + dispatch(loadDetailsPanel(collection.uuid)); dispatch(collectionPanelActions.LOAD_COLLECTION_SUCCESS({ item: collection })); dispatch(resourcesActions.SET_RESOURCES([collection])); dispatch(loadCollectionFiles(collection.uuid)); diff --git a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts index b75de94a..534d70d4 100644 --- a/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts +++ b/src/store/collection-panel/collection-panel-files/collection-panel-files-actions.ts @@ -77,8 +77,8 @@ export const openFileRemoveDialog = (filePath: string) => ? 'Are you sure you want to remove this directory?' : 'Are you sure you want to remove this file?'; const info = isDirectory - ? 'Removing files will change content adress.' - : 'Removing a file will change content adress.'; + ? 'Removing files will change content address.' + : 'Removing a file will change content address.'; dispatch(dialogActions.OPEN_DIALOG({ id: FILE_REMOVE_DIALOG, @@ -101,7 +101,7 @@ export const openMultipleFilesRemoveDialog = () => data: { title: 'Removing files', text: 'Are you sure you want to remove selected files?', - info: 'Removing files will change content adress.', + info: 'Removing files will change content address.', confirmButtonLabel: 'Remove' } }); diff --git a/src/store/collection-panel/collection-panel-reducer.ts b/src/store/collection-panel/collection-panel-reducer.ts index 55829cb5..4207a393 100644 --- a/src/store/collection-panel/collection-panel-reducer.ts +++ b/src/store/collection-panel/collection-panel-reducer.ts @@ -7,10 +7,12 @@ import { CollectionResource } from "~/models/collection"; export interface CollectionPanelState { item: CollectionResource | null; + numberOfCollectionsWithSamePDH: number; } const initialState = { - item: null + item: null, + numberOfCollectionsWithSamePDH: 0 }; export const collectionPanelReducer = (state: CollectionPanelState = initialState, action: CollectionPanelAction) => @@ -18,4 +20,5 @@ export const collectionPanelReducer = (state: CollectionPanelState = initialStat default: () => state, SET_COLLECTION: (item) => ({ ...state, item }), LOAD_COLLECTION_SUCCESS: ({ item }) => ({ ...state, item }), + SET_NUMBER_OF_COLLECTIONS_WITH_SAME_PDH: (num) => ({ ...state, numberOfCollectionsWithSamePDH: num }), }); diff --git a/src/store/workbench/workbench-actions.ts b/src/store/workbench/workbench-actions.ts index adf3fa15..378bb8de 100644 --- a/src/store/workbench/workbench-actions.ts +++ b/src/store/workbench/workbench-actions.ts @@ -68,8 +68,7 @@ import { FilterBuilder } from '~/services/api/filter-builder'; import { GroupContentsResource } from '~/services/groups-service/groups-service'; import { MatchCases, ofType, unionize, UnionOf } from '~/common/unionize'; import { loadRunProcessPanel } from '~/store/run-process-panel/run-process-panel-actions'; -import { loadCollectionFiles } from '~/store/collection-panel/collection-panel-files/collection-panel-files-actions'; -import { collectionPanelActions } from "~/store/collection-panel/collection-panel-action"; +import { collectionPanelActions, loadCollectionPanel } from "~/store/collection-panel/collection-panel-action"; import { CollectionResource } from "~/models/collection"; import { loadSearchResultsPanel, @@ -256,22 +255,22 @@ export const loadCollection = (uuid: string) => dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource)); dispatch(updateResources([collection])); await dispatch(activateSidePanelTreeItem(collection.ownerUuid)); - dispatch(setSidePanelBreadcrumbs(collection.ownerUuid)); - dispatch(loadCollectionFiles(collection.uuid)); + dispatch(setSidePanelBreadcrumbs(collection.ownerUuid)); + dispatch(loadCollectionPanel(collection.uuid)); }, SHARED: collection => { dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource)); dispatch(updateResources([collection])); dispatch(setSharedWithMeBreadcrumbs(collection.ownerUuid)); dispatch(activateSidePanelTreeItem(collection.ownerUuid)); - dispatch(loadCollectionFiles(collection.uuid)); + dispatch(loadCollectionPanel(collection.uuid)); }, TRASHED: collection => { dispatch(collectionPanelActions.SET_COLLECTION(collection as CollectionResource)); dispatch(updateResources([collection])); dispatch(setTrashBreadcrumbs('')); dispatch(activateSidePanelTreeItem(SidePanelTreeCategory.TRASH)); - dispatch(loadCollectionFiles(collection.uuid)); + dispatch(loadCollectionPanel(collection.uuid)); }, }); diff --git a/src/views-components/details-panel/collection-details.tsx b/src/views-components/details-panel/collection-details.tsx index 98fa3886..01b867b3 100644 --- a/src/views-components/details-panel/collection-details.tsx +++ b/src/views-components/details-panel/collection-details.tsx @@ -26,7 +26,7 @@ export class CollectionDetails extends DetailsData { {/* Links but we dont have view */} - + {/* Missing attrs */} diff --git a/src/views-components/details-panel/details-data.tsx b/src/views-components/details-panel/details-data.tsx index 45afb02b..1a67a55d 100644 --- a/src/views-components/details-panel/details-data.tsx +++ b/src/views-components/details-panel/details-data.tsx @@ -7,7 +7,7 @@ import { DetailsResource } from "~/models/details"; import { ResourceData } from "~/store/resources-data/resources-data-reducer"; export abstract class DetailsData { - constructor(protected item: T, protected data?: ResourceData) {} + constructor(protected item: T, protected data?: ResourceData, protected numberOfCollectionsByPDH?: number) {} getTitle(): string { return this.item.name || 'Projects'; diff --git a/src/views-components/details-panel/details-panel.tsx b/src/views-components/details-panel/details-panel.tsx index 2a30ae47..5c8ebe74 100644 --- a/src/views-components/details-panel/details-panel.tsx +++ b/src/views-components/details-panel/details-panel.tsx @@ -62,13 +62,13 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ const EMPTY_RESOURCE: EmptyResource = { kind: undefined, name: 'Projects' }; -const getItem = (res: DetailsResource, resourceData?: ResourceData): DetailsData => { +const getItem = (res: DetailsResource, resourceData?: ResourceData, numberOfCollectionsByPDH?: number): DetailsData => { if ('kind' in res) { switch (res.kind) { case ResourceKind.PROJECT: return new ProjectDetails(res); case ResourceKind.COLLECTION: - return new CollectionDetails(res, resourceData); + return new CollectionDetails(res, resourceData, numberOfCollectionsByPDH); case ResourceKind.PROCESS: return new ProcessDetails(res); default: @@ -79,13 +79,14 @@ const getItem = (res: DetailsResource, resourceData?: ResourceData): DetailsData } }; -const mapStateToProps = ({ detailsPanel, resources, resourcesData, collectionPanelFiles }: RootState) => { +const mapStateToProps = ({ detailsPanel, resources, resourcesData, collectionPanelFiles, collectionPanel }: RootState) => { const resource = getResource(detailsPanel.resourceUuid)(resources) as DetailsResource | undefined; const file = getNode(detailsPanel.resourceUuid)(collectionPanelFiles); const resourceData = getResourceData(detailsPanel.resourceUuid)(resourcesData); + const numberOfCollectionsByPDH = collectionPanel.numberOfCollectionsWithSamePDH; return { isOpened: detailsPanel.isOpened, - item: getItem(resource || (file && file.value) || EMPTY_RESOURCE, resourceData) + item: getItem(resource || (file && file.value) || EMPTY_RESOURCE, resourceData, numberOfCollectionsByPDH), }; };