Skip to content

Commit

Permalink
refactor: apply PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Jul 24, 2024
1 parent 59ecff0 commit e7fdcbe
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 52 deletions.
3 changes: 2 additions & 1 deletion cypress/e2e/item/copy/copy.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {

import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import {
COPY_MANY_ITEMS_BUTTON_SELECTOR,
ITEM_MENU_COPY_BUTTON_CLASS,
MY_GRAASP_ITEM_PATH,
buildItemCard,
Expand All @@ -18,7 +19,7 @@ const copyItems = ({
toItemPath: string;
rootId?: string;
}) => {
cy.get(`[data-testid="FilterNoneIcon"]`).click();
cy.get(COPY_MANY_ITEMS_BUTTON_SELECTOR).click();
cy.handleTreeMenu(toItemPath, rootId);
};

Expand Down
3 changes: 2 additions & 1 deletion cypress/e2e/item/move/move.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import {
ITEM_MENU_MOVE_BUTTON_CLASS,
MOVE_MANY_ITEMS_BUTTON_SELECTOR,
MY_GRAASP_ITEM_PATH,
buildItemsGridMoreButtonSelector,
buildNavigationModalItemId,
Expand All @@ -31,7 +32,7 @@ const moveItems = ({
toItemPath: string;
rootId?: string;
}) => {
cy.get(`[data-testid="OpenWithIcon"]`).click();
cy.get(MOVE_MANY_ITEMS_BUTTON_SELECTOR).click();
cy.handleTreeMenu(toItemPath, rootId);
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@graasp/query-client": "3.16.0",
"@graasp/sdk": "4.20.0",
"@graasp/translations": "1.32.0",
"@graasp/ui": "github:graasp/graasp-ui#card-selection",
"@graasp/ui": "4.22.0",
"@mui/icons-material": "5.16.4",
"@mui/lab": "5.0.0-alpha.172",
"@mui/material": "5.16.4",
Expand Down
9 changes: 5 additions & 4 deletions src/components/item/FolderContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ const FolderContent = ({ item }: { item: PackedItem }): JSX.Element => {
)
.sort(sortFn);

const sortingOptions = Object.values(SortingOptionsForFolder).sort((t1, t2) =>
translateEnums(t1).localeCompare(translateEnums(t2)),
);

if (children) {
return (
<>
Expand Down Expand Up @@ -195,10 +199,7 @@ const FolderContent = ({ item }: { item: PackedItem }): JSX.Element => {
ordering={ordering}
sortBy={sortBy}
setSortBy={setSortBy}
options={Object.values(SortingOptionsForFolder).sort(
(t1, t2) =>
translateEnums(t1).localeCompare(translateEnums(t2)),
)}
options={sortingOptions}
setOrdering={setOrdering}
/>
)}
Expand Down
14 changes: 5 additions & 9 deletions src/components/main/DeleteItemDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const DeleteItemDialog = ({
handleClose();
};

const names = items
.sort((a, b) => (a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1))
.map(({ name }) => <li>{name}</li>);

return (
<Dialog
open={open}
Expand All @@ -58,15 +62,7 @@ const DeleteItemDialog = ({
{translateBuilder(BUILDER.DELETE_ITEM_MODAL_CONTENT, {
count: itemIds.length,
})}
<ul>
{items
.sort((a, b) =>
a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1,
)
.map(({ name }) => (
<li>{name}</li>
))}
</ul>
<ul>{names}</ul>
</DialogContentText>
</DialogContent>
<DialogActions>
Expand Down
15 changes: 8 additions & 7 deletions src/components/main/list/ItemsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const ItemsTable = ({
showThumbnails = true,
canMove = true,
enableMoveInBetween = true,
selectedIds,
selectedIds = [],
onCardClick,
onMove,
}: ItemsTableProps): JSX.Element => {
Expand Down Expand Up @@ -108,16 +108,16 @@ const ItemsTable = ({
// cannot move item into itself, or target cannot be part of selection if moving selection
if (
movedItem.id === targetItem.id ||
(selectedIds?.includes(movedItem?.id) &&
selectedIds?.includes(targetItem.id))
(selectedIds.includes(movedItem?.id) &&
selectedIds.includes(targetItem.id))
) {
toast.error(translateMessage(FAILURE_MESSAGES.INVALID_MOVE_TARGET));
return;
}

let movedItems: PackedItem[] = [];
// use selected ids on drag move if moved item is part of selected ids
if (selectedIds?.includes(movedItem?.id)) {
if (selectedIds.includes(movedItem?.id)) {
movedItems = rows.filter(({ id }) => selectedIds.includes(id));
} else if (movedItem) {
movedItems = [movedItem];
Expand Down Expand Up @@ -170,6 +170,9 @@ const ItemsTable = ({
}
};

const isSelected = (droppedEl: PackedItem | { files: File[] }): boolean =>
'id' in droppedEl ? selectedIds.includes(droppedEl.id) : false;

return (
<>
<DraggingWrapper
Expand All @@ -185,9 +188,7 @@ const ItemsTable = ({
enableMoveInBetween={enableMoveInBetween}
itemsStatuses={itemsStatuses}
showThumbnails={showThumbnails}
isSelected={
'id' in droppedEl ? selectedIds?.includes(droppedEl.id) : false
}
isSelected={isSelected(droppedEl)}
onThumbnailClick={() => {
if ('id' in droppedEl) {
onCardClick?.(droppedEl.id);
Expand Down
9 changes: 6 additions & 3 deletions src/components/pages/home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const HomeScreenContent = ({ searchText }: { searchText: string }) => {
<FileUploader buttons={<NewItemButton />} />
</Box>
);

if (data.pages[0].data.length) {
const totalFetchedItems = data
? data.pages.map(({ data: d }) => d.length).reduce((a, b) => a + b, 0)
Expand Down Expand Up @@ -122,6 +123,10 @@ const HomeScreenContent = ({ searchText }: { searchText: string }) => {
content = <NoItemFilters searchText={searchText} />;
}

const sortingOptions = Object.values(SortingOptions).sort((t1, t2) =>
translateEnums(t1).localeCompare(translateEnums(t2)),
);

return (
<>
<Stack
Expand Down Expand Up @@ -157,9 +162,7 @@ const HomeScreenContent = ({ searchText }: { searchText: string }) => {
setSortBy={setSortBy}
ordering={ordering}
setOrdering={setOrdering}
options={Object.values(SortingOptions).sort((t1, t2) =>
translateEnums(t1).localeCompare(translateEnums(t2)),
)}
options={sortingOptions}
/>
)}
<ModeButton />
Expand Down
2 changes: 2 additions & 0 deletions src/config/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,5 @@ export const RECYCLE_BIN_DELETE_MANY_ITEMS_BUTTON_ID =

export const RECYCLE_BIN_RESTORE_MANY_ITEMS_BUTTON_ID =
'recycleBinRestoreManyButton';
export const COPY_MANY_ITEMS_BUTTON_SELECTOR = `[data-testid="FilterNoneIcon"]`;
export const MOVE_MANY_ITEMS_BUTTON_SELECTOR = `[data-testid="OpenWithIcon"]`;
Loading

0 comments on commit e7fdcbe

Please sign in to comment.