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

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

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
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,
Expand Down Expand Up @@ -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
Expand Up @@ -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');
});
Expand Down
8 changes: 7 additions & 1 deletion cypress/support/commands/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}`;
Expand All @@ -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();
}
},
);
Expand Down
6 changes: 4 additions & 2 deletions src/components/item/form/document/DocumentCreateForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export function DocumentCreateForm({
defaultValues: { flavor: DocumentItemExtraFlavor.None },
});
const {
reset,
handleSubmit,
setValue,
formState: { isValid, isSubmitted },
} = methods;

Expand Down Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion src/components/item/form/link/LinkForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/item/move/MoveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type MoveButtonProps = {
};

const MoveButton = ({
color = 'primary',
color,
id,
type = ActionButton.ICON_BUTTON,
onClick,
Expand Down
4 changes: 1 addition & 3 deletions src/components/item/sharing/ItemSharingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
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';
Expand Down Expand Up @@ -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>
)}
</>
);
Expand Down
1 change: 1 addition & 0 deletions src/components/main/ItemMenuContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const ItemMenuContent = ({ item }: Props): JSX.Element | null => {
canAdmin ? (
<MoveButton
key="move"
color="inherit"
type={ActionButton.MENU_ITEM}
onClick={() => {
openMoveModal();
Expand Down
Loading