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

build: move menu items tree #910

Merged
merged 28 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1b990ec
build: move menu items tree
LinaYahya Dec 6, 2023
c74dc30
fix: moveItem command for testing
LinaYahya Dec 7, 2023
85ca701
feat: disable move menu item if it's a child of element
LinaYahya Dec 7, 2023
3576d93
fix: restore fillTreeInMenu cypress command
LinaYahya Dec 8, 2023
138e750
fix: restore fillTreeInMenu cypress command
LinaYahya Dec 8, 2023
e4f7bef
feat: add default parent as a start for nested folder selection
LinaYahya Dec 8, 2023
273a699
feat: remove move modal context
LinaYahya Dec 12, 2023
5d368e1
feat: get shared items within home tree modal
LinaYahya Dec 12, 2023
28e5d7b
fix: return null row if item is not a folder
LinaYahya Dec 14, 2023
ed723ac
fix: select folder for default at move modal
LinaYahya Dec 15, 2023
ace0108
build: add root path for breadcrumbs
LinaYahya Dec 18, 2023
75eee94
fix: move modal breadcrumb navigation
LinaYahya Dec 21, 2023
7a6e09d
build: rename myItemrootID to home modal item ID
LinaYahya Dec 21, 2023
ae6eddf
fix: remove rootmodal to new folder
LinaYahya Dec 21, 2023
b721736
fix: style and add item name within modal title
LinaYahya Dec 26, 2023
5ce841a
fix: refactor translations
LinaYahya Dec 26, 2023
51a29bc
Merge branch 'main' of https://github.com/graasp/graasp-builder into …
LinaYahya Dec 26, 2023
3031cf2
fix: use optional chaining as parent might be undefined
LinaYahya Dec 26, 2023
b99bbbd
refactor: move useItem to modal itself
LinaYahya Dec 26, 2023
622174f
feat: align home icon with folders options
LinaYahya Jan 9, 2024
8038365
feat(ui): msg color, remove icon on root
LinaYahya Jan 10, 2024
cf91fc0
feat(ui): use home icon for home
LinaYahya Jan 10, 2024
0abd7bc
fix: fix reset itemids on cancel move modal
LinaYahya Jan 11, 2024
fb30564
Merge branch 'main' of https://github.com/graasp/graasp-builder into …
LinaYahya Jan 11, 2024
25cf6e3
feat(ui): remove text folder name trimming
LinaYahya Jan 11, 2024
d9de738
fix: style issues
LinaYahya Jan 12, 2024
2e368f7
fix: trim title on english
LinaYahya Jan 12, 2024
87ffcdb
Merge branch 'main' into 857-move-modal
pyphilia Jan 12, 2024
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
2 changes: 1 addition & 1 deletion cypress/e2e/item/move/gridMoveItem.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const moveItem = ({
`#${buildItemMenu(movedItemId)} .${ITEM_MENU_MOVE_BUTTON_CLASS}`,
).click();

cy.fillTreeModal(toItemPath);
cy.handleTreeMenu(toItemPath);
};

describe('Move Item in Grid', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/item/move/listMoveItem.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const moveItem = ({
`#${buildItemMenu(movedItemId)} .${ITEM_MENU_MOVE_BUTTON_CLASS}`,
).click();

cy.fillTreeModal(toItemPath, rootId);
cy.handleTreeMenu(toItemPath, rootId);
};

describe('Move Item in List', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/item/move/listMoveMultiple.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const moveItems = ({

cy.wait(TABLE_ITEM_RENDER_TIME);
cy.get(`#${ITEMS_TABLE_MOVE_SELECTED_ITEMS_ID}`).click();
cy.fillTreeModal(toItemPath);
cy.handleTreeMenu(toItemPath);
};

describe('Move Items in List', () => {
Expand Down
5 changes: 5 additions & 0 deletions cypress/fixtures/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ const sampleItems: DiscriminatedItem[] = [
settings: {
hasThumbnail: false,
},
extra: {
[ItemType.FOLDER]: {
childrenOrder: ['fdf09f5a-5688-11eb-ae93-0242ac130004'],
},
},
},
{
...DEFAULT_FOLDER_ITEM,
Expand Down
37 changes: 36 additions & 1 deletion cypress/support/commands/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
TREE_MODAL_CONFIRM_BUTTON_ID,
TREE_MODAL_MY_ITEMS_ID,
buildItemFormAppOptionId,
buildItemRowArrowId,
buildPermissionOptionId,
buildTreeItemId,
} from '../../../src/config/selectors';
Expand Down Expand Up @@ -44,6 +45,41 @@ Cypress.Commands.add(
},
);

Cypress.Commands.add(
'handleTreeMenu',
(toItemPath, treeRootId = TREE_MODAL_MY_ITEMS_ID) => {
const ids = getParentsIdsFromPath(toItemPath);

cy.wait(TREE_VIEW_PAUSE);

[TREE_MODAL_MY_ITEMS_ID, ...ids].forEach((value, idx, array) => {
cy.get(`#${treeRootId}`).then(($tree) => {
// click on the element
if (idx === array.length - 1) {
cy.wrap($tree)
.get(`#${buildTreeItemId(value, treeRootId)}`)
.first()
.click();
}
// if can't find children click on parent (current value)
if (
idx !== array.length - 1 &&
!$tree.find(`#${buildTreeItemId(array[idx + 1], treeRootId)}`).length
) {
cy.wrap($tree)
.get(`#${buildTreeItemId(value, treeRootId)}`)
.trigger('mouseover')
.get(`#${buildItemRowArrowId(value)}`)
.first()
.click();
}
});
});

cy.get(`#${TREE_MODAL_CONFIRM_BUTTON_ID}`).click();
},
);

Cypress.Commands.add(
'fillTreeModal',
(toItemPath, treeRootId = TREE_MODAL_MY_ITEMS_ID) => {
Expand Down Expand Up @@ -83,7 +119,6 @@ Cypress.Commands.add(
cy.get(`#${TREE_MODAL_CONFIRM_BUTTON_ID}`).click();
},
);

Cypress.Commands.add(
'fillBaseItemModal',
({ name = '' }, { confirm = true } = {}) => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ declare global {
): void;

fillTreeModal(path: string, rootId?: string): void;

handleTreeMenu(path: string, rootId?: string): void;
switchMode(mode: string): void;
goToItemInGrid(path: string): void;
goToItemInList(path: string): void;
Expand Down
87 changes: 67 additions & 20 deletions src/components/common/MoveButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from 'react';
import { useEffect, useState } from 'react';

import { IconButtonProps } from '@mui/material/IconButton';

Expand All @@ -8,13 +8,18 @@ import {
MoveButton as GraaspMoveButton,
} from '@graasp/ui';

import { validate } from 'uuid';

import { mutations } from '@/config/queryClient';

import { useBuilderTranslation } from '../../config/i18n';
import {
ITEM_MENU_MOVE_BUTTON_CLASS,
ITEM_MOVE_BUTTON_CLASS,
TREE_MODAL_MY_ITEMS_ID,
} from '../../config/selectors';
import { BUILDER } from '../../langs/constants';
import { MoveItemModalContext } from '../context/MoveItemModalContext';
import TreeModal, { TreeModalProps } from '../main/MoveTreeModal';

type MoveButtonProps = {
itemIds: string[];
Expand All @@ -25,36 +30,78 @@ type MoveButtonProps = {
};

const MoveButton = ({
itemIds,
itemIds: defaultItemsIds,
color = 'default',
id,
type = ActionButton.ICON_BUTTON,
onClick,
}: MoveButtonProps): JSX.Element | null => {
}: MoveButtonProps): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const { mutate: moveItems } = mutations.useMoveItems();

const { openModal: openMoveModal } = useContext(MoveItemModalContext);
const [open, setOpen] = useState(false);
const [itemIds, setItemIds] = useState<string[] | null>(
defaultItemsIds || null,
);
LinaYahya marked this conversation as resolved.
Show resolved Hide resolved

// TODO: return error?
if (!openMoveModal) {
return null;
}
const openMoveModal = (newItemIds: string[]) => {
setOpen(true);
setItemIds(newItemIds);
};

const onClose = () => {
setOpen(false);
setItemIds(null);
};

const onConfirm: TreeModalProps['onConfirm'] = (payload) => {
// change item's root id to null
const newPayload = {
...payload,
to:
payload.to &&
payload.to !== TREE_MODAL_MY_ITEMS_ID &&
validate(payload.to)
? payload.to
: undefined,
};
moveItems(newPayload);
LinaYahya marked this conversation as resolved.
Show resolved Hide resolved
onClose();
};
useEffect(() => {
// sync itemIds with default one as there's no way to access setItemIds
setItemIds(defaultItemsIds);
LinaYahya marked this conversation as resolved.
Show resolved Hide resolved
}, [defaultItemsIds]);

const handleMove = () => {
openMoveModal(itemIds);
onClick?.();
if (itemIds) {
openMoveModal(itemIds);
onClick?.();
}
};
LinaYahya marked this conversation as resolved.
Show resolved Hide resolved

return (
<GraaspMoveButton
color={color}
type={type}
id={id}
onClick={handleMove}
text={translateBuilder(BUILDER.MOVE_BUTTON)}
menuItemClassName={ITEM_MENU_MOVE_BUTTON_CLASS}
iconClassName={ITEM_MOVE_BUTTON_CLASS}
/>
<>
<GraaspMoveButton
color={color}
type={type}
id={id}
onClick={handleMove}
text={translateBuilder(BUILDER.MOVE_BUTTON)}
menuItemClassName={ITEM_MENU_MOVE_BUTTON_CLASS}
iconClassName={ITEM_MOVE_BUTTON_CLASS}
/>

{itemIds && (
<TreeModal
onClose={onClose}
open={open}
itemIds={itemIds}
onConfirm={onConfirm}
title={translateBuilder(BUILDER.MOVE_ITEM_MODAL_TITLE)}
/>
)}
</>
);
};

Expand Down
9 changes: 3 additions & 6 deletions src/components/context/ModalProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@ import { CopyItemModalProvider } from './CopyItemModalContext';
import { CreateShortcutModalProvider } from './CreateShortcutModalContext';
import { FlagItemModalProvider } from './FlagItemModalContext';
import { LayoutContextProvider } from './LayoutContext';
import { MoveItemModalProvider } from './MoveItemModalContext';

type Props = { children: JSX.Element };

const ModalProviders = ({ children }: Props): JSX.Element => (
<LayoutContextProvider>
<CopyItemModalProvider>
<MoveItemModalProvider>
<CreateShortcutModalProvider>
<FlagItemModalProvider>{children}</FlagItemModalProvider>
</CreateShortcutModalProvider>
</MoveItemModalProvider>
<CreateShortcutModalProvider>
<FlagItemModalProvider>{children}</FlagItemModalProvider>
</CreateShortcutModalProvider>
</CopyItemModalProvider>
</LayoutContextProvider>
);
Expand Down
76 changes: 0 additions & 76 deletions src/components/context/MoveItemModalContext.tsx

This file was deleted.

54 changes: 25 additions & 29 deletions src/components/main/ItemMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,32 @@ const ItemMenu = ({
>
<MoreVertIcon />
</IconButton>
{Boolean(anchorEl) && (
<Menu
id={buildItemMenu(item.id)}
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}

<Menu
id={buildItemMenu(item.id)}
anchorEl={anchorEl}
keepMounted
open={Boolean(anchorEl)}
onClose={handleClose}
>
{renderAuthenticatedActions()}
{renderEditorActions()}
<MenuItem
onClick={handleCreateShortcut}
className={ITEM_MENU_SHORTCUT_BUTTON_CLASS}
>
{renderAuthenticatedActions()}
{renderEditorActions()}
<MenuItem
onClick={handleCreateShortcut}
className={ITEM_MENU_SHORTCUT_BUTTON_CLASS}
>
<ListItemIcon>
<LabelImportantIcon />
</ListItemIcon>
{translateBuilder(BUILDER.ITEM_MENU_CREATE_SHORTCUT_MENU_ITEM)}
</MenuItem>
<MenuItem
onClick={handleFlag}
className={ITEM_MENU_FLAG_BUTTON_CLASS}
>
<ListItemIcon>
<FlagIcon />
</ListItemIcon>
{translateBuilder(BUILDER.ITEM_MENU_FLAG_MENU_ITEM)}
</MenuItem>
</Menu>
)}
<ListItemIcon>
<LabelImportantIcon />
</ListItemIcon>
{translateBuilder(BUILDER.ITEM_MENU_CREATE_SHORTCUT_MENU_ITEM)}
</MenuItem>
<MenuItem onClick={handleFlag} className={ITEM_MENU_FLAG_BUTTON_CLASS}>
<ListItemIcon>
<FlagIcon />
</ListItemIcon>
{translateBuilder(BUILDER.ITEM_MENU_FLAG_MENU_ITEM)}
</MenuItem>
</Menu>
</>
);
};
Expand Down
Loading