Skip to content

Commit

Permalink
chore: wrap freeze header in a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed Sep 5, 2024
1 parent 6364ede commit 94603a6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
6 changes: 4 additions & 2 deletions app/components/AnalystDashboard/AllDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
const showLeadFeatureFlag = useFeature('show_lead').value ?? false;
const showCbcProjects = useFeature('show_cbc_projects').value ?? false;
const showCbcProjectsLink = useFeature('show_cbc_view_link').value ?? false;
const freezeHeader = useFeature('freeze_dashboard_header').value ?? false;
const [columnVisibility, setColumnVisibility] = useState<MRT_VisibilityState>(
{ Lead: false, program: false }
);
Expand Down Expand Up @@ -594,13 +595,13 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
muiTableContainerProps: {
sx: {
padding: '0 8px 8px 8px',
maxHeight: 'calc(100vh - 460px)',
maxHeight: freezeHeader ? 'calc(100vh - 460px)' : '100%',
},
},
layoutMode: isLargeUp ? 'grid' : 'semantic',
muiTableBodyCellProps,
muiTableHeadCellProps,
enableStickyHeader: true,
enableStickyHeader: freezeHeader,
onSortingChange: handleOnSortChange,
onColumnFiltersChange: setColumnFilters,
autoResetAll: false,
Expand Down Expand Up @@ -642,6 +643,7 @@ const AllDashboardTable: React.FC<Props> = ({ query }) => {
<>
{renderRowCount()}
<MaterialReactTable table={table} />
{!freezeHeader && renderRowCount()}
</>
);
};
Expand Down
33 changes: 30 additions & 3 deletions app/tests/pages/analyst/dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ const mockShowCbcProjects = (
ruleId: 'show_cbc_projects',
});

const mockFreezeHeader = (
value: boolean
): moduleApi.FeatureResult<boolean> => ({
value,
source: 'defaultValue',
on: null,
off: null,
ruleId: 'freeze_dashboard_header',
});

jest.mock('js-cookie', () => ({
get: jest.fn(),
remove: jest.fn(),
Expand Down Expand Up @@ -433,9 +443,26 @@ describe('The index page', () => {
});

it('renders analyst table row counts', async () => {
jest
.spyOn(moduleApi, 'useFeature')
.mockReturnValue(mockShowCbcProjects(true));
jest.spyOn(moduleApi, 'useFeature').mockImplementation((ruleId: string) => {
if (ruleId === 'freeze_dashboard_header') {
return mockFreezeHeader(false);
}
return mockShowCbcProjects(true);
});
pageTestingHelper.loadQuery();
pageTestingHelper.renderPage();

const countRows = screen.getAllByText(/Showing 8 of 8 rows/i);
expect(countRows).toHaveLength(2);
});

it('remove bottom analyst table row counts when freeze dashboard header', async () => {
jest.spyOn(moduleApi, 'useFeature').mockImplementation((ruleId: string) => {
if (ruleId === 'freeze_dashboard_header') {
return mockFreezeHeader(true);
}
return mockShowCbcProjects(true);
});
pageTestingHelper.loadQuery();
pageTestingHelper.renderPage();

Expand Down

0 comments on commit 94603a6

Please sign in to comment.