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 { ProjectResource } from "~/models/project";
19 import { ProjectPanelColumnNames } from "~/views/project-panel/project-panel";
20 import { updateFavorites } from "~/store/favorites/favorites-actions";
21 import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
22 import { updateResources } from "~/store/resources/resources-actions";
23 import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
24 import { getSortColumn } from "~/store/data-explorer/data-explorer-reducer";
25 import { serializeResourceTypeFilters } from '~/store//resource-type-filters/resource-type-filters';
26 import { getDataExplorerColumnFilters } from '~/store/data-explorer/data-explorer-middleware-service';
27 import { joinFilters } from '~/services/api/filter-builder';
29 export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
30 constructor(private services: ServiceRepository, id: string) {
34 async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
35 const dataExplorer = api.getState().dataExplorer[this.getId()];
36 const columns = dataExplorer.columns as DataColumns<string>;
37 const sortColumn = getSortColumn(dataExplorer);
39 const typeFilters = serializeResourceTypeFilters(getDataExplorerColumnFilters(columns, ProjectPanelColumnNames.TYPE));
41 const otherFilters = new FilterBuilder()
42 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.COLLECTION)
43 // .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROCESS)
44 .addILike("name", dataExplorer.searchValue, GroupContentsResourcePrefix.PROJECT)
45 .addEqual("is_trashed", true)
48 const filters = joinFilters(
53 const order = new OrderBuilder<ProjectResource>();
56 const sortDirection = sortColumn && sortColumn.sortDirection === SortDirection.ASC
58 : OrderDirection.DESC;
60 const columnName = sortColumn && sortColumn.name === ProjectPanelColumnNames.NAME ? "name" : "createdAt";
62 .addOrder(sortDirection, columnName, GroupContentsResourcePrefix.COLLECTION)
63 .addOrder(sortDirection, columnName, GroupContentsResourcePrefix.PROJECT);
67 api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
68 const userUuid = this.services.authService.getUuid()!;
69 const listResults = await this.services.groupsService
71 ...dataExplorerToListParams(dataExplorer),
72 order: order.getOrder(),
77 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
79 const items = listResults.items.map(it => it.uuid);
81 api.dispatch(trashPanelActions.SET_ITEMS({
82 ...listResultsToDataExplorerItemsMeta(listResults),
85 api.dispatch<any>(updateFavorites(items));
86 api.dispatch(updateResources(listResults.items));
88 api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
89 api.dispatch(trashPanelActions.SET_ITEMS({
93 rowsPerPage: dataExplorer.rowsPerPage
95 api.dispatch(couldNotFetchTrashContents());
100 const couldNotFetchTrashContents = () =>
101 snackbarActions.OPEN_SNACKBAR({
102 message: 'Could not fetch trash contents.',
103 kind: SnackbarKind.ERROR