diff --git a/cypress/e2e/item/share/shareItem.cy.ts b/cypress/e2e/item/share/shareItem.cy.ts index b5306ea60..4a9dfef32 100644 --- a/cypress/e2e/item/share/shareItem.cy.ts +++ b/cypress/e2e/item/share/shareItem.cy.ts @@ -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, @@ -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', diff --git a/package.json b/package.json index 2b92dcc32..89c450f14 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/item/publish/publicationButtons/PublishedButton.tsx b/src/components/item/publish/publicationButtons/PublishedButton.tsx index 6d24d6c55..66dda7802 100644 --- a/src/components/item/publish/publicationButtons/PublishedButton.tsx +++ b/src/components/item/publish/publicationButtons/PublishedButton.tsx @@ -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'; @@ -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 = ( diff --git a/src/components/item/sharing/shortLink/PlatformIcon.tsx b/src/components/item/sharing/shortLink/PlatformIcon.tsx index 0b43d1ad1..926643755 100644 --- a/src/components/item/sharing/shortLink/PlatformIcon.tsx +++ b/src/components/item/sharing/shortLink/PlatformIcon.tsx @@ -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; }; diff --git a/src/components/item/sharing/shortLink/PlatformSelect.tsx b/src/components/item/sharing/shortLink/PlatformSelect.tsx index a1d798dee..9bc8b0943 100644 --- a/src/components/item/sharing/shortLink/PlatformSelect.tsx +++ b/src/components/item/sharing/shortLink/PlatformSelect.tsx @@ -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; diff --git a/src/components/item/sharing/shortLink/ShortLinkDialogContent.tsx b/src/components/item/sharing/shortLink/ShortLinkDialogContent.tsx index 291a28c17..97fe9872c 100644 --- a/src/components/item/sharing/shortLink/ShortLinkDialogContent.tsx +++ b/src/components/item/sharing/shortLink/ShortLinkDialogContent.tsx @@ -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'; @@ -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'; @@ -29,7 +30,7 @@ const { useShortLinkAvailable } = hooks; type Props = { itemId: string; initialAlias: string; - initialPlatform: ShortLinkPlatform; + initialPlatform: ShortLink['platform']; isNew: boolean; handleClose: () => void; }; diff --git a/src/components/item/sharing/shortLink/ShortLink.tsx b/src/components/item/sharing/shortLink/ShortLinkDisplay.tsx similarity index 94% rename from src/components/item/sharing/shortLink/ShortLink.tsx rename to src/components/item/sharing/shortLink/ShortLinkDisplay.tsx index bdb24eb33..0cd219e16 100644 --- a/src/components/item/sharing/shortLink/ShortLink.tsx +++ b/src/components/item/sharing/shortLink/ShortLinkDisplay.tsx @@ -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 { @@ -16,7 +16,6 @@ import { buildShortLinkPlatformTextId, buildShortLinkUrlTextId, } from '@/config/selectors'; -import { ShortLinkPlatform } from '@/utils/shortLink'; import ConfirmDeleteLink from './ConfirmDeleteLink'; import PlatformIcon from './PlatformIcon'; @@ -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 }) => ({ @@ -54,7 +53,7 @@ const StyledText = styled('p')(({ color = 'auto' }) => ({ textTransform: 'capitalize', })); -const ShortLink = ({ +const ShortLinkDisplay = ({ url, shortLink, isShorten, @@ -139,4 +138,4 @@ const ShortLink = ({ ); }; -export default ShortLink; +export default ShortLinkDisplay; diff --git a/src/components/item/sharing/shortLink/ShortLinkMenu.tsx b/src/components/item/sharing/shortLink/ShortLinkMenu.tsx index d03a8cad2..a90ac1a77 100644 --- a/src/components/item/sharing/shortLink/ShortLinkMenu.tsx +++ b/src/components/item/sharing/shortLink/ShortLinkMenu.tsx @@ -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'; @@ -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; }; diff --git a/src/components/item/sharing/shortLink/ShortLinksRenderer.tsx b/src/components/item/sharing/shortLink/ShortLinksRenderer.tsx index 7dfe7d496..4c6fda232 100644 --- a/src/components/item/sharing/shortLink/ShortLinksRenderer.tsx +++ b/src/components/item/sharing/shortLink/ShortLinksRenderer.tsx @@ -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; @@ -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((platform) => { - if (!publishedEntry && platform === ShortLinkPlatformConst.library) { + if (!publishedEntry && platform === Context.Library) { return undefined; } const clientHostManager = ClientHostManager.getInstance(); @@ -131,7 +133,7 @@ const ShortLinksRenderer = ({ {shortLinks.map((shortLink) => ( - `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'; diff --git a/src/utils/shortLink.ts b/src/utils/shortLink.ts index 578c98728..5d50fcf08 100644 --- a/src/utils/shortLink.ts +++ b/src/utils/shortLink.ts @@ -1,5 +1,3 @@ -import { ShortLinkPlatform as ShortLinkPlatformConst } from '@graasp/sdk'; - import { BUILDER } from '@/langs/constants'; export const MIN_SHORT_LINK_LENGTH = 6; @@ -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]; diff --git a/yarn.lock b/yarn.lock index 5447f10be..7bc87d74b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -1779,7 +1779,7 @@ __metadata: peerDependencies: date-fns: ^3 uuid: ^9 || ^10.0.0 - checksum: 10/899b1003f605e944a00d306e7c0d1f9329e7d4cdf8f13ea2f731130ec16ab14e648ee2d884fbc1baa12ea167bd26f7e974b69031484cc243c615578cf69a74ea + checksum: 10/02bd822171627b980804d702ac772635ba7288e10da9f8e2cce47893b79c663c410c51e3152e527151449c20f902b08e518a0aac420e059b027e387fb0b6f9e4 languageName: node linkType: hard @@ -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"