Skip to content
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

fix(platform): table filter enhancement #12771

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5967ae8
feat(core):
khotcholava Nov 19, 2024
3f135e0
feat(core):
khotcholava Nov 25, 2024
c11dc19
Merge branch 'main' into 11783-table-filter-enhancement
khotcholava Nov 27, 2024
34e1581
feat(platform): table filter enhancement
khotcholava Nov 29, 2024
5c3ed1f
feat(platform): table filter enhancement
khotcholava Nov 29, 2024
c1c7ab0
feat(platform): table filter enhancement
khotcholava Nov 29, 2024
20f6e29
feat(platform): table filter enhancement
khotcholava Nov 29, 2024
a0d9d35
feat(platform): table filter enhancement
khotcholava Dec 4, 2024
748ed9e
fix(table): table filter toolbar
khotcholava Dec 9, 2024
117f058
fix(table): table filter toolbar
khotcholava Dec 11, 2024
1db00cb
fix(table): table filter toolbar
khotcholava Dec 11, 2024
4a08c25
fix(platform): table filter toolbar
khotcholava Dec 11, 2024
eb5d57b
fix(platform): table filter toolbar
khotcholava Dec 17, 2024
14898cc
Merge branch 'main' into 11783-table-filter-enhancement
khotcholava Dec 17, 2024
14e05c4
fix(platform): table filter toolbar
khotcholava Dec 11, 2024
68df50b
fix(platform): table filter toolbar
khotcholava Dec 11, 2024
dc43d8b
fix(platform): table filter toolbar
khotcholava Dec 17, 2024
f6698e9
fix(platform): remove emtpy tab in dynamic page with tabs (#12786)
droshev Nov 28, 2024
526bfb9
chore(release): publish 0.53.2-rc.14 [ci skip]
fundamental-bot Nov 28, 2024
01d40af
fix(platform): table spanning (#12783)
khotcholava Nov 28, 2024
e98c01e
chore(release): publish 0.53.2-rc.15 [ci skip]
fundamental-bot Nov 29, 2024
0ebc249
fix(docs): extra scrollbar track showing on docs page for chrome (#12…
CondensedMilk7 Dec 2, 2024
8102ed2
chore(release): publish 0.53.2-rc.16 [ci skip]
fundamental-bot Dec 2, 2024
24ecf26
fix(platform): update Load More label with Show More (#12806)
droshev Dec 2, 2024
8522e37
chore(release): publish 0.53.2-rc.17 [ci skip]
fundamental-bot Dec 2, 2024
5a4c438
fix(platform): update settings generator docs and component to update…
mikerodonnell89 Dec 3, 2024
972b92a
chore(release): publish 0.53.2-rc.18 [ci skip]
fundamental-bot Dec 3, 2024
15b50be
chore(release): publish 0.53.2 [ci skip]
fundamental-bot Dec 3, 2024
280d7a8
fix(core, platform): fix illustrated message in table (#12689)
droshev Dec 3, 2024
fdfe4e1
chore(release): publish 0.54.0-rc.0 [ci skip]
fundamental-bot Dec 3, 2024
89bf0ac
fix(core): fix form field spacing (#12819)
droshev Dec 9, 2024
2557145
chore(release): publish 0.54.0-rc.1 [ci skip]
fundamental-bot Dec 9, 2024
d6f76b6
chore: remove notworking workflow (#12830)
droshev Dec 9, 2024
5f1c23f
chore(release): publish 0.54.0-rc.2 [ci skip]
fundamental-bot Dec 9, 2024
c069e10
chore(release): publish 0.54.0 [ci skip]
fundamental-bot Dec 10, 2024
221e252
Merge remote-tracking branch 'origin/11783-table-filter-enhancement' …
khotcholava Dec 19, 2024
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
3 changes: 3 additions & 0 deletions libs/core/toolbar/toolbar.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
flex-shrink: 0;
}

.fd-toolbar--no-shrink > * {
flex-shrink: 1;
}
fdk-dynamic-portal {
&:not(:last-of-type) {
[fd-toolbar-item] {
Expand Down
5 changes: 5 additions & 0 deletions libs/core/toolbar/toolbar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla
@Input()
fdType: ToolbarType = 'solid';

/** Determines if toolbar should be shrunk */
@Input()
noShrink = false;

/** The title for the toolbar. */
@Input()
title: string;
Expand Down Expand Up @@ -247,6 +251,7 @@ export class ToolbarComponent implements AfterViewInit, AfterViewChecked, CssCla
buildComponentCssClass(): string[] {
return [
'fd-toolbar',
`${this.noShrink ? 'fd-toolbar--no-shrink' : ''}`,
`fd-toolbar--${this.fdType}`,
`${this.active && this.fdType === 'info' ? 'fd-toolbar--active' : ''}`,
`${this.title || this.titleComponent ? 'fd-toolbar--title' : ''}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface BaseCollectionFilter<T> {
value2?: Nullable<T>;
exclude?: boolean;
strategy?: FilterStrategy;
fieldName?: string;
}
export interface CollectionStringFilter extends BaseCollectionFilter<string> {
strategy: FilterStringStrategy;
Expand Down
2 changes: 1 addition & 1 deletion libs/platform/table-helpers/services/table.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('TableServiceService', () => {
const setTableStateSpy = jest.spyOn(service, 'setTableState');
const filterChangeSpy = jest.spyOn(service.filterChange$, 'next');
const newFilterBy: CollectionStringFilter[] = [
{ field: 'name', value: 'Product name', strategy: FILTER_STRING_STRATEGY.CONTAINS }
{ field: 'name', value: 'Product name', fieldName: 'name', strategy: FILTER_STRING_STRATEGY.CONTAINS }
];
const newState: TableState = { ...DEFAULT_TABLE_STATE, filterBy: newFilterBy };
const event: FilterChange = { current: newFilterBy, previous: DEFAULT_TABLE_STATE.filterBy };
Expand Down
31 changes: 25 additions & 6 deletions libs/platform/table-helpers/services/table.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { skip } from 'rxjs/operators';
import { DEFAULT_TABLE_STATE } from '../constants';

import { toSignal } from '@angular/core/rxjs-interop';
import { Nullable } from '@fundamental-ngx/cdk/utils';
import { CollectionFilter, CollectionGroup, CollectionPage, CollectionSort, TableState } from '../interfaces';
import {
ColumnsChange,
Expand Down Expand Up @@ -188,7 +189,12 @@ export class TableService {
const prevState = this.getTableState();
const prevFilterRules = (prevState && prevState.filterBy) || [];

const newFilterRules: CollectionFilter[] = filterRules ? [...filterRules] : [];
const newFilterRules: CollectionFilter[] = filterRules
? filterRules.map((rule) => ({
...rule,
fieldName: this._getFieldName(rule.field, rule.fieldName)
}))
: [];
const state: TableState = { ...prevState, filterBy: newFilterRules };

if (!equal(prevFilterRules, state.filterBy)) {
Expand All @@ -209,9 +215,11 @@ export class TableService {

const newFilterRules: CollectionFilter[] = [
...prevFilterRules.filter((existing) => !rulesToAdd.find(({ field }) => field === existing.field)),
...rulesToAdd
...rulesToAdd.map((rule) => ({
...rule,
fieldName: this._getFieldName(rule.field, rule.fieldName)
}))
];

const state: TableState = { ...prevState, filterBy: newFilterRules };

if (!equal(prevFilterRules, state.filterBy)) {
Expand Down Expand Up @@ -426,10 +434,13 @@ export class TableService {
* @param state Table state.
*/
buildFilterRulesMap(state = this.getTableState()): void {
const prevState = this.getTableState();
const evt = { current: state.filterBy, previous: prevState.filterBy };
const filterRulesWithFieldNames = state.filterBy.map((rule) => ({
...rule,
fieldName: this._getFieldName(rule.field, rule.fieldName)
}));

this.filterRules$.set(
state.filterBy.reduce((hash, rule) => {
filterRulesWithFieldNames.reduce((hash, rule) => {
const key = rule.field;
if (!hash.has(key)) {
hash.set(key, []);
Expand All @@ -438,6 +449,8 @@ export class TableService {
return hash;
}, new Map<string, CollectionFilter[]>())
);

const evt = { current: filterRulesWithFieldNames, previous: state.filterBy };
this.stateChange$.next({ type: 'filter', state: evt });
}

Expand Down Expand Up @@ -468,6 +481,12 @@ export class TableService {
this.buildSortRulesMap();
this.buildFilterRulesMap();
}

/** @hidden */
private _getFieldName(field: string, fieldName: Nullable<string>): string {
const column = this.tableColumns$.getValue().find((col) => col.key === field);
return column ? column.name : fieldName ?? field;
}
}

/** @hidden */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
</fd-toolbar>
@if (appliedFilters().length) {
<fd-toolbar
[noShrink]="true"
fdType="info"
[active]="true"
[titleId]="tableToolbarTitleId"
Expand All @@ -168,12 +169,7 @@
>
<label fd-toolbar-label>
{{ 'platformTable.filteredBy' | fdTranslate }}:
@for (filter of appliedFilters(); track filter.columnName; let i = $index) {
{{ filter.columnName }} ({{ filter.params }})
@if (i < appliedFilters().length - 1) {
,
}
}
{{ _formatAppliedFilters(appliedFilters()) }}
</label>
<fd-toolbar-spacer></fd-toolbar-spacer>
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ export class TableToolbarComponent implements TableToolbarInterface {
this._table.cancelEditing();
}

/** @hidden */
_formatAppliedFilters(appliedFilters: { columnName: string; params: string }[]): string {
return appliedFilters
.map((filter, index) => {
const separator = index < appliedFilters.length - 1 ? ', ' : '';
return `${filter.columnName} (${filter.params})${separator}`;
})
.join('');
}

/** @hidden */
_expandAll(): void {
this._table.expandAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class FilterStepComponent implements FiltersViewStep {
@Input()
columnKey: string;

/** Column name to display in the filter */
@Input()
columnName: string;

/** Table's content density to be used */
@Input()
contentDensity: ContentDensity;
Expand Down Expand Up @@ -91,6 +95,7 @@ export class FilterStepComponent implements FiltersViewStep {
_onFilterValueChange(filterValue: any): void {
const filterBy: CollectionFilter = this._filterBy || {
field: this.columnKey,
fieldName: this.columnName,
value: null,
strategy: FILTER_STRATEGY.EQ,
exclude: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
} @else if (activeStep === ACTIVE_STEP.FILTER) {
<fdp-filter-step
[columnKey]="activeFilterColumnKey!"
[columnName]="activeFilter!.label"
[filter]="activeFilter!"
[filterBy]="filterBy"
(back)="goToFilters()"
Expand Down
7 changes: 6 additions & 1 deletion libs/platform/table/table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ export class TableComponent<T = any>
/** @hidden */
private _setAppliedFilterNames(filters: CollectionFilter[]): void {
const formattedFilters = filters.map((f) => ({
columnName: this._formatColumnName(f.field),
columnName: this._formatColumnName(f.fieldName || ''),
params: this._formatParams(f.value)
}));

Expand All @@ -1875,6 +1875,11 @@ export class TableComponent<T = any>
return String(value); // Handle non-object values
}

// handle array
if (Array.isArray(value)) {
return value.map((val) => this._formatParams(val)).join(', ');
}

return Object.entries(value)
.map(([key, val]) => `${key}: ${this._formatParams(val)}`) // Recursive call for nested objects
.join(', ');
Expand Down
2 changes: 1 addition & 1 deletion libs/platform/table/tests/table.component-host.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ describe('TableComponent Host', () => {
describe('data source', () => {
it('fetch should be triggered when call table.filter()', () => {
const filterBy: CollectionFilter[] = [
{ field: 'status', value: 'valid', strategy: 'equalTo', exclude: false }
{ field: 'status', value: 'valid', strategy: 'equalTo', fieldName: 'status', exclude: false }
];

tableComponent.filter(filterBy);
Expand Down
Loading