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

redesign landing page systems #1024 #1025

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
092d050
redesign landing page systems #1024
joshuadkitenge Oct 11, 2024
a141694
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 11, 2024
d18f8f1
Rename actions menu and view tabs #1024
joshuadkitenge Oct 11, 2024
2b07823
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 16, 2024
3042b8e
Use common components #1024
joshuadkitenge Oct 17, 2024
cbac313
Merge branch 'develop' into redesign-landing-page-catalogue-items-#1022
joshuadkitenge Oct 17, 2024
6a3447c
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 17, 2024
88ee997
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 17, 2024
5569c8f
fix type in tabView #1024
joshuadkitenge Oct 17, 2024
1264ec0
fix e2e test #1024
joshuadkitenge Oct 17, 2024
c25186d
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 17, 2024
8440ea0
remove .only #1024
joshuadkitenge Oct 17, 2024
c197264
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 17, 2024
8cac27a
add more spacing #1024
joshuadkitenge Oct 17, 2024
8aa85cd
remove comment #1024
joshuadkitenge Oct 17, 2024
e2c0d64
Merge branch 'redesign-landing-page-catalogue-items-#1022' into redes…
joshuadkitenge Oct 17, 2024
0d46834
address review comments #1024
joshuadkitenge Oct 17, 2024
7dd2969
Move the the Action menu outside the component #1024
joshuadkitenge Oct 17, 2024
d4c614a
address review comments #1024
joshuadkitenge Oct 21, 2024
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 cypress/e2e/with_api/catalogueItems/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const modifyCatalogueItem = (
cy.findByText(values.notes).should('exist');
}
cy.go('back');
cy.go('back');
}
};

Expand Down
5 changes: 3 additions & 2 deletions cypress/e2e/with_mock_data/systems.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('Systems', () => {
cy.findByRole('link', { name: 'Pulse Laser' }).should('be.visible');
cy.findByRole('link', { name: 'Laser Tech' }).should('be.visible');
cy.findByRole('link', { name: 'Laser Star' }).should('be.visible');
cy.findByRole('link', { name: "Laser Xpress" }).should('be.visible');
cy.findByRole('link', { name: 'Laser Xpress' }).should('be.visible');

// One in title, one in breadcrumbs
cy.findAllByText('Plasma Beam').should('have.length', 2);
Expand Down Expand Up @@ -580,7 +580,8 @@ describe('Systems', () => {
it('edits a system from a landing page', () => {
cy.visit('/systems/65328f34a40ff5301575a4e3');

cy.findByRole('button', { name: 'Edit System' }).click();
cy.findByRole('button', { name: 'systems page actions menu' }).click();
cy.findByText('Edit').click();

cy.findByLabelText('Name *').clear();
cy.findByLabelText('Name *').type('System name');
Expand Down
70 changes: 42 additions & 28 deletions src/catalogue/items/catalogueItemsLandingPage.component.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
import InventoryOutlinedIcon from '@mui/icons-material/InventoryOutlined';
import NotesIcon from '@mui/icons-material/Notes';
import {
Box,
Expand All @@ -11,7 +12,11 @@ import Grid from '@mui/material/Grid';
import Typography from '@mui/material/Typography';
import React from 'react';
import { Link, useParams } from 'react-router-dom';
import { BreadcrumbsInfo } from '../../api/api.types';
import {
BreadcrumbsInfo,
CatalogueCategory,
CatalogueItem,
} from '../../api/api.types';
import {
useGetCatalogueBreadcrumbs,
useGetCatalogueCategory,
Expand All @@ -26,6 +31,33 @@ import Breadcrumbs from '../../view/breadcrumbs.component';
import { useNavigateToCatalogue } from '../catalogue.component';
import CatalogueItemsDialog from './catalogueItemsDialog.component';

const CatalogueItemsActionMenu = (props: {
catalogueItem: CatalogueItem;
catalogueCategory: CatalogueCategory;
}) => {
const { catalogueItem, catalogueCategory } = props;
const [editItemDialogOpen, setEditItemDialogOpen] =
React.useState<boolean>(false);
return (
<ActionMenu
ariaLabelPrefix="catalogue items landing page"
printMenuItem
editMenuItem={{
onClick: () => setEditItemDialogOpen(true),
dialog: (
<CatalogueItemsDialog
open={editItemDialogOpen}
onClose={() => setEditItemDialogOpen(false)}
parentInfo={catalogueCategory}
selectedCatalogueItem={catalogueItem}
requestType="patch"
/>
),
}}
/>
);
};

function CatalogueItemsLandingPage() {
const { catalogue_item_id: catalogueItemId } = useParams();
const navigateToCatalogue = useNavigateToCatalogue();
Expand Down Expand Up @@ -58,9 +90,6 @@ function CatalogueItemsLandingPage() {
catalogueItemIdData?.manufacturer_id
);

const [editItemDialogOpen, setEditItemDialogOpen] =
React.useState<boolean>(false);

return (
<Grid container flexDirection="column">
<Grid
Expand Down Expand Up @@ -88,7 +117,7 @@ function CatalogueItemsLandingPage() {
/>
</Grid>
</Grid>
{catalogueItemIdData && (
{catalogueItemIdData && catalogueCategoryData && (
<Grid item container justifyContent="center" xs={12}>
<Grid
item
Expand Down Expand Up @@ -137,21 +166,9 @@ function CatalogueItemsLandingPage() {
<Grid item container justifyContent={'flex-end'} xs={12} sm={2}>
{/* Actions Section */}
<Grid item>
<ActionMenu
ariaLabelPrefix="catalogue items landing page"
printMenuItem
editMenuItem={{
onClick: () => setEditItemDialogOpen(true),
dialog: (
<CatalogueItemsDialog
open={editItemDialogOpen}
onClose={() => setEditItemDialogOpen(false)}
parentInfo={catalogueCategoryData}
selectedCatalogueItem={catalogueItemIdData}
requestType="patch"
/>
),
}}
<CatalogueItemsActionMenu
catalogueItem={catalogueItemIdData}
catalogueCategory={catalogueCategoryData}
/>
</Grid>
<Grid item>
Expand All @@ -160,6 +177,7 @@ function CatalogueItemsLandingPage() {
variant="outlined"
component={Link}
to={'items'}
startIcon={<InventoryOutlinedIcon />}
>
Items
</Button>
Expand All @@ -171,7 +189,9 @@ function CatalogueItemsLandingPage() {
defaultTab="Information"
ariaLabelPrefix="catalogue items landing page"
galleryEntityId={catalogueItemIdData.id}
galleryOrder={1}
attachmentsEntityId={catalogueItemIdData.id}
attachmentsOrder={2}
tabData={[
{
value: 'Information',
Expand Down Expand Up @@ -495,6 +515,7 @@ function CatalogueItemsLandingPage() {
)}
</Grid>
),
order: 0,
},
{
value: 'Notes',
Expand All @@ -513,6 +534,7 @@ function CatalogueItemsLandingPage() {
{catalogueItemIdData.notes ?? 'None'}
</Typography>
),
order: 3,
},
]}
/>
Expand Down Expand Up @@ -543,14 +565,6 @@ function CatalogueItemsLandingPage() {
<LinearProgress />
</Box>
)}

<CatalogueItemsDialog
open={editItemDialogOpen}
onClose={() => setEditItemDialogOpen(false)}
parentInfo={catalogueCategoryData}
selectedCatalogueItem={catalogueItemIdData}
requestType="patch"
/>
</Grid>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/actionMenu.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
export interface ActionMenuProps {
ariaLabelPrefix: string;
editMenuItem: { onClick: () => void; dialog: React.ReactNode };
printMenuItem: boolean;
printMenuItem?: boolean;
}
function ActionMenu(props: ActionMenuProps) {
const { editMenuItem, printMenuItem, ariaLabelPrefix } = props;
Expand Down
82 changes: 73 additions & 9 deletions src/common/tab/__snapshots__/tabView.component.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ exports[`TabView Component > renders correctly 1`] = `
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
<button
aria-controls="tab3-tabpanel"
aria-selected="false"
class="MuiButtonBase-root MuiTab-root MuiTab-labelIcon MuiTab-textColorPrimary css-12xzlyc-MuiButtonBase-root-MuiTab-root"
id="tab3-tab"
role="tab"
tabindex="-1"
type="button"
>
<div
class="MuiTab-iconWrapper"
>
icon 3
</div>
tab3
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
<button
aria-controls="tab2-tabpanel"
aria-selected="false"
Expand All @@ -60,20 +79,51 @@ exports[`TabView Component > renders correctly 1`] = `
/>
</button>
<button
aria-controls="tab3-tabpanel"
aria-controls="Gallery-tabpanel"
aria-selected="false"
class="MuiButtonBase-root MuiTab-root MuiTab-labelIcon MuiTab-textColorPrimary css-12xzlyc-MuiButtonBase-root-MuiTab-root"
id="tab3-tab"
id="Gallery-tab"
role="tab"
tabindex="-1"
type="button"
>
<div
class="MuiTab-iconWrapper"
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTab-iconWrapper css-i4bv87-MuiSvgIcon-root"
data-testid="CollectionsOutlinedIcon"
focusable="false"
viewBox="0 0 24 24"
>
icon 3
</div>
tab3
<path
d="M20 4v12H8V4zm0-2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2m-8.5 9.67 1.69 2.26 2.48-3.1L19 15H9zM2 6v14c0 1.1.9 2 2 2h14v-2H4V6z"
/>
</svg>
Gallery
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
<button
aria-controls="Attachments-tabpanel"
aria-selected="false"
class="MuiButtonBase-root MuiTab-root MuiTab-labelIcon MuiTab-textColorPrimary css-12xzlyc-MuiButtonBase-root-MuiTab-root"
id="Attachments-tab"
role="tab"
tabindex="-1"
type="button"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium MuiTab-iconWrapper css-i4bv87-MuiSvgIcon-root"
data-testid="AttachmentOutlinedIcon"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M18.5 16H7c-2.21 0-4-1.79-4-4s1.79-4 4-4h12.5c1.38 0 2.5 1.12 2.5 2.5S20.88 13 19.5 13H9c-.55 0-1-.45-1-1s.45-1 1-1h9.5V9.5H9c-1.38 0-2.5 1.12-2.5 2.5s1.12 2.5 2.5 2.5h10.5c2.21 0 4-1.79 4-4s-1.79-4-4-4H7c-3.04 0-5.5 2.46-5.5 5.5s2.46 5.5 5.5 5.5h11.5z"
/>
</svg>
Attachments
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
Expand Down Expand Up @@ -103,6 +153,13 @@ exports[`TabView Component > renders correctly 1`] = `
</div>
</div>
</div>
<div
aria-labelledby="tab3-tab"
hidden=""
id="tab3-tabpanel"
role="tabpanel"
style="height: 100%;"
/>
<div
aria-labelledby="tab2-tab"
hidden=""
Expand All @@ -111,9 +168,16 @@ exports[`TabView Component > renders correctly 1`] = `
style="height: 100%;"
/>
<div
aria-labelledby="tab3-tab"
aria-labelledby="Gallery-tab"
hidden=""
id="tab3-tabpanel"
id="Gallery-tabpanel"
role="tabpanel"
style="height: 100%;"
/>
<div
aria-labelledby="Attachments-tab"
hidden=""
id="Attachments-tabpanel"
role="tabpanel"
style="height: 100%;"
/>
Expand Down
7 changes: 1 addition & 6 deletions src/common/tab/tabPanel.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@ export interface TabPanelProps<T> {
label: T | false;
}

export function TabPanel<T>({
children,
value,
label,
...other
}: TabPanelProps<T>) {
function TabPanel<T>({ children, value, label, ...other }: TabPanelProps<T>) {
return (
<div
role="tabpanel"
Expand Down
29 changes: 25 additions & 4 deletions src/common/tab/tabView.component.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { screen } from '@testing-library/react';

import userEvent from '@testing-library/user-event';
import { act } from 'react';
import { renderComponentWithRouterProvider } from '../../testUtils';
Expand All @@ -25,18 +24,25 @@ describe('TabView Component', () => {
value: 'tab1',
icon: <div>icon 1</div>,
component: <div>Content for Tab 1</div>,
order: 1,
},
{
value: 'tab2',
icon: <div>icon 2</div>,
component: <div>Content for Tab 2</div>,
order: 3,
},
{
value: 'tab3',
icon: <div>icon 3</div>,
component: <div>Content for Tab 3</div>,
order: 2,
},
],
galleryEntityId: '1',
galleryOrder: 4,
attachmentsEntityId: '1',
attachmentsOrder: 5,
};
});

Expand All @@ -47,9 +53,9 @@ describe('TabView Component', () => {
});
expect(baseElement).toMatchSnapshot();
});

it('renders correctly with default tab', () => {
createView('/catalogue/item/1');

expect(screen.getByText('Content for Tab 1')).toBeInTheDocument();
});

Expand All @@ -73,9 +79,24 @@ describe('TabView Component', () => {
expect(router.state.location.search).toBe('');
});

it('load tab from url', () => {
it('loads tab from URL', () => {
createView('/catalogue/item/1?tab=tab2');

expect(screen.getByText('Content for Tab 2')).toBeInTheDocument();
});

it('renders tabs in correct order', () => {
createView('/catalogue/item/1');

const tabs = screen.getAllByRole('tab');
const tabLabels = tabs.map((tab) => tab.textContent);

// Check that the tabs are ordered as expected
expect(tabLabels).toEqual([
'icon 1tab1',
'icon 3tab3',
'icon 2tab2',
'Gallery',
'Attachments',
]);
});
});
Loading