Skip to content

fix(FilterBar): disable "down" reorder btns on last row #7040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
5 changes: 2 additions & 3 deletions packages/main/src/components/FilterBar/FilterBar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ describe('FilterBar.cy.tsx', () => {
cy.findAllByTestId('INPUT').should('have.length', 1);
cy.findAllByTestId('SWITCH').should('have.length', 1);
cy.findAllByTestId('SELECT').should('have.length', 1);

cy.get('[text="Filters (42)"]').click({ force: true });
cy.findToolbarButtonByText('Filters (42)').click();
cy.get('@openSpy').should('have.been.calledOnce');
cy.get('@afterOpenSpy').should('have.been.calledOnce');

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

cy.get('[text="Filters"]').click({ force: true });
cy.findToolbarButtonByText('Filters').click();
cy.get('[ui5-dialog]').should('have.attr', 'open');
cy.wait(200);
cy.get('[data-text="SELECT w/ initial selected"]').as('notSelected');
Expand Down
32 changes: 14 additions & 18 deletions packages/main/src/components/FilterBar/FilterDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import BarDesign from '@ui5/webcomponents/dist/types/BarDesign.js';
import ButtonDesign from '@ui5/webcomponents/dist/types/ButtonDesign.js';
import TableSelectionMode from '@ui5/webcomponents/dist/types/TableSelectionMode.js';
import TitleLevel from '@ui5/webcomponents/dist/types/TitleLevel.js';
import group2Icon from '@ui5/webcomponents-icons/dist/group-2.js';
import listIcon from '@ui5/webcomponents-icons/dist/list.js';
Expand Down Expand Up @@ -37,7 +36,8 @@ import type {
DialogDomRef,
InputPropTypes,
SegmentedButtonPropTypes,
TableSelectionDomRef
TableSelectionMultiDomRef,
TableSelectionMultiPropTypes
} from '../../webComponents/index.js';
import {
Bar,
Expand All @@ -53,7 +53,7 @@ import {
Table,
TableHeaderCell,
TableHeaderRow,
TableSelection,
TableSelectionMulti,
Title
} from '../../webComponents/index.js';
import type { FilterGroupItemInternalProps } from '../FilterGroupItem/types.js';
Expand All @@ -64,7 +64,7 @@ import type { FilterBarPropTypes } from './types.js';

interface ForceRequiredObject {
required: string[];
target: TableSelectionDomRef;
target: TableSelectionMultiDomRef;
selected: Set<string>;
prevSelected: Set<string>;
selectedKeys: Set<string>;
Expand Down Expand Up @@ -234,9 +234,10 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
)
: orderedChildren;

return filteredChildren.map((child, index) => {
return filteredChildren.map((child, index, arr) => {
return cloneElement<FilterGroupItemInternalProps>(child, {
'data-index': index
'data-index': index,
'data-filters-count': arr.length
});
});
};
Expand Down Expand Up @@ -378,9 +379,10 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
}
}, [selectedFilters]);

const handleCheckBoxChange = (e) => {
if (e.target.hasAttribute('ui5-table-selection')) {
const _selected: Set<string> = new Set(e.target.selected.length ? e.target.selected.split(' ') : []);
const handleCheckBoxChange: TableSelectionMultiPropTypes['onChange'] = (e) => {
const selectionFeature = e.target;
if (selectionFeature.hasAttribute('ui5-table-selection-multi')) {
const _selected: Set<string> = selectionFeature.getSelectedAsSet();
const prevSelected: Set<string> = new Set(selectedFilters ?? []);
const alwaysSelected = Object.keys(requiredFilters).filter((key) => requiredFilters[key]);
const selectedKeys: Set<string> = _selected.symmetricDifference(prevSelected);
Expand All @@ -389,7 +391,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
if (alwaysSelected.length) {
setForceRequired({
required: alwaysSelected,
target: e.target,
target: selectionFeature,
selected: _selected,
prevSelected,
selectedKeys
Expand Down Expand Up @@ -443,13 +445,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
className={classNames.tableInGroup}
data-component-name="FilterBarDialogPanelTable"
data-with-value={showValues}
features={
<TableSelection
mode={TableSelectionMode.Multiple}
selected={selected}
onChange={handleCheckBoxChange}
/>
}
features={<TableSelectionMulti selected={selected} onChange={handleCheckBoxChange} />}
headerRow={
<TableHeaderRow className={classNames.groupedTableHeader}>
<TableHeaderCell>{filterText}</TableHeaderCell>
Expand Down Expand Up @@ -617,7 +613,7 @@ export const FilterDialog = (props: FilterDialogPropTypes) => {
tabIndex={!isListView ? -1 : undefined}
features={
<>
<TableSelection mode={TableSelectionMode.Multiple} onChange={handleCheckBoxChange} selected={selected} />
<TableSelectionMulti onChange={handleCheckBoxChange} selected={selected} />
</>
}
headerRow={
Expand Down
5 changes: 4 additions & 1 deletion packages/main/src/components/FilterGroupItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const FilterGroupItem = forwardRef<HTMLDivElement, FilterGroupItemPropTypes & Fi
} = props;
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
const index = props['data-index'];
const filtersCount = props['data-filters-count'];
const isomporphicReorderKey = isMac ? 'CMD' : 'CTRL';
const tableRowRef = useRef<TableRowDomRef>(null);

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

useEffect(() => {
if (index === 0) {
// fallback
setItemPosition('first');
}
if (index === filtersCount - 1) {
setItemPosition('last');
}
}, [index]);

const handleReorder = (e: Parameters<ButtonPropTypes['onClick']>[0]) => {
Expand Down
7 changes: 7 additions & 0 deletions packages/main/src/components/FilterGroupItem/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,16 @@ export interface FilterGroupItemPropTypes extends CommonProps {
active?: boolean;
}

/**
* @private
*/
export interface FilterGroupItemInternalProps extends FilterGroupItemPropTypes {
/**
* @private
*/
'data-index'?: number;
/**
* @private
*/
'data-filters-count'?: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
margin-block-end: 0.25rem;
background-color: var(--sapObjectHeader_Background);
display: grid;
grid-auto-columns: min-content calc(100% - 5rem - 2rem);

&:has([data-component-name='ObjectPageHeaderImage']) {
grid-auto-columns: min-content calc(100% - 5rem - 2rem);
}

[data-component-name='ObjectPageHeaderContent'] {
grid-column: 2;
Expand Down
6 changes: 4 additions & 2 deletions packages/main/src/components/ObjectPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,19 @@ const ObjectPage = forwardRef<ObjectPageDomRef, ObjectPagePropTypes>((props, ref
<span
className={classNames.headerImage}
style={{ borderRadius: imageShapeCircle ? '50%' : 0, overflow: 'hidden' }}
data-component-name="ObjectPageHeaderImage"
>
<img src={image} className={classNames.image} alt="Company Logo" />
</span>
);
} else {
return cloneElement(image, {
size: AvatarSize.L,
className: clsx(classNames.headerImage, image.props?.className)
className: clsx(classNames.headerImage, image.props?.className),
'data-component-name': 'ObjectPageHeaderImage'
} as AvatarPropTypes);
}
}, [image, classNames.headerImage, classNames.image, imageShapeCircle]);
}, [image, imageShapeCircle]);

const scrollToSectionById = (id: string | undefined, isSubSection = false) => {
const section = getSectionElementById(objectPageRef.current, isSubSection, id);
Expand Down
Loading