Skip to content
This repository has been archived by the owner on Jan 23, 2025. It is now read-only.

fix: normalize url on create, fix document flavor #1597

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Changes from 2 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
24 changes: 24 additions & 0 deletions cypress/e2e/item/create/createDocument.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
DocumentItemExtraFlavor,
DocumentItemFactory,
ItemType,
PackedFolderItemFactory,
@@ -93,4 +94,27 @@ describe('Create Document', () => {
true,
);
});

it('create document with flavor', () => {
cy.setUpApi();
cy.visit(HOME_PATH);

const documentToCreate = DocumentItemFactory({
name: 'document',
extra: {
[ItemType.DOCUMENT]: {
content: '<h1>Some Title</h1>',
flavor: DocumentItemExtraFlavor.Error,
},
},
});
createDocument(documentToCreate);

cy.wait('@postItem').then(({ request: { body } }) => {
expect(body.extra.document.flavor).to.eq(
documentToCreate.extra.document.flavor,
);
expect(body.extra.document.content).to.contain('Some Title');
});
});
});
4 changes: 2 additions & 2 deletions cypress/e2e/item/create/createLink.cy.ts
Original file line number Diff line number Diff line change
@@ -49,10 +49,10 @@ describe('Create Link', () => {
createLink({ url: 'graasp.org' });
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click();

cy.wait('@postItem').then(() => {
cy.wait('@postItem').then(({ request: { body } }) => {
// check item is created and displayed
cy.wait(CREATE_ITEM_PAUSE);

expect(body.extra.url).to.contain('http');
// expect update
cy.wait('@getAccessibleItems');
});
8 changes: 7 additions & 1 deletion cypress/support/commands/item.ts
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { DiscriminatedItem, getAppExtra, getDocumentExtra } from '@graasp/sdk';
import {
CUSTOM_APP_CYPRESS_ID,
CUSTOM_APP_URL_ID,
FLAVOR_SELECT_ID,
FOLDER_FORM_DESCRIPTION_ID,
HOME_MODAL_ITEM_ID,
ITEM_FORM_APP_URL_ID,
@@ -121,6 +122,11 @@ Cypress.Commands.add(
({ name = '', extra }, { confirm = true } = {}) => {
cy.fillBaseItemModal({ name }, { confirm: false });

if (extra.document.flavor) {
cy.get(`#${FLAVOR_SELECT_ID} div`).click();
cy.get(`li[data-value="${extra.document.flavor}"]`).click();
}

const content =
// first select all the text and then remove it to have a clear field, then type new text
`{selectall}{backspace}${getDocumentExtra(extra)?.content}`;
@@ -133,7 +139,7 @@ Cypress.Commands.add(
}

if (confirm) {
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click();
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).scrollIntoView().click();
}
},
);
6 changes: 4 additions & 2 deletions src/components/item/form/document/DocumentCreateForm.tsx
Original file line number Diff line number Diff line change
@@ -55,8 +55,8 @@ export function DocumentCreateForm({
defaultValues: { flavor: DocumentItemExtraFlavor.None },
});
const {
reset,
handleSubmit,
setValue,
formState: { isValid, isSubmitted },
} = methods;

@@ -91,7 +91,9 @@ export function DocumentCreateForm({
<DocumentFlavorSelect />
<DocumentContentForm
documentItemId={ITEM_FORM_DOCUMENT_TEXT_ID}
onChange={(v) => reset({ content: v })}
onChange={(v) => {
setValue('content', v);
}}
placeholder={translateBuilder(BUILDER.TEXT_EDITOR_PLACEHOLDER)}
/>
</DialogContent>
2 changes: 1 addition & 1 deletion src/components/item/form/link/LinkForm.tsx
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ export const LinkForm = ({
type: ItemType.LINK,
description: data.description,
extra: buildLinkExtra({
url: data.url,
url: normalizeURL(data.url),
description: linkData?.description,
thumbnails: linkData?.thumbnails,
icons: linkData?.icons,
2 changes: 1 addition & 1 deletion src/components/item/move/MoveButton.tsx
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ type MoveButtonProps = {
};

const MoveButton = ({
color = 'primary',
color,
id,
type = ActionButton.ICON_BUTTON,
onClick,
4 changes: 1 addition & 3 deletions src/components/item/sharing/ItemSharingTab.tsx
Original file line number Diff line number Diff line change
@@ -61,9 +61,7 @@ const ItemSharingTab = (): JSX.Element => {
)}
</Alert>
) : (
<Stack direction="row" alignItems="center">
<VisibilitySelect item={item} edit={canAdmin} />
</Stack>
<VisibilitySelect item={item} edit={canAdmin} />
)}
<HideSettingCheckbox item={item} />
</Stack>
68 changes: 35 additions & 33 deletions src/components/item/sharing/VisibilitySelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MenuItem, Select, Typography } from '@mui/material';
import { Alert, MenuItem, Select, Stack } from '@mui/material';

import { PackedItem } from '@graasp/sdk';
import { Loader } from '@graasp/ui';
@@ -75,42 +75,44 @@ const VisibilitySelect = ({ item, edit }: Props): JSX.Element | null => {

return (
<>
{isModalOpen && (
<UpdateVisibilityModal
isOpen={isModalOpen}
newVisibility={pendingVisibility}
onClose={onCloseModal}
onValidate={onValidateModal}
/>
)}
{edit && (
<Select
value={visibility}
onChange={(e) => onVisibilityChange(e.target.value)}
disabled={isDisabled}
id={SHARE_ITEM_VISIBILITY_SELECT_ID}
sx={{ mr: 1 }}
>
<MenuItem value={SETTINGS.ITEM_PRIVATE.name}>
{translateBuilder(BUILDER.ITEM_SETTINGS_VISIBILITY_PRIVATE_LABEL)}
</MenuItem>
<MenuItem value={SETTINGS.ITEM_LOGIN.name}>
{translateBuilder(
BUILDER.ITEM_SETTINGS_VISIBILITY_PSEUDONYMIZED_LABEL,
)}
</MenuItem>
<MenuItem value={SETTINGS.ITEM_PUBLIC.name}>
{translateBuilder(BUILDER.ITEM_SETTINGS_VISIBILITY_PUBLIC_LABEL)}
</MenuItem>
</Select>
)}
{renderVisiblityIndication()}
<Stack direction="row" alignItems="center">
{isModalOpen && (
<UpdateVisibilityModal
isOpen={isModalOpen}
newVisibility={pendingVisibility}
onClose={onCloseModal}
onValidate={onValidateModal}
/>
)}
{edit && (
<Select
value={visibility}
onChange={(e) => onVisibilityChange(e.target.value)}
disabled={isDisabled}
id={SHARE_ITEM_VISIBILITY_SELECT_ID}
sx={{ mr: 1 }}
>
<MenuItem value={SETTINGS.ITEM_PRIVATE.name}>
{translateBuilder(BUILDER.ITEM_SETTINGS_VISIBILITY_PRIVATE_LABEL)}
</MenuItem>
<MenuItem value={SETTINGS.ITEM_LOGIN.name}>
{translateBuilder(
BUILDER.ITEM_SETTINGS_VISIBILITY_PSEUDONYMIZED_LABEL,
)}
</MenuItem>
<MenuItem value={SETTINGS.ITEM_PUBLIC.name}>
{translateBuilder(BUILDER.ITEM_SETTINGS_VISIBILITY_PUBLIC_LABEL)}
</MenuItem>
</Select>
)}
{renderVisiblityIndication()}
</Stack>
{isDisabled && (
<Typography variant="body2">
<Alert severity="info">
{translateBuilder(
BUILDER.ITEM_SETTINGS_VISIBILITY_CANNOT_EDIT_PARENT_MESSAGE,
)}
</Typography>
</Alert>
)}
</>
);
1 change: 1 addition & 0 deletions src/components/main/ItemMenuContent.tsx
Original file line number Diff line number Diff line change
@@ -114,6 +114,7 @@ const ItemMenuContent = ({ item }: Props): JSX.Element | null => {
canAdmin ? (
<MoveButton
key="move"
color="inherit"
type={ActionButton.MENU_ITEM}
onClick={() => {
openMoveModal();