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

fix: remove navigation root and own and shared calls #1211

Merged
merged 4 commits into from
May 3, 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
21 changes: 1 addition & 20 deletions cypress/e2e/item/home/home.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ITEM_PAGE_SIZE } from '@/config/constants';

import i18n, { BUILDER_NAMESPACE } from '../../../../src/config/i18n';
import i18n from '../../../../src/config/i18n';
import { HOME_PATH, ITEMS_PATH } from '../../../../src/config/paths';
import {
ACCESSIBLE_ITEMS_NEXT_PAGE_BUTTON_SELECTOR,
Expand All @@ -9,21 +9,16 @@ import {
ITEMS_GRID_PAGINATION_ID,
ITEMS_TABLE_ROW,
ITEM_SEARCH_INPUT_ID,
NAVIGATION_ROOT_ID,
buildItemCard,
buildItemsTableRowIdAttribute,
buildItemsTableRowSelector,
} from '../../../../src/config/selectors';
import { ItemLayoutMode } from '../../../../src/enums';
import { BUILDER } from '../../../../src/langs/constants';
import { SAMPLE_ITEMS, generateOwnItems } from '../../../fixtures/items';
import { CURRENT_USER } from '../../../fixtures/members';
import { NAVIGATION_LOAD_PAUSE } from '../../../support/constants';
import { ItemForTest } from '../../../support/types';

const translateBuilder = (key: string) =>
i18n.t(key, { ns: BUILDER_NAMESPACE });

const sampleItems = generateOwnItems(30);

// register a custom one time interceptor to listen specifically
Expand Down Expand Up @@ -169,23 +164,13 @@ describe('Home', () => {
}
});

// root title
cy.get(`#${NAVIGATION_ROOT_ID}`).contains(
translateBuilder(BUILDER.NAVIGATION_MY_ITEMS_TITLE),
);

// visit child
const { id: childChildId } = SAMPLE_ITEMS.items[3];
cy.goToItemInGrid(childChildId);

// expect no children
cy.get(`#${ITEMS_GRID_NO_ITEM_ID}`).should('exist');

// root title
cy.get(`#${NAVIGATION_ROOT_ID}`).contains(
translateBuilder(BUILDER.NAVIGATION_MY_ITEMS_TITLE),
);

// return parent with navigation and should display children
cy.wait(NAVIGATION_LOAD_PAUSE);
cy.goToItemWithNavigation(childId);
Expand All @@ -200,10 +185,6 @@ describe('Home', () => {
cy.get(`#${buildItemCard(item.id)}`).should('exist');
}
});
// root title
cy.get(`#${NAVIGATION_ROOT_ID}`).contains(
translateBuilder(BUILDER.NAVIGATION_MY_ITEMS_TITLE),
);
});
});
});
Expand Down
73 changes: 0 additions & 73 deletions cypress/e2e/item/shared/sharedItems.cy.ts

This file was deleted.

8 changes: 4 additions & 4 deletions cypress/e2e/item/view/viewFolder.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import i18n from '../../../../src/config/i18n';
import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import { buildItemPath } from '../../../../src/config/paths';
import {
ITEM_SEARCH_INPUT_ID,
NAVIGATION_ROOT_ID,
NAVIGATION_HOME_ID,
buildItemCard,
buildItemsTableRowIdAttribute,
} from '../../../../src/config/selectors';
Expand Down Expand Up @@ -47,7 +47,7 @@ describe('View Folder', () => {
expectFolderViewScreenLayout({ item: SAMPLE_ITEMS.items[0] });

// visit home
cy.get(`#${NAVIGATION_ROOT_ID} [href="${HOME_PATH}"]`).click();
cy.get(`#${NAVIGATION_HOME_ID}`).click();

// should get accessible items
cy.wait('@getAccessibleItems').then(({ response: { body } }) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('View Folder', () => {

expectFolderViewScreenLayout({ item: SAMPLE_ITEMS.items[0] });
// visit home
cy.get(`#${NAVIGATION_ROOT_ID} [href="${HOME_PATH}"]`).click();
cy.get(`#${NAVIGATION_HOME_ID}`).click();

cy.wait('@getAccessibleItems').then(({ response: { body } }) => {
// check item is created and displayed
Expand Down
78 changes: 16 additions & 62 deletions src/components/layout/Navigation.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import { useLocation, useParams } from 'react-router-dom';
import { useLocation, useNavigate, useParams } from 'react-router-dom';

import { HomeMenu, ItemMenu, Navigation } from '@graasp/ui';
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
import { IconButton } from '@mui/material';

import { Navigation } from '@graasp/ui';

import { Home } from 'lucide-react';

import { useBuilderTranslation } from '../../config/i18n';
import {
BOOKMARKED_ITEMS_PATH,
HOME_PATH,
SHARED_ITEMS_PATH,
buildItemPath,
} from '../../config/paths';
import { HOME_PATH, buildItemPath } from '../../config/paths';
import { hooks } from '../../config/queryClient';
import {
NAVIGATION_HOME_ID,
NAVIGATION_ROOT_ID,
buildNavigationLink,
} from '../../config/selectors';
import { BUILDER } from '../../langs/constants';
import { buildExtraItems } from './utils';

const {
useItem,
useParents,
useCurrentMember,
useChildren,
useOwnItems,
useSharedItems,
} = hooks;
const { useItem, useParents, useCurrentMember, useChildren } = hooks;

const Navigator = (): JSX.Element | null => {
const navigate = useNavigate();
const { t: translateBuilder } = useBuilderTranslation();
const { itemId } = useParams();
const { pathname } = useLocation();
Expand All @@ -42,69 +36,29 @@ const Navigator = (): JSX.Element | null => {
enabled: !!itemPath,
});

const isParentOwned =
currentMember &&
(item?.creator?.id ?? parents?.[0]?.creator?.id) === currentMember?.id;

if (isItemLoading || areParentsLoading) {
return null;
}

const buildToItemPath = (id: string) => buildItemPath(id);

const menu = [
// todo: remove distinction -> not a good idea to show the whole root in arrow
{
name: translateBuilder(BUILDER.NAVIGATION_MY_ITEMS_TITLE),
id: 'home',
to: HOME_PATH,
},
{
name: translateBuilder(BUILDER.NAVIGATION_SHARED_ITEMS_TITLE),
id: 'shared',
to: SHARED_ITEMS_PATH,
},
{
name: translateBuilder(BUILDER.NAVIGATION_BOOKMARKED_ITEMS_TITLE),
id: 'bookmark',
to: BOOKMARKED_ITEMS_PATH,
},
];

const renderRoot = () => {
// no access to root if signed out
if (!currentMember) {
return null;
}

const selected =
isParentOwned || pathname === HOME_PATH ? menu[0] : menu[1];

return (
<>
<HomeMenu
selected={selected}
elements={menu}
buildMenuItemId={buildNavigationLink}
/>
<ItemMenu
itemId="root"
useChildren={
isParentOwned || pathname === HOME_PATH
? (useOwnItems as any)
: useSharedItems
}
buildToItemPath={buildToItemPath}
/>
<IconButton id={NAVIGATION_HOME_ID} onClick={() => navigate(HOME_PATH)}>
pyphilia marked this conversation as resolved.
Show resolved Hide resolved
<Home />
</IconButton>
<ArrowForwardIosIcon sx={{ m: 2 }} fontSize="inherit" />
</>
);
};

if (
item === undefined &&
pathname !== SHARED_ITEMS_PATH &&
pathname !== HOME_PATH
) {
if (item === undefined && pathname !== HOME_PATH) {
return null;
}

Expand Down
1 change: 1 addition & 0 deletions src/config/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export const buildInvitationTableRowSelector = (id: string): string =>
export const ITEM_RESEND_INVITATION_BUTTON_CLASS = 'itemResendInvitationButton';
export const CREATE_MEMBERSHIP_FORM_ID = 'createMembershipFormId';
export const NAVIGATION_ROOT_ID = 'navigationRoot';
export const NAVIGATION_HOME_ID = 'navigationHome';
export const HEADER_MEMBER_MENU_BUTTON_ID = 'headerMemberMenuButton';
export const HEADER_MEMBER_MENU_SEE_PROFILE_BUTTON_ID =
'headerMemberMenuSeeProfileButton';
Expand Down