const services = createServices(config, {
progressFn: (id, working) => {
- store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
+ //store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
},
errorFn: (id, error, showSnackBar: boolean) => {
if (showSnackBar) {
super(id);
}
- async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
+ async requestItems(api: MiddlewareAPI<Dispatch, RootState>, criteriaChanged?: boolean, background?: boolean) {
const dataExplorer = getDataExplorer(api.getState().dataExplorer, this.getId());
if (!dataExplorer) {
api.dispatch(allProcessesPanelDataExplorerIsNotSet());
} else {
try {
- api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.START_WORKING(this.getId())); }
const processItems = await this.services.containerRequestService.list(
{
...getParams(dataExplorer),
select: containerRequestFieldsNoMounts,
});
- api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }
api.dispatch(resourcesActions.SET_RESOURCES(processItems.items));
await api.dispatch<any>(loadMissingProcessesInformation(processItems.items));
api.dispatch(allProcessesPanelActions.SET_ITEMS({
rowsPerPage: processItems.limit
}));
} catch {
- api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }
api.dispatch(allProcessesPanelActions.SET_ITEMS({
items: [],
itemsAvailable: 0,
}
}
-const getParams = ( dataExplorer: DataExplorer ) => ({
+const getParams = (dataExplorer: DataExplorer) => ({
...dataExplorerToListParams(dataExplorer),
order: getOrder<ContainerRequestResource>(dataExplorer),
filters: getFilters(dataExplorer)
});
-const getFilters = ( dataExplorer: DataExplorer ) => {
+const getFilters = (dataExplorer: DataExplorer) => {
const columns = dataExplorer.columns as DataColumns<string, ContainerRequestResource>;
const statusColumnFilters = getDataExplorerColumnFilters(columns, 'Status');
const activeStatusFilter = Object.keys(statusColumnFilters).find(
export const dataExplorerActions = unionize({
CLEAR: ofType<{ id: string }>(),
RESET_PAGINATION: ofType<{ id: string }>(),
- REQUEST_ITEMS: ofType<{ id: string; criteriaChanged?: boolean }>(),
+ REQUEST_ITEMS: ofType<{ id: string; criteriaChanged?: boolean, background?: boolean }>(),
REQUEST_STATE: ofType<{ id: string; criteriaChanged?: boolean }>(),
SET_FETCH_MODE: ofType<{ id: string; fetchMode: DataTableFetchMode }>(),
SET_COLUMNS: ofType<{ id: string; columns: DataColumns<any, any> }>(),
export const bindDataExplorerActions = (id: string) => ({
CLEAR: () => dataExplorerActions.CLEAR({ id }),
RESET_PAGINATION: () => dataExplorerActions.RESET_PAGINATION({ id }),
- REQUEST_ITEMS: (criteriaChanged?: boolean) => dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged }),
+ REQUEST_ITEMS: (criteriaChanged?: boolean, background?: boolean) => dataExplorerActions.REQUEST_ITEMS({ id, criteriaChanged, background }),
SET_FETCH_MODE: (payload: { fetchMode: DataTableFetchMode }) => dataExplorerActions.SET_FETCH_MODE({ ...payload, id }),
SET_COLUMNS: (payload: { columns: DataColumns<any, any> }) => dataExplorerActions.SET_COLUMNS({ ...payload, id }),
SET_FILTERS: (payload: { columnName: string; filters: DataTableFilters }) => dataExplorerActions.SET_FILTERS({ ...payload, id }),
abstract requestItems(
api: MiddlewareAPI<Dispatch, RootState>,
- criteriaChanged?: boolean
+ criteriaChanged?: boolean,
+ background?: boolean
): Promise<void>;
}
export const dataExplorerMiddleware =
(service: DataExplorerMiddlewareService): Middleware =>
- (api) =>
- (next) => {
- const actions = bindDataExplorerActions(service.getId());
+ (api) =>
+ (next) => {
+ const actions = bindDataExplorerActions(service.getId());
- return (action) => {
- const handleAction =
- <T extends { id: string }>(handler: (data: T) => void) =>
- (data: T) => {
- next(action);
- if (data.id === service.getId()) {
- handler(data);
- }
- };
- dataExplorerActions.match(action, {
- SET_PAGE: handleAction(() => {
- api.dispatch(actions.REQUEST_ITEMS(false));
- }),
- SET_ROWS_PER_PAGE: handleAction(() => {
- api.dispatch(actions.REQUEST_ITEMS(true));
- }),
- SET_FILTERS: handleAction(() => {
- api.dispatch(actions.RESET_PAGINATION());
- api.dispatch(actions.REQUEST_ITEMS(true));
- }),
- TOGGLE_SORT: handleAction(() => {
- api.dispatch(actions.REQUEST_ITEMS(true));
- }),
- SET_EXPLORER_SEARCH_VALUE: handleAction(() => {
- api.dispatch(actions.RESET_PAGINATION());
- api.dispatch(actions.REQUEST_ITEMS(true));
- }),
- REQUEST_ITEMS: handleAction(({ criteriaChanged }) => {
- api.dispatch<any>(async (
- dispatch: Dispatch,
- getState: () => RootState,
- services: ServiceRepository
- ) => {
- while (true) {
- let de = getDataExplorer(
- getState().dataExplorer,
- service.getId()
- );
- switch (de.requestState) {
- case DataTableRequestState.IDLE:
- // Start a new request.
- try {
- dispatch(
- actions.SET_REQUEST_STATE({
- requestState: DataTableRequestState.PENDING,
- })
- );
- await service.requestItems(api, criteriaChanged);
- } catch {
- dispatch(
- actions.SET_REQUEST_STATE({
- requestState: DataTableRequestState.NEED_REFRESH,
- })
- );
- }
- // Now check if the state is still PENDING, if it moved to NEED_REFRESH
- // then we need to reissue requestItems
- de = getDataExplorer(
+ return (action) => {
+ const handleAction =
+ <T extends { id: string }>(handler: (data: T) => void) =>
+ (data: T) => {
+ next(action);
+ if (data.id === service.getId()) {
+ handler(data);
+ }
+ };
+ dataExplorerActions.match(action, {
+ SET_PAGE: handleAction(() => {
+ api.dispatch(actions.REQUEST_ITEMS(false));
+ }),
+ SET_ROWS_PER_PAGE: handleAction(() => {
+ api.dispatch(actions.REQUEST_ITEMS(true));
+ }),
+ SET_FILTERS: handleAction(() => {
+ api.dispatch(actions.RESET_PAGINATION());
+ api.dispatch(actions.REQUEST_ITEMS(true));
+ }),
+ TOGGLE_SORT: handleAction(() => {
+ api.dispatch(actions.REQUEST_ITEMS(true));
+ }),
+ SET_EXPLORER_SEARCH_VALUE: handleAction(() => {
+ api.dispatch(actions.RESET_PAGINATION());
+ api.dispatch(actions.REQUEST_ITEMS(true));
+ }),
+ REQUEST_ITEMS: handleAction(({ criteriaChanged, background }) => {
+ api.dispatch<any>(async (
+ dispatch: Dispatch,
+ getState: () => RootState,
+ services: ServiceRepository
+ ) => {
+ while (true) {
+ let de = getDataExplorer(
getState().dataExplorer,
service.getId()
);
- const complete =
- de.requestState === DataTableRequestState.PENDING;
- dispatch(
- actions.SET_REQUEST_STATE({
- requestState: DataTableRequestState.IDLE,
- })
- );
- if (complete) {
- return;
+ switch (de.requestState) {
+ case DataTableRequestState.IDLE:
+ // Start a new request.
+ try {
+ dispatch(
+ actions.SET_REQUEST_STATE({
+ requestState: DataTableRequestState.PENDING,
+ })
+ );
+ await service.requestItems(api, criteriaChanged, background);
+ } catch {
+ dispatch(
+ actions.SET_REQUEST_STATE({
+ requestState: DataTableRequestState.NEED_REFRESH,
+ })
+ );
+ }
+ // Now check if the state is still PENDING, if it moved to NEED_REFRESH
+ // then we need to reissue requestItems
+ de = getDataExplorer(
+ getState().dataExplorer,
+ service.getId()
+ );
+ const complete =
+ de.requestState === DataTableRequestState.PENDING;
+ dispatch(
+ actions.SET_REQUEST_STATE({
+ requestState: DataTableRequestState.IDLE,
+ })
+ );
+ if (complete) {
+ return;
+ }
+ break;
+ case DataTableRequestState.PENDING:
+ // State is PENDING, move it to NEED_REFRESH so that when the current request finishes it starts a new one.
+ dispatch(
+ actions.SET_REQUEST_STATE({
+ requestState: DataTableRequestState.NEED_REFRESH,
+ })
+ );
+ return;
+ case DataTableRequestState.NEED_REFRESH:
+ // Nothing to do right now.
+ return;
}
- break;
- case DataTableRequestState.PENDING:
- // State is PENDING, move it to NEED_REFRESH so that when the current request finishes it starts a new one.
- dispatch(
- actions.SET_REQUEST_STATE({
- requestState: DataTableRequestState.NEED_REFRESH,
- })
- );
- return;
- case DataTableRequestState.NEED_REFRESH:
- // Nothing to do right now.
- return;
- }
- }
+ }
+ });
+ }),
+ default: () => next(action),
});
- }),
- default: () => next(action),
- });
- };
- };
+ };
+ };
case containerRequest.containerUuid && !container:
return ProcessStatus.UNKNOWN;
+ case containerRequest.state === ContainerRequestState.UNCOMMITTED:
+ return ProcessStatus.DRAFT;
+
+ case containerRequest.state === ContainerRequestState.FINAL &&
+ container?.state === ContainerState.RUNNING:
+ // It's right about to be completed but we haven't
+ // gotten the updated container record yet
+ return ProcessStatus.RUNNING;
+
case containerRequest.state === ContainerRequestState.FINAL &&
container?.state !== ContainerState.COMPLETE:
// Request was finalized before its container started (or the
// container was cancelled)
return ProcessStatus.CANCELLED;
- case containerRequest.state === ContainerRequestState.UNCOMMITTED:
- return ProcessStatus.DRAFT;
-
case container && container.state === ContainerState.COMPLETE:
if (container?.exitCode === 0) {
if (containerRequest && container.finishedAt) {
super(id);
}
- async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
+ async requestItems(api: MiddlewareAPI<Dispatch, RootState>, criteriaChanged?: boolean, background?: boolean) {
const state = api.getState();
const dataExplorer = getDataExplorer(state.dataExplorer, this.getId());
const projectUuid = getProjectPanelCurrentUuid(state);
api.dispatch(projectPanelDataExplorerIsNotSet());
} else {
try {
- api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.START_WORKING(this.getId())); }
const response = await this.services.groupsService.contents(projectUuid, getParams(dataExplorer, !!isProjectTrashed));
const resourceUuids = response.items.map(item => item.uuid);
api.dispatch<any>(updateFavorites(resourceUuids));
);
api.dispatch(couldNotFetchProjectContents());
} finally {
- api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }
}
}
}
super(id);
}
- async requestItems(api: MiddlewareAPI<Dispatch, RootState>) {
+ async requestItems(api: MiddlewareAPI<Dispatch, RootState>, criteriaChanged?: boolean, background?: boolean) {
const state = api.getState();
const parentContainerRequestUuid = state.processPanel.containerRequestUuid;
if (parentContainerRequestUuid === "") { return; }
const dataExplorer = getDataExplorer(state.dataExplorer, this.getId());
try {
- api.dispatch(progressIndicatorActions.START_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.START_WORKING(this.getId())); }
const parentContainerRequest = await this.services.containerRequestService.get(parentContainerRequestUuid);
if (parentContainerRequest.containerUuid) {
const containerRequests = await this.services.containerRequestService.list(
{
- ...getParams(dataExplorer, parentContainerRequest) ,
+ ...getParams(dataExplorer, parentContainerRequest),
select: containerRequestFieldsNoMounts
});
api.dispatch(updateResources(containerRequests.items));
// Populate the actual user view
api.dispatch(setItems(containerRequests));
}
- api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }
} catch {
- api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId()));
+ if (!background) { api.dispatch(progressIndicatorActions.PERSIST_STOP_WORKING(this.getId())); }
api.dispatch(couldNotFetchSubprocesses());
}
}
export const getFilters = (
dataExplorer: DataExplorer,
parentContainerRequest: ContainerRequestResource) => {
- const columns = dataExplorer.columns as DataColumns<string, ProcessResource>;
- const statusColumnFilters = getDataExplorerColumnFilters(columns, 'Status');
- const activeStatusFilter = Object.keys(statusColumnFilters).find(
- filterName => statusColumnFilters[filterName].selected
- ) || ProcessStatusFilter.ALL;
+ const columns = dataExplorer.columns as DataColumns<string, ProcessResource>;
+ const statusColumnFilters = getDataExplorerColumnFilters(columns, 'Status');
+ const activeStatusFilter = Object.keys(statusColumnFilters).find(
+ filterName => statusColumnFilters[filterName].selected
+ ) || ProcessStatusFilter.ALL;
- // Get all the subprocess' container requests and containers.
- const fb = new FilterBuilder().addEqual('requesting_container_uuid', parentContainerRequest.containerUuid);
- const statusFilters = buildProcessStatusFilters(fb, activeStatusFilter).getFilters();
+ // Get all the subprocess' container requests and containers.
+ const fb = new FilterBuilder().addEqual('requesting_container_uuid', parentContainerRequest.containerUuid);
+ const statusFilters = buildProcessStatusFilters(fb, activeStatusFilter).getFilters();
- const nameFilters = dataExplorer.searchValue
- ? new FilterBuilder()
- .addILike("name", dataExplorer.searchValue)
- .getFilters()
- : '';
+ const nameFilters = dataExplorer.searchValue
+ ? new FilterBuilder()
+ .addILike("name", dataExplorer.searchValue)
+ .getFilters()
+ : '';
- return joinFilters(
- nameFilters,
- statusFilters
- );
- };
+ return joinFilters(
+ nameFilters,
+ statusFilters
+ );
+};
export const setItems = (listResults: ListResults<ProcessResource>) =>
subprocessPanelActions.SET_ITEMS({
}
const proc = getProcess(state.processPanel.containerRequestUuid)(state.resources);
if (proc && proc.container && proc.container.uuid === message.properties["new_attributes"]["requesting_container_uuid"]) {
- store.dispatch(subprocessPanelActions.REQUEST_ITEMS());
+ store.dispatch(subprocessPanelActions.REQUEST_ITEMS(false, true));
return;
}
}
const subproc = getSubprocesses(state.processPanel.containerRequestUuid)(state.resources);
for (const sb of subproc) {
if (sb.containerRequest.uuid === message.objectUuid || (sb.container && sb.container.uuid === message.objectUuid)) {
- store.dispatch(subprocessPanelActions.REQUEST_ITEMS());
+ store.dispatch(subprocessPanelActions.REQUEST_ITEMS(false, true));
break;
}
}
}
if (matchAllProcessesRoute(location)) {
- store.dispatch(allProcessesPanelActions.REQUEST_ITEMS());
+ store.dispatch(allProcessesPanelActions.REQUEST_ITEMS(false, true));
}
if (matchProjectRoute(location) && message.objectOwnerUuid === getProjectPanelCurrentUuid(state)) {
- store.dispatch(projectPanelActions.REQUEST_ITEMS());
+ store.dispatch(projectPanelActions.REQUEST_ITEMS(false, true));
}
return;
default: