Skip to content

Commit 50467bc

Browse files
committed
release(cp): fix: Contentful prioritization
1 parent 83fda90 commit 50467bc

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

shared/constants/app-state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export type CarouselSlide = {
3232
undismissable?: boolean;
3333
startDate?: string;
3434
endDate?: string;
35+
priorityPlacement?: boolean;
3536
};

ui/components/multichain/carousel/carousel.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ export const Carousel = React.forwardRef(
7474
return !slide.dismissed || slide.undismissable;
7575
})
7676
.sort((a, b) => {
77+
// Prioritize Contentful Priority slides
78+
if (a.priorityPlacement === true && b.priorityPlacement !== true) {
79+
return -1;
80+
}
81+
if (a.priorityPlacement !== true && b.priorityPlacement === true) {
82+
return 1;
83+
}
84+
7785
if (!useExternalServices) {
7886
if (a.id === BASIC_FUNCTIONALITY_SLIDE.id) {
7987
return -1;

ui/hooks/useCarouselManagement/fetchCarouselSlidesFromContentful.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export async function fetchCarouselSlidesFromContentful(): Promise<{
8282
dismissed: false,
8383
startDate,
8484
endDate,
85+
priorityPlacement,
8586
};
8687

8788
if (priorityPlacement) {

ui/hooks/useCarouselManagement/useCarouselManagement.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,49 @@ describe('useCarouselManagement', () => {
544544
});
545545
});
546546

547+
describe('priorityPlacement', () => {
548+
it('should place priority slides before regular contentful slides', async () => {
549+
const PRIORITY_SLIDE: CarouselSlide = {
550+
...FUND_SLIDE,
551+
id: 'contentful-priority-slide-id',
552+
dismissed: false,
553+
priorityPlacement: true,
554+
title: 'Priority Slide',
555+
description: 'Comes first',
556+
image: 'priority.png',
557+
};
558+
559+
const REGULAR_SLIDE: CarouselSlide = {
560+
...CARD_SLIDE,
561+
id: 'regular-slide-id',
562+
dismissed: false,
563+
title: 'Regular Slide',
564+
description: 'Comes later',
565+
image: 'regular.png',
566+
};
567+
568+
jest.mocked(fetchCarouselSlidesFromContentful).mockResolvedValueOnce({
569+
prioritySlides: [PRIORITY_SLIDE],
570+
regularSlides: [REGULAR_SLIDE],
571+
});
572+
573+
renderHook(() =>
574+
useCarouselManagement({ testDate: new Date().toISOString() }),
575+
);
576+
577+
await waitFor(() => expect(mockUpdateSlides).toHaveBeenCalled());
578+
579+
const updatedSlides = mockUpdateSlides.mock.calls[0][0];
580+
const ids = updatedSlides.map((s) => s.id);
581+
582+
expect(ids).toContain('contentful-priority-slide-id');
583+
expect(ids).toContain('regular-slide-id');
584+
expect(ids.indexOf('contentful-priority-slide-id')).toBeLessThan(
585+
ids.indexOf('regular-slide-id'),
586+
);
587+
});
588+
});
589+
547590
describe('Smart account upgrade slide', () => {
548591
beforeEach(() => {
549592
mockGetUseExternalServices.mockReturnValue(false);

0 commit comments

Comments
 (0)