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

Austenem/CAT-872 improve redirect toast #3556

Merged
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
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-improve-redirect-toast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Update Unified View redirect toast to be more informative.
6 changes: 5 additions & 1 deletion context/app/routes_browse.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def details(type, uuid):
type='dataset',
uuid=supported_entity[0]['uuid'],
_anchor=anchor,
redirected=True))
redirected=True,
redirectedFromId=entity['hubmap_id'],
redirectedFromPipeline=entity['pipeline']))
austenem marked this conversation as resolved.
Show resolved Hide resolved

if type != actual_type:
return redirect(url_for('routes_browse.details', type=actual_type, uuid=uuid))
Expand All @@ -89,6 +91,8 @@ def details(type, uuid):
**get_default_flask_data(),
'entity': entity,
'redirected': redirected,
'redirectedFromId': request.args.get('redirectedFromId'),
'redirectedFromPipeline': request.args.get('redirectedFromPipeline')
}

if type == 'publication':
Expand Down
2 changes: 2 additions & 0 deletions context/app/static/js/components/Contexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export interface FlaskDataContextType {
title: string; // preview page title
vis_lifted_uuid?: string;
redirected?: boolean;
redirectedFromId?: string;
redirectedFromPipeline?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The .get without a second argument will resolve to None if the key isn't present and will then be null once converted to json. The types here should be ?: string | null.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Got it - is this preferable to providing a false second value to .get?

}

export const FlaskDataContext = createContext<FlaskDataContextType>('FlaskDataContext');
Expand Down
13 changes: 10 additions & 3 deletions context/app/static/js/pages/Dataset/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,20 @@ function useProcessedDatasetsSections(): { sections: TableOfContentsItem | false
}

export function useRedirectAlert() {
const { redirected } = useFlaskDataContext();
const { redirected, redirectedFromId, redirectedFromPipeline } = useFlaskDataContext();
const { toastInfo } = useSnackbarActions();

useEffect(() => {
if (redirected) {
toastInfo('You have been redirected to the unified view for this dataset.');
if (redirectedFromId && redirectedFromPipeline) {
toastInfo(
`You have been redirected to the unified view for ${redirectedFromPipeline} dataset ${redirectedFromId}.`,
);
} else {
toastInfo('You have been redirected to the unified view for this dataset.');
}
}
}, [redirected, toastInfo]);
}, [redirected, toastInfo, redirectedFromId, redirectedFromPipeline]);
}

export { useProcessedDatasets, useProcessedDatasetsSections };
Expand Down
Loading