Skip to content

Commit d147fd4

Browse files
authored
Merge pull request #1707 from fedspendingtransparency/FDG-9980
FDG-9980 Data Table Mobile View - Table Select Dialog
2 parents 7fcd958 + dd8a90f commit d147fd4

File tree

5 files changed

+43
-21
lines changed

5 files changed

+43
-21
lines changed

src/components/data-preview/data-preview-dropdown/data-preview-table-select-dropdown.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ import DataPreviewDropdownDialogSearch from '../data-preview-dropdown-search/dat
99
import { pxToNumber } from '../../../helpers/styles-helper/styles-helper';
1010
import { breakpointLg } from '../data-preview.module.scss';
1111
import DataPreviewMobileDialog from '../data-preview-mobile-dialog/data-preview-mobile-dialog';
12-
import DataPreviewMobileFilterList, {
13-
placeholderDataTables,
14-
} from '../data-preview-filter-section/data-preview-mobile-filter-list/data-preview-mobile-filter-list';
12+
import DataPreviewMobileFilterList from '../data-preview-filter-section/data-preview-mobile-filter-list/data-preview-mobile-filter-list';
1513

1614
const DataPreviewTableSelectDropdown: FunctionComponent<ITableSelectDropdown> = ({
1715
apis,
@@ -56,7 +54,7 @@ const DataPreviewTableSelectDropdown: FunctionComponent<ITableSelectDropdown> =
5654
selectedOption={allTablesSelected ? allTablesOption.tableName : selectedTable?.tableName}
5755
active={active}
5856
setActive={setActive}
59-
dropdownWidth="30rem"
57+
dropdownWidth={width < pxToNumber(breakpointLg) ? '20rem' : '30rem'}
6058
/>
6159
);
6260

@@ -156,7 +154,7 @@ const DataPreviewTableSelectDropdown: FunctionComponent<ITableSelectDropdown> =
156154
onClose={handleCancel}
157155
filterName="Data Tables"
158156
searchText="Search data tables"
159-
filterComponent={<DataPreviewMobileFilterList filterOptions={placeholderDataTables} />}
157+
filterComponent={<DataPreviewMobileFilterList filterOptions={options} getName={option => option.tableName} />}
160158
/>
161159
)}
162160
</>

src/components/data-preview/data-preview-filter-section/data-preview-mobile-filter-list/data-preview-mobile-filter-list.spec.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,47 @@ const mockFilters = [
1313

1414
describe('Data preview mobile filter list', () => {
1515
it('Renders a list of buttons', () => {
16-
const { getAllByRole } = render(<DataPreviewMobileFilterList filterOptions={mockFilters} />);
16+
const { getAllByRole } = render(
17+
<DataPreviewMobileFilterList filterOptions={mockFilters} getName={option => option.name} getSecondary={option => option.secondary} />
18+
);
1719
const buttons = getAllByRole('button');
1820
expect(buttons.length).toEqual(6);
1921
});
2022

2123
it('Renders the parts of each button', () => {
22-
const { getByText } = render(<DataPreviewMobileFilterList filterOptions={mockFilters} />);
24+
const { getByText } = render(
25+
<DataPreviewMobileFilterList filterOptions={mockFilters} getName={option => option.name} getSecondary={option => option.secondary} />
26+
);
2327
expect(getByText('Record Date')).toBeInTheDocument();
2428
expect(getByText('Last 5 years')).toBeInTheDocument();
2529
});
2630

2731
it('Adds the selected class onto selected filters', () => {
28-
const { getByRole } = render(<DataPreviewMobileFilterList filterOptions={mockFilters} />);
32+
const { getByRole } = render(
33+
<DataPreviewMobileFilterList filterOptions={mockFilters} getName={option => option.name} getSecondary={option => option.secondary} />
34+
);
2935
expect(getByRole('button', { name: 'Parent ID No filter applied' })).toHaveClass('selected');
3036
expect(getByRole('button', { name: 'Record Date Last 5 years' })).not.toHaveClass('selected');
3137
});
3238

3339
it('Adds the active class onto active filters', () => {
34-
const { getByRole } = render(<DataPreviewMobileFilterList filterOptions={mockFilters} />);
40+
const { getByRole } = render(
41+
<DataPreviewMobileFilterList filterOptions={mockFilters} getName={option => option.name} getSecondary={option => option.secondary} />
42+
);
3543
expect(getByRole('button', { name: 'Record Date Last 5 years' })).toHaveClass('active');
3644
expect(getByRole('button', { name: 'Parent ID No filter applied' })).not.toHaveClass('active');
3745
});
3846

3947
it('Calls the onClick handle upon button click', () => {
4048
const clickHandlerSpy = jest.fn();
41-
const { getByRole } = render(<DataPreviewMobileFilterList onClick={clickHandlerSpy} filterOptions={mockFilters} />);
49+
const { getByRole } = render(
50+
<DataPreviewMobileFilterList
51+
onClick={clickHandlerSpy}
52+
filterOptions={mockFilters}
53+
getName={option => option.name}
54+
getSecondary={option => option.secondary}
55+
/>
56+
);
4257
const button = getByRole('button', { name: 'Record Date Last 5 years' });
4358
fireEvent.click(button);
4459
expect(clickHandlerSpy).toHaveBeenCalled();

src/components/data-preview/data-preview-filter-section/data-preview-mobile-filter-list/data-preview-mobile-filter-list.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,28 @@ export const placeholderFilters = [
2020
{ name: 'Current Month Budget Amount', secondary: 'No filter applied', selected: false, active: false },
2121
];
2222

23-
export const placeholderDataTables = [
24-
{ name: 'All Data Tables (Download Only)', secondary: null, selected: true, active: false },
25-
{ name: 'Summary of Receipts, Outlays, and the Deficit/Surplus of the U.S. Government', secondary: null, selected: false, active: false },
26-
{ name: 'Summary of Budget and Off-Budget Results and Financing of the U.S. Government', secondary: null, selected: false, active: false },
27-
];
28-
2923
export interface IMobileFilterList {
3024
filterOptions: { name: string; secondary?: string; selected?: boolean; active?: boolean }[];
3125
onClick: () => void;
26+
getName: (option: any) => string;
27+
getSecondary: (option: any) => string;
3228
}
3329

34-
const DataPreviewMobileFilterList: FunctionComponent<IMobileFilterList> = ({ filterOptions = placeholderFilters, onClick }) => {
30+
const DataPreviewMobileFilterList: FunctionComponent<IMobileFilterList> = ({
31+
filterOptions = placeholderFilters,
32+
onClick,
33+
getName,
34+
getSecondary = option => option.secondary,
35+
}) => {
3536
return (
3637
<>
3738
{filterOptions.map((filterOption, index) => {
3839
return (
3940
<div key={index}>
4041
<button className={`${buttonSleeve} ${filterOption.selected ? selected : ''} ${filterOption.active ? active : ''}`} onClick={onClick}>
4142
<div className={left}>
42-
<span className={optionName}>{filterOption.name}</span>
43-
{filterOption.secondary && <span className={optionSecondary}>{filterOption.secondary}</span>}
43+
<span className={optionName}>{getName(filterOption)}</span>
44+
{getSecondary(filterOption) && <span className={optionSecondary}>{getSecondary(filterOption)}</span>}
4445
</div>
4546
<div className={right}>
4647
<FontAwesomeIcon icon={faCaretRight} />

src/components/data-preview/data-preview-filter-section/data-preview-table-filters/data-preview-table-filters.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ const DataPreviewTableFilters: FunctionComponent<ITableFilters> = ({
8484
onClose={handleCancel}
8585
filterName="Filters"
8686
searchText="Search filters"
87-
filterComponent={<DataPreviewMobileFilterList filterOptions={placeholderFilters} />}
87+
filterComponent={
88+
<DataPreviewMobileFilterList
89+
filterOptions={placeholderFilters}
90+
getName={option => option.name}
91+
getSecondary={option => option.secondary}
92+
/>
93+
}
8894
/>
8995
)}
9096
</>

src/components/data-preview/data-preview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ export const DataPreview: FunctionComponent<IDataPreview> = ({
259259
return customFormat?.dateFormat && fieldType === 'DATE' ? moment(detailDate).format(customFormat.dateFormat) : detailDate;
260260
};
261261

262+
const checkDataDisplays = config.apis.every(api => (api?.dataDisplays?.length || 0) <= 1);
263+
262264
return (
263265
<DatasetSectionContainer id="data-preview-table">
264266
<DataTableProvider config={config} detailViewState={detailViewState}>
@@ -278,7 +280,7 @@ export const DataPreview: FunctionComponent<IDataPreview> = ({
278280
selectedPivot={selectedPivot}
279281
setSelectedPivot={setSelectedPivot}
280282
pivotsUpdated={pivotsUpdated}
281-
hideDropdown={(config.apis.length === 1 || (detailApi && config.apis.length === 2)) && config.apis[0]?.dataDisplays?.length <= 1}
283+
hideDropdown={(config.apis.length === 1 || (detailApi && config.apis.length === 2)) && checkDataDisplays}
282284
detailViewState={detailViewState}
283285
width={width}
284286
/>

0 commit comments

Comments
 (0)