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 { DataColumns } from "~/components/data-table/data-table";
11 import { ServiceRepository } from "~/services/services";
12 import { SortDirection } from "~/components/data-table/data-column";
13 import { FilterBuilder } from "~/services/api/filter-builder";
14 import { trashPanelActions } from "./trash-panel-action";
15 import { Dispatch, MiddlewareAPI } from "redux";
16 import { OrderBuilder, OrderDirection } from "~/services/api/order-builder";
17 import { GroupContentsResourcePrefix } from "~/services/groups-service/groups-service";
18 import { TrashPanelColumnNames, TrashPanelFilter } from "~/views/trash-panel/trash-panel";
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 { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
23 import { updateResources } from "~/store/resources/resources-actions";
24 import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
25 import { getSortColumn } from "~/store/data-explorer/data-explorer-reducer";
26 import { serializeResourceTypeFilters } from '~/store//resource-type-filters/resource-type-filters';
27 import { getDataExplorerColumnFilters } from '~/store/data-explorer/data-explorer-middleware-service';
28 import { joinFilters } from '../../services/api/filter-builder';
30 export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
31 constructor(private services: ServiceRepository, id: string) {
35 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
36 const dataExplorer = api.getState().dataExplorer[this.getId()];
37 const columns = dataExplorer.columns as DataColumns<string>;
38 const sortColumn = getSortColumn(dataExplorer);
40 const typeFilters = serializeResourceTypeFilters(getDataExplorerColumnFilters(columns, ProjectPanelColumnNames.TYPE));
42 const otherFilters = new FilterBuilder()
43 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.COLLECTION)
44 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROCESS)
45 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROJECT)
46 .addEqual("is_trashed", true)
49 const filters = joinFilters(
54 const order = new OrderBuilder<ProjectResource>();
57 const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.ASC
59 : OrderDirection.DESC;
61 const columnName = sortColumn && sortColumn.name === ProjectPanelColumnNames.NAME ? "name" : "createdAt";
63 .addOrder(sortDirection, columnName, GroupContentsResourcePrefix.COLLECTION)
64 .addOrder(sortDirection, columnName, GroupContentsResourcePrefix.PROJECT);
68 api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
69 const userUuid = this.services.authService.getUuid()!;
70 const listResults = await this.services.groupsService
72 ...dataExplorerToListParams(dataExplorer),
73 order: order.getOrder(),
78 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
80 const items = listResults.items.map(it => it.uuid);
82 api.dispatch(trashPanelActions.SET_ITEMS({
83 ...listResultsToDataExplorerItemsMeta(listResults),
86 api.dispatch<any>(updateFavorites(items));
87 api.dispatch(updateResources(listResults.items));
89 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
90 api.dispatch(trashPanelActions.SET_ITEMS({
94 rowsPerPage: dataExplorer.rowsPerPage
96 api.dispatch(couldNotFetchTrashContents());
101 const couldNotFetchTrashContents = () =>
102 snackbarActions.OPEN_SNACKBAR({
103 message: 'Could not fetch trash contents.',
104 kind: SnackbarKind.ERROR