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: remove is published badge #1569

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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