Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NickAkhmetov/CAT-925 ensure visualizations for support image pyramid datasets use parent dataset UUID for notebooks #3570

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-cat-925.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Ensure visualizations for image pyramids use parent UUID to fetch notebooks.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface VisualizationProps {
shouldDisplayHeader: boolean;
shouldMountVitessce?: boolean;
markerGene?: string;
parentUuid?: string;
}

function Visualization({
Expand All @@ -60,6 +61,7 @@ function Visualization({
shouldDisplayHeader,
shouldMountVitessce = true,
markerGene,
parentUuid,
}: VisualizationProps) {
const { vizIsFullscreen, expandViz, vizTheme, setVitessceState, setVitessceStateDebounced, setVizNotebookId } =
useVisualizationStore(visualizationStoreSelector);
Expand Down Expand Up @@ -128,7 +130,7 @@ function Visualization({
mapped_data_access_level={mapped_data_access_level}
hasNotebook={hasNotebook}
/>
<VisualizationDownloadButton uuid={uuid} hasNotebook={hasNotebook} />
<VisualizationDownloadButton uuid={uuid} hasNotebook={hasNotebook} parentUuid={parentUuid} />
<VisualizationShareButton />
<VisualizationThemeSwitch />
<SecondaryBackgroundTooltip title="Switch to Fullscreen">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ const tooltip = 'Download Jupyter Notebook';
interface VisualizationDownloadButtonProps {
uuid?: string;
hasNotebook?: boolean;
parentUuid?: string;
}

function VisualizationDownloadButton({ uuid, hasNotebook }: VisualizationDownloadButtonProps) {
function VisualizationDownloadButton({ uuid, hasNotebook, parentUuid }: VisualizationDownloadButtonProps) {
const trackEntityPageEvent = useTrackEntityPageEvent();
const { toastError } = useSnackbarActions();

const downloadNotebook = useCallback(() => {
trackEntityPageEvent({ action: `Vitessce / ${tooltip}` });
postAndDownloadFile({
url: `/notebooks/entities/dataset/${uuid}.ws.ipynb`,
url: `/notebooks/entities/dataset/${parentUuid ?? uuid}.ws.ipynb`,
body: {},
})
.then()
.catch(() => {
toastError('Failed to download Jupyter Notebook');
});
}, [uuid, toastError, trackEntityPageEvent]);
}, [parentUuid, uuid, toastError, trackEntityPageEvent]);

if (!uuid || !hasNotebook) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ function VisualizationWrapper({
}),
[isPublicationPage, shouldDisplayHeader, uuid],
);
// Find parent UUID for the visualization if present
const parentUuid: string | undefined = useMemo(() => {
if (Array.isArray(vitData)) {
const vitDataArray = vitData as object[];
const found = vitDataArray.find((data) => 'parentUuid' in data) as { parentUuid: string } | undefined;
return found?.parentUuid;
}
if ('parentUuid' in vitData) {
return (vitData as { parentUuid: string }).parentUuid;
}
return undefined;
}, [vitData]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since vitData is passed to Visualization, could this be calculated there instead of being passed as an extra prop?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call! No need to have the extra layer of prop drilling.


return (
<VizContainerStyleContext.Provider value={containerStyles}>
<VisualizationErrorBoundary>
Expand All @@ -51,6 +64,7 @@ function VisualizationWrapper({
shouldDisplayHeader={shouldDisplayHeader}
shouldMountVitessce={hasBeenMounted}
markerGene={markerGene}
parentUuid={parentUuid}
/>
</Suspense>
</VisualizationErrorBoundary>
Expand Down
6 changes: 5 additions & 1 deletion context/app/static/js/pages/Dataset/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ export function useVitessceConf(uuid: string, parentUuid?: string) {
if (parentUuid) {
urlParams.set('parent', parentUuid);
}
return useSWR<VitessceConf>(getVitessceConfKey(uuid, groupsToken), (_key: unknown) =>
const swr = useSWR<VitessceConf>(getVitessceConfKey(uuid, groupsToken), (_key: unknown) =>
fetcher({ url: `${base}?${urlParams.toString()}`, requestInit: { headers: getAuthHeader(groupsToken) } }),
);
if (parentUuid) {
return { ...swr, data: { ...swr.data, parentUuid } };
}
return swr;
}

function useProcessedDatasets(includeComponents?: boolean) {
Expand Down
Loading