Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

feat(sn-filter-pane): apply collapseMode setting #348

Merged
merged 42 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d134f86
refactor: both scenarios working somewhat ok
johanlahti Aug 31, 2023
fc66a63
refactor: cover more edge cases
johanlahti Aug 31, 2023
b0e1f6e
refactor: fix more edge-cases
johanlahti Sep 1, 2023
610cb76
fix: adjust sorting algorithm
johanlahti Sep 4, 2023
7c02a20
refactor: replicate old behaviour
johanlahti Sep 5, 2023
101fff2
Merge remote-tracking branch 'origin/main' into feat/collapse-implement
johanlahti Sep 5, 2023
1daff54
fix: new attempt to replicate failing rendering
johanlahti Sep 5, 2023
5590f2e
refactor: second attempt to replicate rendering
johanlahti Sep 5, 2023
936cf83
refactor: refactor and improve code structure
johanlahti Sep 5, 2023
0b984eb
test: fix failing test due to bad import
johanlahti Sep 5, 2023
4aa4abb
refactor: fix single grid corner case
johanlahti Sep 6, 2023
d6d4c37
fix: tiny sort alg adjustment to replicate
johanlahti Sep 8, 2023
c9593af
refactor: unit tests and cleaning
johanlahti Sep 11, 2023
7eddc7d
fix: use explicit height for last item too
johanlahti Sep 11, 2023
4dc524a
refactor: move overflowing itemCount to last
johanlahti Sep 12, 2023
5c936bf
fix: ignore for single column case
johanlahti Sep 12, 2023
841e981
fix: test lint fix
johanlahti Sep 12, 2023
53f9170
test: fix failing test due to new way of
johanlahti Sep 12, 2023
57c43c2
refactor: adapt height calculation to grid mode
johanlahti Sep 12, 2023
e44b318
fix: account for collapsed alwaysExpanded
johanlahti Sep 13, 2023
067a543
test: unit test fix
johanlahti Sep 13, 2023
38470ec
fix: check height both for collapsed and non-
johanlahti Sep 13, 2023
91257d2
refactor: invert option and new translation
johanlahti Sep 14, 2023
95bbf53
refactor: change string again
johanlahti Sep 14, 2023
4fb0517
refactor: update selections toolbar string
johanlahti Sep 15, 2023
fbc24ca
refactor: move always expanded items to overflow
johanlahti Sep 20, 2023
06f6b66
refactor: handle overflow column too big
johanlahti Sep 21, 2023
e66aa62
refactor: handle last item padding
johanlahti Sep 22, 2023
ef85b3b
refactor: bug fixes
johanlahti Sep 26, 2023
db401ea
fix: sort one more time
johanlahti Sep 27, 2023
3e3e70d
test: update rendering tests
johanlahti Sep 27, 2023
823e251
test: fix type
johanlahti Sep 27, 2023
23c4cd1
fix: use timeout to resolve race condition during
johanlahti Sep 27, 2023
75f8c57
fix: smoother resize with timeout and fix collapse
johanlahti Sep 27, 2023
3b4cde0
Merge remote-tracking branch 'origin/main' into feat/collapse-implement
johanlahti Sep 28, 2023
7b34d18
fix: rm item spacing
johanlahti Sep 28, 2023
26a167f
fix: trigger resize on non-resize events when
johanlahti Sep 29, 2023
0d57caa
test: update snapshots
johanlahti Sep 29, 2023
8acd256
Update types/global.d.ts
johanlahti Oct 2, 2023
6c1f40b
Update packages/sn-filter-pane/src/components/ListboxGrid/distribute-…
johanlahti Oct 2, 2023
29da3d9
fix: rm unused line
johanlahti Oct 2, 2023
308408b
fix: lint fixes
johanlahti Oct 3, 2023
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
4 changes: 2 additions & 2 deletions packages/sn-filter-pane/src/components/ExpandButton.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Button, Grid, styled } from '@mui/material';
import { Button, styled } from '@mui/material';
import React from 'react';
import ExpandMore from '@mui/icons-material/ExpandMore';
import { BUTTON_HEIGHT } from './ListboxGrid/distribute-resources';
import type { IStores } from '../store';
import POPOVER_CONTAINER_PADDING from './FoldedListbox/constants';
import { BUTTON_HEIGHT } from './ListboxGrid/grid-constants';

export interface FoldedListboxProps {
onClick?: (event: { event: React.MouseEvent<HTMLButtonElement> }) => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ISize } from '../../ListboxGrid/interfaces';
import POPOVER_CONTAINER_PADDING from '../../FoldedListbox/constants';
import getSizes from '../get-sizes';
import { COLLAPSED_HEIGHT } from '../../ListboxGrid/distribute-resources';
import { COLLAPSED_HEIGHT } from '../../ListboxGrid/grid-constants';

describe('getSizes', () => {
it.only('should return correct sizes for narrow-small container', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { COLLAPSED_HEIGHT } from '../ListboxGrid/distribute-resources';
import { ISize } from '../ListboxGrid/interfaces';
import POPOVER_CONTAINER_PADDING from '../FoldedListbox/constants';
import { COLLAPSED_HEIGHT } from '../ListboxGrid/grid-constants';

const getSizes = (containerSize?: ISize, isInPopover?: boolean) => {
const isNarrow = containerSize?.height !== undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ function ListboxGrid({ stores }: { stores: IStores }) {

useEffect(() => {
const firstChild = gridRef?.current?.querySelector?.('.listbox-container,.listbox-popover-container') as HTMLObjectElement;
firstChild?.setAttribute('tabIndex', '-1');
if (keyboard?.active) {
firstChild?.setAttribute('tabIndex', '-1');
firstChild?.focus();
} else {
firstChild?.setAttribute('tabIndex', '-1');
}
}, [keyboard]);

Expand All @@ -129,11 +127,10 @@ function ListboxGrid({ stores }: { stores: IStores }) {
{!!columns?.length && columns?.map((column: IColumn, i: number) => (
<ColumnGrid key={i} widthPercent={100 / columns.length}>
<Column lastColumn={!isRtl ? columns.length === i + 1 : i === 0}>

{!!column?.items?.length && column.items.map((item: IListboxResource, j: number) => (
<ColumnItem
key={item.id}
lastItem={column.items?.length === j + 1}
lastItem={column.items?.length === j + 1 && !column.hiddenItems}
listItem={item}
>
{item.expand
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
import { IListboxResource } from '../../../hooks/types';
import {
countListBoxes, doAllFit, estimateColumnHeight, getExpandedHeightLimit, getListBoxMaxHeight, getListBoxMinHeight, getMaxColumns, howManyListBoxesFit,
} from '../distribute-resources-counting';
import { ExpandProps, ISize } from '../interfaces';

const getResource = (collapseMode = 'auto') => ({
dense: false,
collapseMode: 'auto',
hasHeader: true,
neverExpanded: collapseMode === 'always',
alwaysExpanded: collapseMode === 'never',
layout: { layoutOptions: { collapseMode, dense: false } },
} as unknown as IListboxResource);

describe('distribute resources countng functions', () => {
describe('getListBoxMinHeight should return correct height for different settings', () => {
it('hasHeader: true, collapse: never, dense: false', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'never', dense: false } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(77);
});
it('hasHeader: true, collapse: never, dense: true', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'never', dense: true } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(68);
});
it('hasHeader: false, collapse: never, dense: false', () => {
const resource = { hasHeader: false, layout: { layoutOptions: { collapseMode: 'never', dense: false } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(29);
});
it('hasHeader: false, collapse: never, dense: true', () => {
const resource = { hasHeader: false, layout: { layoutOptions: { collapseMode: 'never', dense: true } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(20);
});

describe('asCollapsed == true should always return collapsed height', () => {
it('hasHeader: true, collapse: never, dense: false', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'never', dense: false } } } as IListboxResource;
expect(getListBoxMinHeight(resource, false, true)).toEqual(34);
});
it('hasHeader: true, collapse: never, dense: true', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'never', dense: true } } } as IListboxResource;
expect(getListBoxMinHeight(resource, false, true)).toEqual(34);
});
});

it('hasHeader: false, collapse: auto, dense: false', () => {
const resource = { hasHeader: false, layout: { layoutOptions: { collapseMode: 'auto', dense: false } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(34);
});
it('hasHeader: true, collapse: auto, dense: false', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'auto', dense: false } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(34);
});
it('hasHeader: true, collapse: always, dense: false', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'auto', dense: false } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(34);
});
it('hasHeader: true, collapse: always, dense: true', () => {
const resource = { hasHeader: true, layout: { layoutOptions: { collapseMode: 'auto', dense: true } } } as IListboxResource;
expect(getListBoxMinHeight(resource)).toEqual(34);
});
});

describe('getMaxColumns should behave', () => {
it('getMaxColumns -> 1', () => {
const size = {
width: 100,
height: 200,
dimensionCount: 4,
};
expect(getMaxColumns(size, false)).toEqual(1);
});
it('getMaxColumns -> 2', () => {
const size = {
width: 336,
height: 200,
dimensionCount: 4,
};
expect(getMaxColumns(size, false)).toEqual(2);
});
it('getMaxColumns with dense -> 1', () => {
const size = {
width: 336,
height: 200,
dimensionCount: 4,
};
expect(getMaxColumns(size, true)).toEqual(1);
});
it('getMaxColumns -> 2 desoute dimensionCount and height being high', () => {
const size = {
width: 336,
height: 10200,
dimensionCount: 100,
};
expect(getMaxColumns(size, false)).toEqual(2);
});
it('getMaxColumns -> 1 although size is 0', () => {
const size = {
width: 0,
height: 0,
dimensionCount: 100,
};
expect(getMaxColumns(size, false)).toEqual(1);
});
it('getMaxColumns -> 1 although size is 0', () => {
const size = {
width: 0,
height: 0,
dimensionCount: 100,
};
expect(getMaxColumns(size, true)).toEqual(1);
});
});

describe('howManyListBoxesFit should behave', () => {
it('howManyListBoxesFit - always expanded', () => {
const columnSize = {
width: 0,
height: 78,
} as ISize;
const resourcesSlice: IListboxResource[] = [getResource('never')];
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(1);
columnSize.height = 34;
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(0);
});

it('howManyListBoxesFit - always collapsed', () => {
const columnSize = {
width: 0,
height: 35,
} as ISize;
const resourcesSlice: IListboxResource[] = [getResource('always')];
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(1);
columnSize.height = 34;
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(0);
});
it('howManyListBoxesFit - auto', () => {
const columnSize = {
width: 0,
height: 35,
} as ISize;
const resourcesSlice: IListboxResource[] = [getResource('auto')];
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(1);
columnSize.height = 34;
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(0);
});
it('howManyListBoxesFit - combination', () => {
const columnSize = {
width: 0,
height: 162,
} as ISize;
const resourcesSlice: IListboxResource[] = [getResource('never'), getResource('always'), getResource('auto')];
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(3);
columnSize.height = 161;
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(3);
columnSize.height = 77;
expect(howManyListBoxesFit(columnSize, resourcesSlice)).toEqual(2);
});
});

describe('countListBoxes should count like a pro', () => {
it('should count', () => {
expect(countListBoxes([{ itemCount: 3 }, { itemCount: 2 }, { itemCount: 3 }, { itemCount: 0 }])).toEqual(8);
});
it('should not count', () => {
expect(countListBoxes([])).toEqual(0);
});
it('should not throw', () => {
expect(countListBoxes([{}])).toEqual(0);
});
});

describe('doAllFit', () => {
it('should count like a pro', () => {
expect(doAllFit(2, 2, 4)).toEqual(true);
expect(doAllFit(2, 2, 5)).toEqual(false);
expect(doAllFit(0, 2, 0)).toEqual(true);
});
});

describe('getExpandedHeightLimit', () => {
it('should be 0 when alwaysExpanded', () => {
expect(getExpandedHeightLimit({ alwaysExpanded: true } as ExpandProps)).toEqual(0);
expect(getExpandedHeightLimit({ alwaysExpanded: true, hasHeader: true } as ExpandProps)).toEqual(0);
});
it('should be 0 when isSingleGridLayout', () => {
expect(getExpandedHeightLimit({ isSingleGridLayout: true } as ExpandProps)).toEqual(0);
});
it('should account for header in isSingleGridLayout', () => {
expect(getExpandedHeightLimit({ isSingleGridLayout: true, hasHeader: true } as ExpandProps)).toEqual(80);
});
it('should return default value', () => {
expect(getExpandedHeightLimit({} as ExpandProps)).toEqual(90);
});
});

describe('getListBoxMaxHeight', () => {
it('should calculate like a pro', () => {
expect(getListBoxMaxHeight({
cardinal: 3,
dense: false,
hasHeader: true,
neverExpanded: false,
alwaysExpanded: false,
} as IListboxResource)).toEqual(135);
});
it('should calculate like a pro with dense', () => {
expect(getListBoxMaxHeight({
cardinal: 3,
dense: true,
hasHeader: true,
neverExpanded: false,
alwaysExpanded: false,
} as IListboxResource)).toEqual(108);
});
it('should account for no header', () => {
expect(getListBoxMaxHeight({
cardinal: 3,
dense: false,
hasHeader: false,
neverExpanded: false,
alwaysExpanded: false,
} as IListboxResource)).toEqual(87);
});
it('should account for alwaysExpanded', () => {
expect(getListBoxMaxHeight({
cardinal: 3,
dense: false,
hasHeader: true,
neverExpanded: false,
alwaysExpanded: true,
} as IListboxResource)).toEqual(135);
});
it('should account for neverExpanded', () => {
expect(getListBoxMaxHeight({
cardinal: 3,
dense: false,
hasHeader: true,
neverExpanded: true,
alwaysExpanded: false,
layout: {
layoutOptions: {
collapseMode: 'always',
},
},
} as IListboxResource)).toEqual(34);
});
it('should return 0 when cardinal is 0 and no header', () => {
expect(getListBoxMaxHeight({
cardinal: 0,
dense: false,
hasHeader: false,
neverExpanded: false,
alwaysExpanded: false,
layout: {
layoutOptions: {
collapseMode: 'auto',
},
},
} as IListboxResource)).toEqual(0);
});
it('should account for header when cardinal is 0', () => {
expect(getListBoxMaxHeight({
cardinal: 0,
dense: false,
hasHeader: true,
neverExpanded: false,
alwaysExpanded: false,
layout: {
layoutOptions: {
collapseMode: 'auto',
},
},
} as IListboxResource)).toEqual(48);
});
});

describe('estimateColumnHeight', () => {
it('should estimate like a wizard', () => {
expect(estimateColumnHeight({
items: [
getResource('auto'),
getResource('always'),
getResource('never'),
],
})).toEqual(171);
});

it('should only count the padding', () => {
expect(estimateColumnHeight({
items: [],
})).toEqual(2);
});
});
});
Loading
Loading