Skip to content

Commit a20770a

Browse files
authored
fix(FilterBar): disable "down" reorder btns on last row (#7040)
1 parent 5a406c3 commit a20770a

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

packages/main/src/components/FilterBar/FilterBar.cy.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ describe('FilterBar.cy.tsx', () => {
185185
cy.findAllByTestId('INPUT').should('have.length', 1);
186186
cy.findAllByTestId('SWITCH').should('have.length', 1);
187187
cy.findAllByTestId('SELECT').should('have.length', 1);
188-
189-
cy.get('[text="Filters (42)"]').click({ force: true });
188+
cy.findToolbarButtonByText('Filters (42)').click();
190189
cy.get('@openSpy').should('have.been.calledOnce');
191190
cy.get('@afterOpenSpy').should('have.been.calledOnce');
192191

@@ -650,7 +649,7 @@ describe('FilterBar.cy.tsx', () => {
650649
cy.get('[ui5-label]').eq(3).should('have.text', 'Input');
651650
cy.get('[ui5-label]').eq(4).should('have.text', 'Switch');
652651

653-
cy.get('[text="Filters"]').click({ force: true });
652+
cy.findToolbarButtonByText('Filters').click();
654653
cy.get('[ui5-dialog]').should('have.attr', 'open');
655654
cy.wait(200);
656655
cy.get('[data-text="SELECT w/ initial selected"]').as('notSelected');

packages/main/src/components/FilterBar/FilterDialog.tsx

+14-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import BarDesign from '@ui5/webcomponents/dist/types/BarDesign.js';
22
import ButtonDesign from '@ui5/webcomponents/dist/types/ButtonDesign.js';
3-
import TableSelectionMode from '@ui5/webcomponents/dist/types/TableSelectionMode.js';
43
import TitleLevel from '@ui5/webcomponents/dist/types/TitleLevel.js';
54
import group2Icon from '@ui5/webcomponents-icons/dist/group-2.js';
65
import listIcon from '@ui5/webcomponents-icons/dist/list.js';
@@ -37,7 +36,8 @@ import type {
3736
DialogDomRef,
3837
InputPropTypes,
3938
SegmentedButtonPropTypes,
40-
TableSelectionDomRef
39+
TableSelectionMultiDomRef,
40+
TableSelectionMultiPropTypes
4141
} from '../../webComponents/index.js';
4242
import {
4343
Bar,
@@ -53,7 +53,7 @@ import {
5353
Table,
5454
TableHeaderCell,
5555
TableHeaderRow,
56-
TableSelection,
56+
TableSelectionMulti,
5757
Title
5858
} from '../../webComponents/index.js';
5959
import type { FilterGroupItemInternalProps } from '../FilterGroupItem/types.js';
@@ -64,7 +64,7 @@ import type { FilterBarPropTypes } from './types.js';
6464

6565
interface ForceRequiredObject {
6666
required: string[];
67-
target: TableSelectionDomRef;
67+
target: TableSelectionMultiDomRef;
6868
selected: Set<string>;
6969
prevSelected: Set<string>;
7070
selectedKeys: Set<string>;
@@ -234,9 +234,10 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
234234
)
235235
: orderedChildren;
236236

237-
return filteredChildren.map((child, index) => {
237+
return filteredChildren.map((child, index, arr) => {
238238
return cloneElement<FilterGroupItemInternalProps>(child, {
239-
'data-index': index
239+
'data-index': index,
240+
'data-filters-count': arr.length
240241
});
241242
});
242243
};
@@ -378,9 +379,10 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
378379
}
379380
}, [selectedFilters]);
380381

381-
const handleCheckBoxChange = (e) => {
382-
if (e.target.hasAttribute('ui5-table-selection')) {
383-
const _selected: Set<string> = new Set(e.target.selected.length ? e.target.selected.split(' ') : []);
382+
const handleCheckBoxChange: TableSelectionMultiPropTypes['onChange'] = (e) => {
383+
const selectionFeature = e.target;
384+
if (selectionFeature.hasAttribute('ui5-table-selection-multi')) {
385+
const _selected: Set<string> = selectionFeature.getSelectedAsSet();
384386
const prevSelected: Set<string> = new Set(selectedFilters ?? []);
385387
const alwaysSelected = Object.keys(requiredFilters).filter((key) => requiredFilters[key]);
386388
const selectedKeys: Set<string> = _selected.symmetricDifference(prevSelected);
@@ -389,7 +391,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
389391
if (alwaysSelected.length) {
390392
setForceRequired({
391393
required: alwaysSelected,
392-
target: e.target,
394+
target: selectionFeature,
393395
selected: _selected,
394396
prevSelected,
395397
selectedKeys
@@ -443,13 +445,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
443445
className={classNames.tableInGroup}
444446
data-component-name="FilterBarDialogPanelTable"
445447
data-with-value={showValues}
446-
features={
447-
<TableSelection
448-
mode={TableSelectionMode.Multiple}
449-
selected={selected}
450-
onChange={handleCheckBoxChange}
451-
/>
452-
}
448+
features={<TableSelectionMulti selected={selected} onChange={handleCheckBoxChange} />}
453449
headerRow={
454450
<TableHeaderRow className={classNames.groupedTableHeader}>
455451
<TableHeaderCell>{filterText}</TableHeaderCell>
@@ -617,7 +613,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
617613
tabIndex={!isListView ? -1 : undefined}
618614
features={
619615
<>
620-
<TableSelection mode={TableSelectionMode.Multiple} onChange={handleCheckBoxChange} selected={selected} />
616+
<TableSelectionMulti onChange={handleCheckBoxChange} selected={selected} />
621617
</>
622618
}
623619
headerRow={

packages/main/src/components/FilterGroupItem/index.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const FilterGroupItem = forwardRef<HTMLDivElement, FilterGroupItemPropTypes & Fi
5656
} = props;
5757
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
5858
const index = props['data-index'];
59+
const filtersCount = props['data-filters-count'];
5960
const isomporphicReorderKey = isMac ? 'CMD' : 'CTRL';
6061
const tableRowRef = useRef<TableRowDomRef>(null);
6162

@@ -99,9 +100,11 @@ const FilterGroupItem = forwardRef<HTMLDivElement, FilterGroupItemPropTypes & Fi
99100

100101
useEffect(() => {
101102
if (index === 0) {
102-
// fallback
103103
setItemPosition('first');
104104
}
105+
if (index === filtersCount - 1) {
106+
setItemPosition('last');
107+
}
105108
}, [index]);
106109

107110
const handleReorder = (e: Parameters<ButtonPropTypes['onClick']>[0]) => {

packages/main/src/components/FilterGroupItem/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ export interface FilterGroupItemPropTypes extends CommonProps {
6666
active?: boolean;
6767
}
6868

69+
/**
70+
* @private
71+
*/
6972
export interface FilterGroupItemInternalProps extends FilterGroupItemPropTypes {
7073
/**
7174
* @private
7275
*/
7376
'data-index'?: number;
77+
/**
78+
* @private
79+
*/
80+
'data-filters-count'?: number;
7481
}

0 commit comments

Comments
 (0)