Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Commit

Permalink
fix: make PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
spaenleh committed May 31, 2023
1 parent d60deee commit d205672
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 184 deletions.
10 changes: 1 addition & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,7 @@
{
"allowHigherOrderFunctions": true
}
],
// "@typescript-eslint/explicit-function-return-type": [
// "error",
// {
// "allowExpressions": true,
// "allowTypedFunctionExpressions": true,
// "allowHigherOrderFunctions": true,
// }
// ]
]
}
},
{
Expand Down
5 changes: 2 additions & 3 deletions cypress/e2e/header.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { HOME_PATH } from '../../src/config/paths';
import {
HEADER_MEMBER_MENU_BUTTON_ID,
HEADER_MEMBER_MENU_SEE_PROFILE_BUTTON_ID, // HEADER_MEMBER_MENU_SIGN_IN_BUTTON_ID,
HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID, // buildMemberMenuItemId,
HEADER_MEMBER_MENU_SEE_PROFILE_BUTTON_ID,
HEADER_MEMBER_MENU_SIGN_OUT_BUTTON_ID,
} from '../../src/config/selectors';
// import { MOCK_SESSIONS } from '../fixtures/members';
import { MEMBER_PROFILE_PATH, SIGN_IN_PATH } from '../support/constants';

// catch hook warning from react
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ describe('Navigation', () => {
cy.setUpApi({
items: [...items, ...sharedItems],
});
// eslint-disable-next-line no-console
console.log(items);
cy.visit('/');

cy.wait(['@getCurrentMember', '@getOwnItems', '@getSharedItems']);

cy.get(`#${MY_ITEMS_ID} #${SHOW_MORE_ITEMS_ID}`).click();
items.forEach((i) =>
cy.get(`.${buildTreeItemClass(i.id)}`, { timeout: 2000 }),
Expand Down
8 changes: 0 additions & 8 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ Cypress.Commands.add(
);
mockGetItemChat({ chatMessages });
mockGetItemMembershipsForItem(items, currentMember);
// mockGetPublicItem({ items: cachedItems });

mockGetItemTags(items, currentMember);

mockGetItemsTags(items, currentMember);
mockGetLoginSchemaType(items, currentMember);

mockGetChildren(items, currentMember);
// mockGetPublicChildren(cachedItems);

mockGetDescendants(items, currentMember);

Expand All @@ -70,7 +68,6 @@ Cypress.Commands.add(
mockGetCurrentMember(currentMember, getCurrentMemberError);

mockDefaultDownloadFile({ items, currentMember });
// mockPublicDefaultDownloadFile(cachedItems);

mockSignOut();

Expand Down Expand Up @@ -140,11 +137,6 @@ declare global {
getIframeDocument(iframeSelector: string): Chainable;
getIframeBody(iframeSelector: string): Chainable;

// clickElementInIframe(
// iframeSelector: string,
// elementSelector: string,
// ): Chainable;

checkContentInElementInIframe(
iframeSelector: string,
elementSelector: string,
Expand Down
113 changes: 0 additions & 113 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ const checkMemberHasAccess = ({
return { statusCode: StatusCodes.FORBIDDEN };
};

// const checkIsPublic = (item: MockItem): { statusCode: number } | undefined => {
// const isPublic = item?.tags?.find(({ tagId }) => tagId === PUBLIC_TAG_ID);
// if (!isPublic) {
// return { statusCode: StatusCodes.UNAUTHORIZED };
// }
// return undefined;
// };

export const mockGetOwnItems = ({
items,
currentMember,
Expand Down Expand Up @@ -305,39 +297,6 @@ export const mockGetItemMembershipsForItem = (
).as('getItemMemberships');
};

// export const mockGetPublicItem = (
// { items }: { items: MockItem[] },
// shouldThrowError?: boolean,
// ): void => {
// cy.intercept(
// {
// method: DEFAULT_GET.method,
// url: new RegExp(`${API_HOST}/${buildGetPublicItemRoute(ID_FORMAT)}$`),
// },
// ({ url, reply }) => {
// const itemId = url.slice(API_HOST.length).split('/')[3];
// const item = getItemById(items, itemId);

// // item does not exist in db
// if (!item || shouldThrowError) {
// return reply({
// statusCode: StatusCodes.NOT_FOUND,
// });
// }

// const error = checkIsPublic(item);
// if (isError(error)) {
// return reply(error);
// }

// return reply({
// body: item,
// statusCode: StatusCodes.OK,
// });
// },
// ).as('getPublicItem');
// };

export const mockGetChildren = (items: MockItem[], member: Member): void => {
cy.intercept(
{
Expand Down Expand Up @@ -400,35 +359,6 @@ export const mockGetDescendants = (items: MockItem[], member: Member): void => {
).as('getDescendants');
};

// export const mockGetPublicChildren = (items: MockItem[]): void => {
// cy.intercept(
// {
// method: DEFAULT_GET.method,
// url: new RegExp(`${API_HOST}/p/items/${ID_FORMAT}/children`),
// },
// ({ url, reply }) => {
// const id = url.slice(API_HOST.length).split('/')[3];
// const item = items.find(({ id: thisId }) => id === thisId);
// // item does not exist in db
// if (!item) {
// return reply({
// statusCode: StatusCodes.NOT_FOUND,
// });
// }

// const error = checkIsPublic(item);
// if (isError(error)) {
// return reply(error);
// }

// const children = items.filter((testItem) =>
// isChildOf(testItem.path, item.path),
// );
// return reply(children);
// },
// ).as('getPublicChildren');
// };

export const mockGetMemberBy = (
members: Member[],
shouldThrowError?: boolean,
Expand Down Expand Up @@ -498,49 +428,6 @@ export const mockDefaultDownloadFile = (
).as('downloadFile');
};

// export const mockPublicDefaultDownloadFile = (
// items: MockItem[],
// shouldThrowError?: boolean,
// ): void => {
// cy.intercept(
// {
// method: DEFAULT_GET.method,
// url: new RegExp(
// `${API_HOST}/${buildPublicDownloadFilesRoute(ID_FORMAT)}`,
// ),
// },
// ({ reply, url }) => {
// if (shouldThrowError) {
// return reply({ statusCode: StatusCodes.BAD_REQUEST });
// }

// const id = url.slice(API_HOST.length).split('/')[3];
// const item = items.find(({ id: thisId }) => id === thisId);
// const { replyUrl } = qs.parse(url.slice(url.indexOf('?') + 1));

// // item does not exist in db
// if (!item) {
// return reply({
// statusCode: StatusCodes.NOT_FOUND,
// });
// }

// const error = checkIsPublic(item);
// if (isError(error)) {
// return reply(error);
// }

// // either return the file url or the fixture data
// // info: we don't test fixture data anymore since the frontend uses url only
// if (replyUrl) {
// return reply({ url: item.filepath });
// }

// return reply({ fixture: item.filepath });
// },
// ).as('publicDownloadFile');
// };

export const mockGetItemTags = (items: MockItem[], member: Member): void => {
cy.intercept(
{
Expand Down
25 changes: 10 additions & 15 deletions src/config/notifier.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { toast } from 'react-toastify';

import { FAILURE_MESSAGES, SUCCESS_MESSAGES } from '@graasp/translations';
import { Notifier } from '@graasp/query-client';

import { useMessagesTranslation } from '@/config/i18n';
// import { FAILURE_MESSAGES, SUCCESS_MESSAGES } from '@graasp/translations';

type NotifierType = {
type: string;
payload: { error: string };
};

// todo: check how this works and improve error reporting
export default ({ type, payload }: NotifierType): void => {
const { t } = useMessagesTranslation();
const notifier: Notifier = ({ type, payload }) => {
const message = null;
switch (type) {
// error messages
Expand All @@ -22,13 +15,15 @@ export default ({ type, payload }: NotifierType): void => {

// error notification
if (payload?.error && message) {
const translatedMessage =
t(message) || t(FAILURE_MESSAGES.UNEXPECTED_ERROR);
toast.error(translatedMessage);
// todo: can't use translation hooks inside this function
// const translatedMessage =
// t(message) || t(FAILURE_MESSAGES.UNEXPECTED_ERROR);
toast.error(message);
}
// success notification
else if (message) {
const translatedMessage = t(message) || t(SUCCESS_MESSAGES.DEFAULT_SUCCESS);
toast.success(translatedMessage);
// const translatedMessage = t(message) || t(SUCCESS_MESSAGES.DEFAULT_SUCCESS);
toast.success(message);
}
};
export default notifier;
5 changes: 2 additions & 3 deletions src/config/queryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ const {
API_HOST,
DOMAIN,
// todo: improve types
notifier: notifier as (e: unknown) => void,
// todo: re-enable once websockets work in refactor
enableWebsocket: false,
notifier,
enableWebsocket: true,
defaultQueryOptions: {
keepPreviousData: true,
// avoid refetching when same data are closely fetched
Expand Down
27 changes: 14 additions & 13 deletions src/modules/common/HiddenWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Box, styled } from '@mui/material';

import { ItemRecord } from '@graasp/sdk/frontend';
import { PLAYER } from '@graasp/translations';

import { usePlayerTranslation } from '@/config/i18n';
import { buildHiddenWrapperId } from '@/config/selectors';

export const HIDDEN_STYLE = {
Expand All @@ -23,18 +25,17 @@ const HiddenWrapper = ({
hidden: boolean;
itemId: ItemRecord['id'];
children: JSX.Element;
}): JSX.Element => (
<StyledBox
isHidden={isHidden}
id={buildHiddenWrapperId(itemId, isHidden)}
title={
isHidden
? "This element is hidden, you can see it because you have admin or write access, users with read access won't see it"
: undefined
}
>
{children}
</StyledBox>
);
}): JSX.Element => {
const { t } = usePlayerTranslation();
return (
<StyledBox
isHidden={isHidden}
id={buildHiddenWrapperId(itemId, isHidden)}
title={isHidden ? t(PLAYER.HIDDEN_WRAPPER_TOOLTIP) : undefined}
>
{children}
</StyledBox>
);
};

export default HiddenWrapper;
3 changes: 3 additions & 0 deletions src/modules/item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ const ItemContent = ({ item }: ItemContentProps) => {
);
return folderButton;

// todo: check that the folders are displayed as expected.
// in case everything is okay, remove the following

// // display children shortcut pinned folders
// if (isShortcut && isShortcutPinned) {
// return folderButton;
Expand Down
5 changes: 2 additions & 3 deletions src/modules/pages/ItemPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ItemScreenWrapper = (rootId: string) => {

const { usePostItemLogin, useSignOut } = mutations;

const ItemPage = (): JSX.Element => {
const ItemPage = (): JSX.Element | null => {
const { mutate: signOut } = useSignOut();
const { mutate: itemLoginSignIn } = usePostItemLogin();
const { rootId } = useParams();
Expand All @@ -35,8 +35,7 @@ const ItemPage = (): JSX.Element => {

if (!rootId) {
navigate(HOME_PATH);
// TODO: return not found?
return ForbiddenContent;
return null;
}

const Component = ItemLoginAuthorization({
Expand Down
14 changes: 0 additions & 14 deletions src/modules/tree/DynamicTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ const DynamicTreeView = ({
const [expandedItems, setExpandedItems] = useState(initialExpendedItems);
const [showAll, setShowAll] = useState(false);

// const {
// data: children,
// isLoading: isLoadingChildren,
// isError: isErrorChildren,
// } = useDescendants(rootId, {
// enabled: isFolder,
// getUpdates: isFolder,
// });

if (isLoading) {
return <Skeleton variant="text" />;
}
Expand All @@ -63,11 +54,6 @@ const DynamicTreeView = ({
const onToggle = (_event: unknown, nodeIds: string[]) =>
setExpandedItems(nodeIds);

// show only folder items in the navigation tree
// const itemsFiltered = items?.filter((item) =>
// GRAASP_MENU_ITEMS.includes(item.type),
// );

const itemsToShow = items?.filter((item) =>
onlyShowContainerItems ? GRAASP_MENU_ITEMS.includes(item.type) : true,
);
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default ({ mode }: { mode: string }): UserConfigExport => {
base: '',
server: {
port: parseInt(process.env.VITE_PORT, 10),
// open: true,
open: true,
watch: {
ignored: ['**/coverage/**'],
},
Expand Down

0 comments on commit d205672

Please sign in to comment.