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

Support user without projects in the UI #1578

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from all 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
21 changes: 16 additions & 5 deletions frontend/src/layouts/AppLayout/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const useSideNavigation = () => {
const { t } = useTranslation();
const userName = useAppSelector(selectUserName) ?? '';
const { pathname } = useLocation();
const { selectedProject } = useProjectDropdown();
const { selectedProject, projectsDropdownList } = useProjectDropdown();
const [isAvailableAdministrationLinks] = usePermissionGuard({ allowedGlobalRoles: [GlobalUserRole.ADMIN] });

const isPoolDetails = Boolean(useMatch(ROUTES.FLEETS.DETAILS.TEMPLATE));
Expand Down Expand Up @@ -63,7 +63,7 @@ export const useSideNavigation = () => {
].filter(Boolean);

const navLinks: SideNavigationProps['items'] = [
{
projectsDropdownList.length && {
type: 'section',
text: t('navigation.project'),
items: projectLinks,
Expand Down Expand Up @@ -110,15 +110,14 @@ export const useSideNavigation = () => {
export const useProjectDropdown = () => {
const { t } = useTranslation();
const { pathname } = useLocation();
const userName = useAppSelector(selectUserName) ?? '';
const navigate = useNavigate();
const params = useParams();
const paramProjectName = params.projectName;
const { data } = useGetProjectsQuery();
const { data, isLoading } = useGetProjectsQuery();
const [selectedProject, setSelectedProject] = useLocalStorageState('selected-project', data?.[0]?.project_name ?? null);
const { isAvailableProjectManaging } = useCheckAvailableProjectPermission();

const isAvailableProjectDropdown =
![ROUTES.PROJECT.LIST, ROUTES.ADMINISTRATION.RUNS.LIST].includes(pathname) && pathname.indexOf(ROUTES.USER.LIST) !== 0;
const onFollowProject: ButtonDropdownProps['onItemFollow'] = (event) => {
event.preventDefault();

Expand All @@ -136,6 +135,13 @@ export const useProjectDropdown = () => {
}
}, [paramProjectName]);

useEffect(() => {
if (!isLoading && data?.length === 0) {
navigate(ROUTES.USER.DETAILS.FORMAT(userName));
setSelectedProject(null);
}
}, [isLoading]);

useEffect(() => {
if (data?.length) {
if (!selectedProject) {
Expand Down Expand Up @@ -175,5 +181,10 @@ export const useProjectDropdown = () => {
return items;
}, [data, isAvailableProjectManaging]);

const isAvailableProjectDropdown =
![ROUTES.PROJECT.LIST, ROUTES.ADMINISTRATION.RUNS.LIST].includes(pathname) &&
pathname.indexOf(ROUTES.USER.LIST) !== 0 &&
projectsDropdownList.length;

return { projectsDropdownList, selectedProject, isAvailableProjectDropdown, onFollowProject } as const;
};