Skip to content

Commit

Permalink
fix: shortlinks (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh authored Jun 27, 2024
1 parent 153f503 commit 241ee02
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 45 deletions.
3 changes: 2 additions & 1 deletion cypress/e2e/item/share/shareItem.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Context, ShortLink, appendPathToUrl } from '@graasp/sdk';

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

import {
SHARE_ITEM_QR_BTN_ID,
Expand All @@ -19,6 +18,8 @@ import {
buildGraaspPlayerView,
} from '../../../support/paths';

type ShortLinkPlatform = ShortLink['platform'];

export const checkContainPlatformText = (platform: ShortLinkPlatform): void => {
cy.get(`#${buildShortLinkPlatformTextId(platform)}`).should(
'contain',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@graasp/chatbox": "3.1.0",
"@graasp/map": "1.15.0",
"@graasp/query-client": "3.14.0",
"@graasp/sdk": "4.14.0",
"@graasp/sdk": "4.15.0",
"@graasp/translations": "1.28.0",
"@graasp/ui": "4.20.0",
"@mui/icons-material": "5.15.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import LinkIcon from '@mui/icons-material/Link';
import { LoadingButton } from '@mui/lab';
import { Alert, Button } from '@mui/material';

import { ClientHostManager, PackedItem, ShortLinkPlatform } from '@graasp/sdk';
import { ClientHostManager, Context, PackedItem } from '@graasp/sdk';

import { useBuilderTranslation } from '@/config/i18n';
import { mutations } from '@/config/queryClient';
Expand All @@ -29,7 +29,7 @@ export const PublishedButton = ({ item, isLoading }: Props): JSX.Element => {

const getLibraryLink = () => {
const clientHostManager = ClientHostManager.getInstance();
return clientHostManager.getItemLink(ShortLinkPlatform.library, itemId);
return clientHostManager.getItemLink(Context.Library, itemId);
};

const description = (
Expand Down
6 changes: 2 additions & 4 deletions src/components/item/sharing/shortLink/PlatformIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { Context } from '@graasp/sdk';
import { Context, ShortLink } from '@graasp/sdk';
import { BuildIcon, GraaspLogo, LibraryIcon, PlayIcon } from '@graasp/ui';

import { ShortLinkPlatform } from '@/utils/shortLink';

const DEFAULT_ICON_SIZE = 25;

type Props = {
platform: ShortLinkPlatform;
platform: ShortLink['platform'];
accentColor: string;
size?: number;
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/item/sharing/shortLink/PlatformSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { MenuItem, Select, SelectChangeEvent } from '@mui/material';

import { Context, ItemPublished } from '@graasp/sdk';
import { Context, ItemPublished, ShortLink } from '@graasp/sdk';

import { useEnumsTranslation } from '@/config/i18n';
import { SHORT_LINK_PLATFORM_SELECT_ID } from '@/config/selectors';
import { ShortLinkPlatform } from '@/utils/shortLink';

type ShortLinkPlatform = ShortLink['platform'];
type Props = {
platform: ShortLinkPlatform;
publishedEntry?: ItemPublished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
Stack,
} from '@mui/material';

import { ShortLink } from '@graasp/sdk';

import CancelButton from '@/components/common/CancelButton';
import { SHORT_LINK_API_CALL_DEBOUNCE_MS } from '@/config/constants';
import { useBuilderTranslation } from '@/config/i18n';
Expand All @@ -17,7 +19,6 @@ import {
buildShortLinkCancelBtnId,
} from '@/config/selectors';
import { BUILDER } from '@/langs/constants';
import { ShortLinkPlatform } from '@/utils/shortLink';
import { useDebouncedCallback } from '@/utils/useDebounce';

import AliasInput from './AliasInput';
Expand All @@ -29,7 +30,7 @@ const { useShortLinkAvailable } = hooks;
type Props = {
itemId: string;
initialAlias: string;
initialPlatform: ShortLinkPlatform;
initialPlatform: ShortLink['platform'];
isNew: boolean;
handleClose: () => void;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from 'react';

import { Link, Stack, styled } from '@mui/material';

import { ShortLinkPayload } from '@graasp/sdk';
import { ShortLink, ShortLinkPayload } from '@graasp/sdk';
import { AccentColors } from '@graasp/ui';

import {
Expand All @@ -16,7 +16,6 @@ import {
buildShortLinkPlatformTextId,
buildShortLinkUrlTextId,
} from '@/config/selectors';
import { ShortLinkPlatform } from '@/utils/shortLink';

import ConfirmDeleteLink from './ConfirmDeleteLink';
import PlatformIcon from './PlatformIcon';
Expand All @@ -30,7 +29,7 @@ type Props = {
isShorten: boolean;
canAdminShortLink: boolean;
onUpdate: () => void;
onCreate: (platform: ShortLinkPlatform) => void;
onCreate: (platform: ShortLink['platform']) => void;
};

const StyledBox = styled(Stack)(({ theme }) => ({
Expand All @@ -54,7 +53,7 @@ const StyledText = styled('p')(({ color = 'auto' }) => ({
textTransform: 'capitalize',
}));

const ShortLink = ({
const ShortLinkDisplay = ({
url,
shortLink,
isShorten,
Expand Down Expand Up @@ -139,4 +138,4 @@ const ShortLink = ({
);
};

export default ShortLink;
export default ShortLinkDisplay;
5 changes: 2 additions & 3 deletions src/components/item/sharing/shortLink/ShortLinkMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
Tooltip,
} from '@mui/material';

import { ShortLinkPayload } from '@graasp/sdk';
import { ShortLink, ShortLinkPayload } from '@graasp/sdk';
import { FAILURE_MESSAGES, SUCCESS_MESSAGES } from '@graasp/translations';

import QRCode from '@/components/common/QRCode';
Expand All @@ -30,14 +30,13 @@ import {
import { BUILDER } from '@/langs/constants';
import { COPY_ITEM_LINK_TO_CLIPBOARD } from '@/types/clipboard';
import { copyToClipboard } from '@/utils/clipboard';
import { ShortLinkPlatform } from '@/utils/shortLink';

type Props = {
shortLink: ShortLinkPayload;
url: string;
isShorten: boolean;
canAdminShortLink: boolean;
onCreate: (platform: ShortLinkPlatform) => void;
onCreate: (platform: ShortLink['platform']) => void;
onUpdate: () => void;
onDelete: () => void;
};
Expand Down
18 changes: 10 additions & 8 deletions src/components/item/sharing/shortLink/ShortLinksRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@ import { Box, Dialog, Stack } from '@mui/material';
import {
ClientHostManager,
Context,
ShortLinkPlatform as ShortLinkPlatformConst,
ShortLink,
appendPathToUrl,
} from '@graasp/sdk';

import { useLayoutContext } from '@/components/context/LayoutContext';
import { GRAASP_REDIRECTION_HOST } from '@/config/env';
import { hooks } from '@/config/queryClient';
import { ShortLinkPlatform, randomAlias } from '@/utils/shortLink';
import { randomAlias } from '@/utils/shortLink';

import ShortLink from './ShortLink';
import ShortLinkDialogContent from './ShortLinkDialogContent';
import ShortLinkDisplay from './ShortLinkDisplay';
import ShortLinkSkeleton from './ShortLinkSkeleton';

const { useShortLinksItem, useItemPublishedInformation } = hooks;

type ShortLinkPlatform = ShortLink['platform'];

type Props = {
itemId: string;
canAdminShortLink: boolean;
Expand Down Expand Up @@ -48,14 +50,14 @@ const ShortLinksRenderer = ({

// List of available platforms, the order matters
const platforms = [
ShortLinkPlatformConst.builder,
ShortLinkPlatformConst.player,
ShortLinkPlatformConst.library,
Context.Builder as const,
Context.Player as const,
Context.Library as const,
];

const shortLinks: ShortLinkType[] = platforms
.map<ShortLinkType | undefined>((platform) => {
if (!publishedEntry && platform === ShortLinkPlatformConst.library) {
if (!publishedEntry && platform === Context.Library) {
return undefined;
}
const clientHostManager = ClientHostManager.getInstance();
Expand Down Expand Up @@ -131,7 +133,7 @@ const ShortLinksRenderer = ({
<Stack alignItems="center" justifyContent="center">
<Box width={{ xs: '100%', sm: '80%' }}>
{shortLinks.map((shortLink) => (
<ShortLink
<ShortLinkDisplay
key={shortLink.platform}
url={`${shortLink.url}`}
shortLink={{
Expand Down
10 changes: 4 additions & 6 deletions src/config/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { DescriptionPlacementType } from '@graasp/sdk';

import { PublicationStatus } from '@/types/publication';
import { ShortLinkPlatform } from '@/utils/shortLink';

export const SHARED_ITEMS_ROOT_CONTAINER = 'sharedItemsPageRootContainer';
export const RECYCLED_ITEMS_ROOT_CONTAINER = 'recycledItemsPageRootContainer';
Expand Down Expand Up @@ -365,12 +364,11 @@ export const buildShortLinkEditBtnId = (alias: string): string =>
`shortLinkEditBtn-${alias}`;
export const buildShortLinkShortenBtnId = (
itemId: string,
platform: ShortLinkPlatform,
platform: string,
): string => `${SHORT_LINK_SHORTEN_START_ID}-${platform}-${itemId}`;
export const buildShortLinkPlatformTextId = (
platform: ShortLinkPlatform,
): string => `shortLinkPlatformText-${platform}`;
export const buildShortLinkUrlTextId = (platform: ShortLinkPlatform): string =>
export const buildShortLinkPlatformTextId = (platform: string): string =>
`shortLinkPlatformText-${platform}`;
export const buildShortLinkUrlTextId = (platform: string): string =>
`shortLinkUrlText-${platform}`;
export const ACCESSIBLE_ITEMS_ONLY_ME_ID = 'accessibleItemsOnlyMe';
export const ACCESSIBLE_ITEMS_TABLE_ID = 'accessibleItemsTable';
Expand Down
6 changes: 0 additions & 6 deletions src/utils/shortLink.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ShortLinkPlatform as ShortLinkPlatformConst } from '@graasp/sdk';

import { BUILDER } from '@/langs/constants';

export const MIN_SHORT_LINK_LENGTH = 6;
Expand Down Expand Up @@ -82,7 +80,3 @@ export function isValidAlias(alias: string): InvalidAliasCause {
isValid: true,
};
}

export type ShortLinkPlatform = keyof typeof ShortLinkPlatformConst;
export type ShortLinkPlatformType =
(typeof ShortLinkPlatformConst)[keyof typeof ShortLinkPlatformConst];
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1768,9 +1768,9 @@ __metadata:
languageName: node
linkType: hard

"@graasp/sdk@npm:4.14.0":
version: 4.14.0
resolution: "@graasp/sdk@npm:4.14.0"
"@graasp/sdk@npm:4.15.0":
version: 4.15.0
resolution: "@graasp/sdk@npm:4.15.0"
dependencies:
"@faker-js/faker": "npm:8.4.1"
filesize: "npm:10.1.2"
Expand All @@ -1779,7 +1779,7 @@ __metadata:
peerDependencies:
date-fns: ^3
uuid: ^9 || ^10.0.0
checksum: 10/899b1003f605e944a00d306e7c0d1f9329e7d4cdf8f13ea2f731130ec16ab14e648ee2d884fbc1baa12ea167bd26f7e974b69031484cc243c615578cf69a74ea
checksum: 10/02bd822171627b980804d702ac772635ba7288e10da9f8e2cce47893b79c663c410c51e3152e527151449c20f902b08e518a0aac420e059b027e387fb0b6f9e4
languageName: node
linkType: hard

Expand Down Expand Up @@ -7804,7 +7804,7 @@ __metadata:
"@graasp/chatbox": "npm:3.1.0"
"@graasp/map": "npm:1.15.0"
"@graasp/query-client": "npm:3.14.0"
"@graasp/sdk": "npm:4.14.0"
"@graasp/sdk": "npm:4.15.0"
"@graasp/translations": "npm:1.28.0"
"@graasp/ui": "npm:4.20.0"
"@mui/icons-material": "npm:5.15.19"
Expand Down

0 comments on commit 241ee02

Please sign in to comment.