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

feat(ui): create separate pages for item share, publish and settings #971

Merged
merged 5 commits into from
Feb 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
25 changes: 0 additions & 25 deletions cypress/e2e/item/publish/publishPage.cy.ts

This file was deleted.

17 changes: 0 additions & 17 deletions cypress/e2e/item/settings/settingsPage.cy.ts

This file was deleted.

20 changes: 19 additions & 1 deletion cypress/e2e/item/share/shareItem.cy.ts
pyphilia marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context, ShortLink, appendPathToUrl } from '@graasp/sdk';

import { buildItemPath } from '@/config/paths';
import { buildItemPath, buildItemSharePath } from '@/config/paths';
import { ShortLinkPlatform } from '@/utils/shortLink';

import {
Expand Down Expand Up @@ -196,4 +196,22 @@ describe('Share Item Link', () => {
cy.get(`#${SHARE_ITEM_QR_DIALOG_ID}`).should('exist');
});
});

describe('Without short links', () => {
const item = PUBLISHED_ITEM;

beforeEach(() => {
cy.setUpApi({ items: [item] });
});

it('Builder link is correctly displayed', () => {
cy.visit(buildItemSharePath(item.id));

cy.get(`.${SHORT_LINK_COMPONENT}`).should('have.length', 3);

const context = Context.Builder;
checkContainPlatformText(context);
checkContainUrlText(context, item.id);
});
});
});
27 changes: 0 additions & 27 deletions cypress/e2e/item/share/sharePage.cy.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/components/common/BackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ArrowCircleLeftRoundedIcon from '@mui/icons-material/ArrowCircleLeftRound
import { IconButton, Tooltip } from '@mui/material';

import { useBuilderTranslation } from '@/config/i18n';
import { BUILDER } from '@/langs/constants';

interface Props {
onClick: () => void;
Expand All @@ -10,7 +11,7 @@ const BackButton = ({ onClick }: Props): JSX.Element => {
const { t } = useBuilderTranslation();

return (
<Tooltip title={t('Go Back')}>
<Tooltip title={t(BUILDER.BACK)}>
<IconButton onClick={onClick}>
<ArrowCircleLeftRoundedIcon fontSize="large" />
</IconButton>
Expand Down
14 changes: 4 additions & 10 deletions src/components/common/ItemMetadataButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate } from 'react-router';
import { Link } from 'react-router-dom';

import InfoIcon from '@mui/icons-material/Info';
import { IconButton, Tooltip } from '@mui/material';
Expand All @@ -12,19 +12,13 @@ import { BUILDER } from '../../langs/constants';
const ItemMetadataButton = ({ itemId }: { itemId: string }): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();

const navigate = useNavigate();

const onClick = () => {
navigate(buildItemInformationPath(itemId));
};

return (
<Tooltip title={translateBuilder(BUILDER.ITEM_METADATA_TITLE)}>
<span>
<IconButton id={ITEM_INFORMATION_BUTTON_ID} onClick={onClick}>
<Link to={buildItemInformationPath(itemId)}>
<IconButton id={ITEM_INFORMATION_BUTTON_ID}>
<InfoIcon />
pyphilia marked this conversation as resolved.
Show resolved Hide resolved
</IconButton>
</span>
</Link>
</Tooltip>
);
};
Expand Down
12 changes: 3 additions & 9 deletions src/components/common/PublishButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate } from 'react-router';
import { Link } from 'react-router-dom';

import IconButton from '@mui/material/IconButton';
import Tooltip from '@mui/material/Tooltip';
Expand All @@ -20,26 +20,20 @@ type Props = {

const PublishButton = ({ itemId }: Props): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const navigate = useNavigate();

const onClick = () => {
navigate(buildItemPublishPath(itemId));
};

const title = translateBuilder(BUILDER.LIBRARY_SETTINGS_BUTTON_TITLE);

return (
<Tooltip title={title}>
<span>
<Link to={buildItemPublishPath(itemId)}>
<IconButton
aria-label={title}
className={PUBLISH_ITEM_BUTTON_CLASS}
onClick={onClick}
id={buildPublishButtonId(itemId)}
>
<LibraryIcon size={24} showSetting primaryColor="#777" />
</IconButton>
</span>
</Link>
</Tooltip>
);
};
Expand Down
22 changes: 9 additions & 13 deletions src/components/common/ShareButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate } from 'react-router';
import { Link } from 'react-router-dom';

import { ShareButton as GraaspShareButton } from '@graasp/ui';

Expand All @@ -17,20 +17,16 @@ type Props = {

const ShareButton = ({ itemId }: Props): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const navigate = useNavigate();

const onClick = () => {
navigate(buildItemSharePath(itemId));
};

return (
<GraaspShareButton
tooltip={translateBuilder(BUILDER.SHARE_ITEM_BUTTON)}
ariaLabel={translateBuilder(BUILDER.SHARE_ITEM_BUTTON)}
className={SHARE_ITEM_BUTTON_CLASS}
onClick={onClick}
id={buildShareButtonId(itemId)}
/>
<Link to={buildItemSharePath(itemId)}>
<GraaspShareButton
tooltip={translateBuilder(BUILDER.SHARE_ITEM_BUTTON)}
ariaLabel={translateBuilder(BUILDER.SHARE_ITEM_BUTTON)}
className={SHARE_ITEM_BUTTON_CLASS}
id={buildShareButtonId(itemId)}
/>
</Link>
);
};

Expand Down
2 changes: 0 additions & 2 deletions src/components/item/ItemMetadataContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from '../../config/selectors';
import { BUILDER } from '../../langs/constants';
import { OutletType } from '../pages/item/type';
import ItemMemberships from './ItemMemberships';
import ThumbnailSetting from './settings/ThumbnailSetting';

const { useMember } = hooks;
Expand Down Expand Up @@ -129,7 +128,6 @@ const ItemMetadataContent = (): JSX.Element => {
</TableBody>
</Table>
</TableContainer>
<ItemMemberships id={item.id} maxAvatar={5} />
</Container>
);
};
Expand Down
13 changes: 3 additions & 10 deletions src/components/item/settings/ItemSettingsButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useNavigate } from 'react-router';
import { Link } from 'react-router-dom';

import SettingsIcon from '@mui/icons-material/Settings';
import IconButton from '@mui/material/IconButton';
Expand All @@ -19,23 +19,16 @@ type Props = {

const ItemSettingsButton = ({ id }: Props): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const navigate = useNavigate();

const onClickSettings = () => {
navigate(buildItemSettingsPath(id));
};

return (
<Tooltip title={translateBuilder(BUILDER.SETTINGS_TITLE)}>
<span>
<Link to={buildItemSettingsPath(id)}>
<IconButton
onClick={onClickSettings}
className={ITEM_SETTINGS_BUTTON_CLASS}
id={buildSettingsButtonId(id)}
>
<SettingsIcon />
</IconButton>
</span>
</Link>
</Tooltip>
);
};
Expand Down
8 changes: 2 additions & 6 deletions src/components/layout/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ const Navigator = (): JSX.Element | null => {
const { data: item, isLoading: isItemLoading } = useItem(itemId);
const itemPath = item?.path;

const location = useLocation();

const itemSettingsLocation = location.pathname.split(
`${buildItemPath(itemId)}/`,
)?.[1];
const { pathname: location } = useLocation();

const { data: parents, isLoading: areParentsLoading } = useParents({
id: itemId,
Expand Down Expand Up @@ -114,7 +110,7 @@ const Navigator = (): JSX.Element | null => {

const extraItems = buildExtraItems({
translate: translateBuilder,
location: itemSettingsLocation,
location,
itemId,
});

Expand Down
24 changes: 13 additions & 11 deletions src/components/layout/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import SettingsIcon from '@mui/icons-material/Settings';
import { LibraryIcon } from '@graasp/ui';

import {
ITEM_INFORMATION_PATH,
ITEM_PUBLISH_PATH,
ITEM_SETTINGS_PATH,
ITEM_SHARE_PATH,
buildItemInformationPath,
buildItemPath,
buildItemPublishPath,
buildItemSettingsPath,
buildItemSharePath,
} from '@/config/paths';
import { BUILDER } from '@/langs/constants';

const ItemAction = {
SETTINGS: 'settings',
INFORMATION: 'information',
SHARE: 'share',
PUBLISH: 'publish',
};
export interface MenuItemType {
name: string;
path: string;
Expand All @@ -41,6 +40,9 @@ export const buildExtraItems = ({
if (!itemId) {
return [];
}

const page = buildItemPath(location);

// we don't switch to sub pages
// const menuItems = [
// {
Expand All @@ -61,8 +63,8 @@ export const buildExtraItems = ({
// },
// ];

switch (location) {
case ItemAction.SETTINGS:
switch (true) {
case page.includes(ITEM_SETTINGS_PATH):
return [
{
name: translate(BUILDER.SETTINGS_TITLE),
Expand All @@ -71,7 +73,7 @@ export const buildExtraItems = ({
menuItems: [],
},
];
case ItemAction.SHARE:
case page.includes(ITEM_SHARE_PATH):
return [
{
name: translate(BUILDER.SHARE_ITEM_BUTTON),
Expand All @@ -80,7 +82,7 @@ export const buildExtraItems = ({
menuItems: [],
},
];
case ItemAction.PUBLISH:
case page.includes(ITEM_PUBLISH_PATH):
return [
{
name: translate(BUILDER.LIBRARY_SETTINGS_PUBLISH_BUTTON),
Expand All @@ -89,7 +91,7 @@ export const buildExtraItems = ({
menuItems: [],
},
];
case ItemAction.INFORMATION:
case page.includes(ITEM_INFORMATION_PATH):
return [
{
name: translate(BUILDER.ITEM_ACTION_INFORMATION),
Expand Down
Loading
Loading