Skip to content

Commit

Permalink
feat: remove is published badge (#1569)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia authored Nov 15, 2024
1 parent 2c18136 commit 420602c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 54 deletions.
3 changes: 0 additions & 3 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import {
mockGetItems,
mockGetLatestValidationGroup,
mockGetLinkMetadata,
mockGetManyPublishItemInformations,
mockGetMember,
mockGetMemberMentions,
mockGetMembershipRequestsForItem,
Expand Down Expand Up @@ -314,8 +313,6 @@ Cypress.Commands.add(

mockGetPublishItemInformations(items);

mockGetManyPublishItemInformations(items);

mockGetLatestValidationGroup(items, itemValidationGroups);

mockUpdatePassword(members, updatePasswordError);
Expand Down
28 changes: 0 additions & 28 deletions cypress/support/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1823,34 +1823,6 @@ export const mockGetPublishItemInformations = (items: ItemForTest[]): void => {
).as('getPublishItemInformations');
};

export const mockGetManyPublishItemInformations = (
items: ItemForTest[],
): void => {
cy.intercept(
{
method: HttpMethod.Get,
url: new RegExp(`${API_HOST}/items/collections/informations`),
},
({ reply, url }) => {
const itemIds = new URL(url).searchParams.getAll('itemId');
const completeItems = items.filter((i) => itemIds.includes(i.id));

const result = {
data: {} as { [key: ItemForTest['id']]: ItemPublished },
errors: new Array<{ statusCode: number }>(),
};
for (const i of completeItems) {
if (i.published) {
result.data[i.id] = i.published;
} else {
result.errors.push({ statusCode: StatusCodes.NOT_FOUND });
}
}
return reply(result);
},
).as('getManyPublishItemInformations');
};

export const mockGetPublishItemsForMember = (
publishedItemData: ItemPublished[],
shoulThrow = false,
Expand Down
27 changes: 4 additions & 23 deletions src/components/table/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ import { DiscriminatedItem, PackedItem } from '@graasp/sdk';
import { ItemBadges } from '@graasp/ui';

import { useBuilderTranslation } from '../../config/i18n';
import { hooks } from '../../config/queryClient';
import { BUILDER } from '../../langs/constants';

const { useManyItemPublishedInformations } = hooks;

type ItemStatuses = {
showChatbox: boolean;
isPinned: boolean;
isCollapsible: boolean;
isHidden: boolean;
isPublic: boolean;
isPublished: boolean;
};

const DEFAULT_ITEM_STATUSES: ItemStatuses = {
Expand All @@ -22,7 +18,6 @@ const DEFAULT_ITEM_STATUSES: ItemStatuses = {
isCollapsible: false,
isHidden: false,
isPublic: false,
isPublished: false,
};

export type ItemsStatuses = { [key: DiscriminatedItem['id']]: ItemStatuses };
Expand All @@ -36,19 +31,14 @@ export const useItemsStatuses = ({
items = [],
}: {
items?: PackedItem[];
}): ItemsStatuses => {
const { data: publishedInformations } = useManyItemPublishedInformations({
itemIds: items.map((i) => i.id),
});

return items.reduce((acc, r) => {
}): ItemsStatuses =>
items.reduce((acc, r) => {
const { showChatbox, isPinned, isCollapsible } = {
...DEFAULT_ITEM_STATUSES,
...r.settings,
};
const isHidden = Boolean(r.hidden);
const isPublic = Boolean(r.public);
const isPublished = Boolean(publishedInformations?.data?.[r.id]);

return {
...acc,
Expand All @@ -58,24 +48,16 @@ export const useItemsStatuses = ({
isCollapsible,
isHidden,
isPublic,
isPublished,
},
};
}, {} as ItemsStatuses);
};

const Badges = ({ itemsStatuses, data: item }: ChildCompProps): JSX.Element => {
const { t } = useBuilderTranslation();
// this is useful because the item.id we are looking for may not be present and the itemStatuses will be undefined
const itemStatuses = itemsStatuses?.[item.id] || DEFAULT_ITEM_STATUSES;
const {
showChatbox,
isPinned,
isHidden,
isPublic,
isPublished,
isCollapsible,
} = itemStatuses;
const { showChatbox, isPinned, isHidden, isPublic, isCollapsible } =
itemStatuses;
return (
<ItemBadges
isPinned={isPinned}
Expand All @@ -84,7 +66,6 @@ const Badges = ({ itemsStatuses, data: item }: ChildCompProps): JSX.Element => {
isHiddenTooltip={t(BUILDER.STATUS_TOOLTIP_IS_HIDDEN)}
isPublic={isPublic}
isPublicTooltip={t(BUILDER.STATUS_TOOLTIP_IS_PUBLIC)}
isPublished={isPublished}
isPublishedTooltip={t(BUILDER.STATUS_TOOLTIP_IS_PUBLISHED)}
isCollapsible={isCollapsible}
isCollapsibleTooltip={t(BUILDER.STATUS_TOOLTIP_IS_COLLAPSIBLE)}
Expand Down

0 comments on commit 420602c

Please sign in to comment.