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

feat: filter children in useChildren directly #1031

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 18 additions & 7 deletions cypress/e2e/item/move/listMoveMultiple.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,24 @@ describe('Move Items in List', () => {
const itemIds = [SAMPLE_ITEMS.items[2].id, SAMPLE_ITEMS.items[4].id];
moveItems({ itemIds, toItemPath: MY_GRAASP_ITEM_PATH });

cy.wait('@moveItems').then(({ request: { body, url } }) => {
expect(body.parentId).to.equal(undefined);
itemIds.forEach((movedItem) => expect(url).to.contain(movedItem));
// Since we are invalidating the query cache and the API is mocked,
// the items received remain unchanged even after the websockets update.
// It's not feasible to verify the addition of new items in this test scenario
// unless a real backend is utilized for testing purposes.

itemIds.forEach((id) => {
cy.get(`${buildItemsTableRowIdAttribute(id)}`).should('not.exist');
});
});
// cy.wait('@moveItems').then(({ request: { body, url } }) => {
// expect(body.parentId).to.equal(undefined);
// itemIds.forEach((movedItem) => expect(url).to.contain(movedItem));

// itemIds.forEach((id) => {
// cy.get(`${buildItemsTableRowIdAttribute(id)}`).should('not.exist');
// });
// });

// Therefore, in this test, we can only verify that upon receiving a websocket message,
// the cache is invalidated and a refetch is triggered.

cy.wait('@moveItems');
ReidyT marked this conversation as resolved.
Show resolved Hide resolved
cy.wait('@getChildren');
});
});
28 changes: 23 additions & 5 deletions cypress/e2e/ws/item.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,18 @@ describe('Websocket interactions', () => {
},
});

cy.wait(WEBSOCKETS_DELAY_TIME);
// Since we are invalidating the query cache and the API is mocked,
// the items received remain unchanged even after the websockets update.
// It's not feasible to verify the addition of new items in this test scenario
// unless a real backend is utilized for testing purposes.

// cy.wait(WEBSOCKETS_DELAY_TIME);
// assert item is in list
cy.get(buildItemsTableRowIdAttribute(item.id)).should('exist');
// cy.get(buildItemsTableRowIdAttribute(item.id)).should('exist');

// Therefore, in this test, we can only verify that upon receiving a websocket message,
// the cache is invalidated and a refetch is triggered.
cy.wait('@getChildren');
});

it('displays childItem delete update', () => {
Expand All @@ -136,9 +145,18 @@ describe('Websocket interactions', () => {
},
});

cy.wait(WEBSOCKETS_DELAY_TIME);
// assert item is not in list
cy.get(buildItemsTableRowIdAttribute(item.id)).should('not.exist');
// Since we are invalidating the query cache and the API is mocked,
// the items received remain unchanged even after the websockets update.
// It's not feasible to verify the suppression of old items in this test scenario
// unless a real backend is utilized for testing purposes.

// cy.wait(WEBSOCKETS_DELAY_TIME);
// assert item is in list
// cy.get(buildItemsTableRowIdAttribute(item.id)).should('not.exist');

// Therefore, in this test, we can only verify that upon receiving a websocket message,
// the cache is invalidated and a refetch is triggered.
cy.wait('@getChildren');
});
});
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@emotion/react": "11.11.3",
"@emotion/styled": "11.11.0",
"@graasp/chatbox": "3.0.3",
"@graasp/query-client": "2.6.2",
"@graasp/query-client": "github:graasp/graasp-query-client#831-send-ws-feedback-after-transaction-move",
"@graasp/sdk": "3.8.3",
"@graasp/translations": "1.24.0",
"@graasp/ui": "4.8.1",
Expand All @@ -41,6 +41,7 @@
"date-fns": "3.3.1",
"filesize": "10.1.0",
"http-status-codes": "2.3.0",
"i18next": "23.10.0",
"katex": "0.16.9",
"leaflet-geosearch": "3.11.0",
"lodash.debounce": "4.0.8",
Expand Down
2 changes: 1 addition & 1 deletion src/components/context/FilterItemsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const FilterItemsContextProvider = ({
itemTypes,
setItemTypes,
shouldDisplayItem: (itemType: ItemTypeConst) =>
itemTypes.length === 0 || itemTypes.includes(itemType),
Boolean(!itemTypes.length || itemTypes.includes(itemType)),
}),
[itemTypes],
);
Expand Down
10 changes: 4 additions & 6 deletions src/components/item/ItemContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,17 @@ const FolderContent = ({
item: FolderItemType;
enableEditing: boolean;
}): JSX.Element => {
const { shouldDisplayItem } = useFilterItemsContext();
const { itemTypes } = useFilterItemsContext();

const {
data: children,
isLoading,
isError,
} = useChildren(item.id, {
ordered: true,
types: itemTypes,
});

// TODO: use hook's filter when available
const folderChildren = children?.filter((f) => shouldDisplayItem(f.type));

if (isLoading) {
return <Loader />;
}
Expand All @@ -200,14 +198,14 @@ const FolderContent = ({
parentId={item.id}
id={buildItemsTableId(item.id)}
title={item.name}
items={folderChildren ?? []}
items={children ?? []}
headerElements={
enableEditing ? [<NewItemButton key="newButton" />] : undefined
}
// todo: not exactly correct, since you could have write rights on some child,
// but it's more tedious to check permissions over all selected items
ToolbarActions={enableEditing ? ItemActions : undefined}
totalCount={folderChildren?.length}
totalCount={children?.length}
/>
);
};
Expand Down
13 changes: 4 additions & 9 deletions src/components/item/publish/ItemPublishTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
Typography,
} from '@mui/material';

import { DATA_KEYS } from '@graasp/query-client';
import {
ItemTagType,
ItemValidationStatus,
Expand All @@ -36,7 +35,7 @@ import { OutletType } from '@/components/pages/item/type';

import { ADMIN_CONTACT, CC_LICENSE_ABOUT_URL } from '../../../config/constants';
import { useBuilderTranslation } from '../../../config/i18n';
import { hooks, mutations, useQueryClient } from '../../../config/queryClient';
import { hooks, mutations } from '../../../config/queryClient';
import {
ITEM_PUBLISH_SECTION_TITLE_ID,
ITEM_VALIDATION_BUTTON_ID,
Expand Down Expand Up @@ -64,7 +63,6 @@ const enum PublishFlow {

const ItemPublishTab = (): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const queryClient = useQueryClient();
const { item, permission = PermissionLevel.Read } =
useOutletContext<OutletType>();

Expand Down Expand Up @@ -92,9 +90,8 @@ const ItemPublishTab = (): JSX.Element => {
// item validation
const { mutate: validateItem } = usePostItemValidation();

const { data: lastItemValidationGroup } = useLastItemValidationGroup(
item?.id,
);
const { data: lastItemValidationGroup, refetch: refetchValidation } =
useLastItemValidationGroup(item?.id);

useEffect(() => {
// check if validation is still valid
Expand Down Expand Up @@ -162,9 +159,7 @@ const ItemPublishTab = (): JSX.Element => {
};

const handleRefresh = () => {
queryClient.invalidateQueries(
DATA_KEYS.buildLastItemValidationGroupKey(item.id),
);
refetchValidation();
};

// display icon indicating current status of given item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const ChildrenNavigationTree = ({
isDisabled,
}: ChildrenNavigationTreeProps): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const { data: children } = hooks.useChildren(selectedNavigationItem.id);
// TODO: use hook's filter when available
const folders = children?.filter((f) => f.type === ItemType.FOLDER);
const { data: folders } = hooks.useChildren(selectedNavigationItem.id, {
types: [ItemType.FOLDER],
});
return (
<>
{folders?.map((ele) => (
Expand Down
42 changes: 16 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1522,22 +1522,20 @@ __metadata:
languageName: node
linkType: hard

"@graasp/query-client@npm:2.6.2":
version: 2.6.2
resolution: "@graasp/query-client@npm:2.6.2"
"@graasp/query-client@github:graasp/graasp-query-client#831-send-ws-feedback-after-transaction-move":
version: 2.6.3
resolution: "@graasp/query-client@https://github.com/graasp/graasp-query-client.git#commit=18661c32e30451e958211ba3d51dbe33267b4963"
dependencies:
"@graasp/sdk": "npm:3.8.3"
"@graasp/translations": "npm:1.23.0"
axios: "npm:0.27.2"
crypto-js: "npm:4.2.0"
date-fns: "npm:3.3.1"
http-status-codes: "npm:2.3.0"
qs: "npm:6.11.2"
react-query: "npm:3.39.3"
uuid: "npm:9.0.1"
peerDependencies:
"@graasp/sdk": ^3.8.3
"@graasp/translations": ^1.23.0
react: ^17.0.0 || ^18.0.0
checksum: 10/f0e790c26c4d97c6a6e012799ac07ef66b5349a40398109dabb4c83eabe5513d1aa2d005748790226115c5ce11b338071a228d27c5f7a00debfdc4eda9ef64cc
checksum: 10/b881477f76d8ac3f841fa0ef31dd702383bb25878b339e42f8cacca1cbfa6bac6925b6c6c59c0e32b146eb04c69d7e19e44128be95d1e874bcb14c60e390fd8d
languageName: node
linkType: hard

Expand All @@ -1555,15 +1553,6 @@ __metadata:
languageName: node
linkType: hard

"@graasp/translations@npm:1.23.0":
version: 1.23.0
resolution: "@graasp/translations@npm:1.23.0"
dependencies:
i18next: "npm:23.7.16"
checksum: 10/dc0d605b520a28deb1ad3054323dc4b71f709b79adf5924552c602f3c3ed2fa7c3c8538a3015c86c8db05867159df4b2f6ad18583766b2b97c8dd850952d29e2
languageName: node
linkType: hard

"@graasp/translations@npm:1.24.0":
version: 1.24.0
resolution: "@graasp/translations@npm:1.24.0"
Expand Down Expand Up @@ -7476,7 +7465,7 @@ __metadata:
"@emotion/react": "npm:11.11.3"
"@emotion/styled": "npm:11.11.0"
"@graasp/chatbox": "npm:3.0.3"
"@graasp/query-client": "npm:2.6.2"
"@graasp/query-client": "github:graasp/graasp-query-client#831-send-ws-feedback-after-transaction-move"
"@graasp/sdk": "npm:3.8.3"
"@graasp/translations": "npm:1.24.0"
"@graasp/ui": "npm:4.8.1"
Expand Down Expand Up @@ -7531,6 +7520,7 @@ __metadata:
filesize: "npm:10.1.0"
http-status-codes: "npm:2.3.0"
husky: "npm:9.0.11"
i18next: "npm:23.10.0"
katex: "npm:0.16.9"
leaflet-geosearch: "npm:3.11.0"
lodash.debounce: "npm:4.0.8"
Expand Down Expand Up @@ -7860,21 +7850,21 @@ __metadata:
languageName: node
linkType: hard

"i18next@npm:23.7.11":
version: 23.7.11
resolution: "i18next@npm:23.7.11"
"i18next@npm:23.10.0":
version: 23.10.0
resolution: "i18next@npm:23.10.0"
dependencies:
"@babel/runtime": "npm:^7.23.2"
checksum: 10/1127bc17f94459d40bd9aaa0350e9786d3853eb82449aabb4514e187fafc752c76a3f52c6be1c2722bfdadaa74f0d26b4f7dd04528ba6b2de7e34f5c6c019c21
checksum: 10/d32293a40650783ac746ce476d220ac3285133de729b2c1da0e7c91bc396ec6728629e84ea4c06311ae37dc6b7984ca962d5b296deb58cf713ba477a2edbd0ea
languageName: node
linkType: hard

"i18next@npm:23.7.16":
version: 23.7.16
resolution: "i18next@npm:23.7.16"
"i18next@npm:23.7.11":
version: 23.7.11
resolution: "i18next@npm:23.7.11"
dependencies:
"@babel/runtime": "npm:^7.23.2"
checksum: 10/77e74c07a73316f6fb6678a5a3e8ce58a6e66be457dd1ccd23941e9fc57ad8e1da55193fa6328c70b86073337b776cd267f3c13c6309f548b3116f27a1e41787
checksum: 10/1127bc17f94459d40bd9aaa0350e9786d3853eb82449aabb4514e187fafc752c76a3f52c6be1c2722bfdadaa74f0d26b4f7dd04528ba6b2de7e34f5c6c019c21
languageName: node
linkType: hard

Expand Down
Loading