1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
6 DataExplorerMiddlewareService, dataExplorerToListParams,
7 listResultsToDataExplorerItemsMeta
8 } from "../data-explorer/data-explorer-middleware-service";
9 import { RootState } from "../store";
10 import { getUserUuid } from "common/getuser";
11 import { DataColumns } from "components/data-table/data-table";
12 import { ServiceRepository } from "services/services";
13 import { SortDirection } from "components/data-table/data-column";
14 import { FilterBuilder } from "services/api/filter-builder";
15 import { trashPanelActions } from "./trash-panel-action";
16 import { Dispatch, MiddlewareAPI } from "redux";
17 import { OrderBuilder, OrderDirection } from "services/api/order-builder";
18 import { GroupContentsResourcePrefix } from "services/groups-service/groups-service";
19 import { ProjectResource } from "models/project";
20 import { ProjectPanelColumnNames } from "views/project-panel/project-panel";
21 import { updateFavorites } from "store/favorites/favorites-actions";
22 import { updatePublicFavorites } from 'store/public-favorites/public-favorites-actions';
23 import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
24 import { updateResources } from "store/resources/resources-actions";
25 import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
26 import { getSortColumn } from "store/data-explorer/data-explorer-reducer";
27 import { serializeResourceTypeFilters } from 'store//resource-type-filters/resource-type-filters';
28 import { getDataExplorerColumnFilters } from 'store/data-explorer/data-explorer-middleware-service';
29 import { joinFilters } from 'services/api/filter-builder';
31 export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
32 constructor(private services: ServiceRepository, id: string) {
36 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
37 const dataExplorer = api.getState().dataExplorer[this.getId()];
38 const columns = dataExplorer.columns as DataColumns<string>;
39 const sortColumn = getSortColumn(dataExplorer);
41 const typeFilters = serializeResourceTypeFilters(getDataExplorerColumnFilters(columns, ProjectPanelColumnNames.TYPE));
43 const otherFilters = new FilterBuilder()
44 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.COLLECTION)
45 // .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROCESS)
46 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROJECT)
47 .addEqual("is_trashed", true)
50 const filters = joinFilters(
55 const order = new OrderBuilder<ProjectResource>();
58 const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.ASC
60 : OrderDirection.DESC;
62 const columnName = sortColumn && sortColumn.name === ProjectPanelColumnNames.NAME ? "name" : "createdAt";
64 .addOrder(sortDirection, columnName, GroupContentsResourcePrefix.COLLECTION)
65 .addOrder(sortDirection, columnName, GroupContentsResourcePrefix.PROJECT);
68 const userUuid = getUserUuid(api.getState());
69 if (!userUuid) { return; }
71 api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
72 const listResults = await this.services.groupsService
74 ...dataExplorerToListParams(dataExplorer),
75 order: order.getOrder(),
80 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
82 const items = listResults.items.map(it => it.uuid);
84 api.dispatch(trashPanelActions.SET_ITEMS({
85 ...listResultsToDataExplorerItemsMeta(listResults),
88 api.dispatch<any>(updateFavorites(items));
89 api.dispatch<any>(updatePublicFavorites(items));
90 api.dispatch(updateResources(listResults.items));
92 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
93 api.dispatch(trashPanelActions.SET_ITEMS({
97 rowsPerPage: dataExplorer.rowsPerPage
99 api.dispatch(couldNotFetchTrashContents());
104 const couldNotFetchTrashContents = () =>
105 snackbarActions.OPEN_SNACKBAR({
106 message: 'Could not fetch trash contents.',
107 kind: SnackbarKind.ERROR