Skip to content

Commit

Permalink
WP-835: Click through file location in site search results is failing (
Browse files Browse the repository at this point in the history
…#1045)

* WP-835: Fix site search and data files usage of compress and extract

* handle no allocation scenario
  • Loading branch information
chandra-tacc authored Jan 29, 2025
1 parent 19a8872 commit 486051b
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,26 @@ const DataFilesToolbar = ({ scheme, api }) => {
(scheme === 'private' || scheme === 'projects')
);

const hasActiveAllocation = (state) => {
return (
state.allocations.portal_alloc ||
(Array.isArray(state.allocations.active) &&
state.allocations.active.length > 0)
);
};

const showCompress = !!useSelector(
(state) => state.workbench.config.extractApp && modifiableUserData
(state) =>
state.workbench.config.extractApp &&
modifiableUserData &&
hasActiveAllocation(state)
);

const showExtract = !!useSelector(
(state) => state.workbench.config.compressApp && modifiableUserData
(state) =>
state.workbench.config.compressApp &&
modifiableUserData &&
hasActiveAllocation(state)
);

const showMakePublic = useSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,68 @@ describe('DataFilesToolbar', () => {
},
});
});
it('disables compress and extract when allocation is unavailable', () => {
const { queryByText } = renderComponent(
<DataFilesToolbar scheme="private" api="tapis" />,
mockStore({
allocations: { portal_alloc: undefined, active: [] },
workbench: {
config: {
extractApp: { id: 'extract', version: '0.0.3' },
compressApp: { id: 'compress', version: '0.0.3' },
},
},
files: {
params: {
FilesListing: {
system: 'frontera.home.username',
path: 'home/username/hello.zip',
scheme: 'private',
},
},
listing: { FilesListing: [] },
selected: { FilesListing: [] },
operationStatus: { trash: false },
},
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
expect(queryByText(/compress/)).toBeFalsy();
expect(queryByText(/extract/)).toBeFalsy();
});
it('enables compress and extract when allocation is available', () => {
const { queryByText } = renderComponent(
<DataFilesToolbar scheme="private" api="tapis" />,
mockStore({
allocations: { portal_alloc: undefined, active: ['foo'] },
workbench: {
config: {
extractApp: { id: 'extract', version: '0.0.3' },
compressApp: { id: 'compress', version: '0.0.3' },
},
},
files: {
params: {
FilesListing: {
system: 'frontera.home.username',
path: 'home/username/hello.zip',
scheme: 'private',
},
},
listing: { FilesListing: [] },
selected: { FilesListing: [] },
operationStatus: { trash: false },
},
systems: systemsFixture,
projects: { metadata: [] },
authenticatedUser: { user: { username: 'testuser' } },
}),
createMemoryHistory()
);
expect(queryByText(/compress/)).toBeDefined();
expect(queryByText(/extract/)).toBeDefined();
});
});
22 changes: 18 additions & 4 deletions client/src/hooks/datafiles/mutations/useCompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ function useCompress() {
(state: any) => state.workbench.config.compressApp
);

const defaultAllocation = useSelector(
(state: any) =>
state.allocations.portal_alloc || state.allocations.active[0].projectName
);
const defaultAllocation = useSelector((state: any) => {
if (state.allocations.portal_alloc) {
return state.allocations.portal_alloc;
}
if (
Array.isArray(state.allocations.active) &&
state.allocations.active.length > 0
) {
return state.allocations.active[0].projectName || null;
}
return null;
});

const systems = useSelector(
(state: any) => state.systems.storage.configuration
Expand Down Expand Up @@ -74,6 +82,12 @@ function useCompress() {
defaultPrivateSystem = undefined;
}

if (!defaultAllocation) {
throw new Error('You need an allocation to compress.', {
cause: 'compressError',
});
}

if (scheme !== 'private' && scheme !== 'projects') {
defaultPrivateSystem = systems.find((s: any) => s.default);

Expand Down
29 changes: 22 additions & 7 deletions client/src/hooks/datafiles/mutations/useExtract.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useSelector, useDispatch, shallowEqual } from 'react-redux';
import { getExtractParams } from 'utils/getExtractParams';
import { apiClient } from 'utils/apiClient';
Expand Down Expand Up @@ -43,13 +43,23 @@ function useExtract() {
const extractApp = useSelector(
(state: any) => state.workbench.config.extractApp
);
const defaultAllocation = useSelector((state: any) => {
if (state.allocations.portal_alloc) {
return state.allocations.portal_alloc;
}
if (
Array.isArray(state.allocations.active) &&
state.allocations.active.length > 0
) {
return state.allocations.active[0].projectName || null;
}
return null;
});

const defaultAllocation = useSelector(
(state: any) =>
state.allocations.portal_alloc || state.allocations.active[0].projectName
);

const latestExtract = getAppUtil(extractApp.id, extractApp.version);
const { data: latestExtract } = useQuery({
queryKey: ['extract-app', extractApp.id, extractApp.version],
queryFn: () => getAppUtil(extractApp.id, extractApp.version),
});

const { mutateAsync } = useMutation({ mutationFn: submitJobUtil });

Expand All @@ -58,6 +68,11 @@ function useExtract() {
type: 'DATA_FILES_SET_OPERATION_STATUS',
payload: { status: 'RUNNING', operation: 'extract' },
});
if (!defaultAllocation) {
throw new Error('You need an allocation to extract.', {
cause: 'extractError',
});
}

const params = getExtractParams(
file,
Expand Down

0 comments on commit 486051b

Please sign in to comment.