Fix typo
[arvados-workbench2.git] / src / store / trash-panel / trash-panel-middleware-service.ts
index 6e8fa542478766368968e0912fc636da5f4c9b6b..9afc57b49f74e5808f7254f9d6b3362c74b03ee8 100644 (file)
@@ -19,8 +19,10 @@ import { TrashPanelColumnNames, TrashPanelFilter } from "~/views/trash-panel/tra
 import { ProjectResource } from "~/models/project";
 import { ProjectPanelColumnNames } from "~/views/project-panel/project-panel";
 import { updateFavorites } from "~/store/favorites/favorites-actions";
-import { snackbarActions } from "~/store/snackbar/snackbar-actions";
+import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
 import { updateResources } from "~/store/resources/resources-actions";
+import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
+import { getSortColumn } from "~/store/data-explorer/data-explorer-reducer";
 
 export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
     constructor(private services: ServiceRepository, id: string) {
@@ -30,7 +32,7 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
     async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
         const dataExplorer = api.getState().dataExplorer[this.getId()];
         const columns = dataExplorer.columns as DataColumns<string, TrashPanelFilter>;
-        const sortColumn = dataExplorer.columns.find(c => c.sortDirection !== SortDirection.NONE);
+        const sortColumn = getSortColumn(dataExplorer);
         const typeFilters = this.getColumnFilters(columns, TrashPanelColumnNames.TYPE);
 
         const order = new OrderBuilder<ProjectResource>();
@@ -47,6 +49,7 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
         }
 
         try {
+            api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
             const userUuid = this.services.authService.getUuid()!;
             const listResults = await this.services.groupsService
                 .contents(userUuid, {
@@ -61,6 +64,7 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
                     recursive: true,
                     includeTrash: true
                 });
+            api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
 
             const items = listResults.items.map(it => it.uuid);
 
@@ -71,6 +75,13 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
             api.dispatch<any>(updateFavorites(items));
             api.dispatch(updateResources(listResults.items));
         } catch (e) {
+            api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
+            api.dispatch(trashPanelActions.SET_ITEMS({
+                items: [],
+                itemsAvailable: 0,
+                page: 0,
+                rowsPerPage: dataExplorer.rowsPerPage
+            }));
             api.dispatch(couldNotFetchTrashContents());
         }
     }
@@ -78,5 +89,7 @@ export class TrashPanelMiddlewareService extends DataExplorerMiddlewareService {
 
 const couldNotFetchTrashContents = () =>
     snackbarActions.OPEN_SNACKBAR({
-        message: 'Could not fetch trash contents.'
+        message: 'Could not fetch trash contents.',
+        kind: SnackbarKind.ERROR
     });
+