Skip to content

Commit

Permalink
feat(datagrid-web): control column filters values and operators
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelreichert committed Dec 20, 2024
1 parent c06713f commit 0be971b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/pluggableWidgets/datagrid-web/src/Datagrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Container = observer((props: Props): ReactElement => {
onClickTrigger: props.onClickTrigger,
onClick: props.onClick
});
useOnResetFiltersEvent(props.rootStore.staticInfo.name, props.rootStore.staticInfo.filtersChannelName);
useOnResetFiltersEvent(rootStore.staticInfo.name, rootStore.staticInfo.filtersChannelName);

const visibleColumnsCount = selectActionHelper.showCheckboxColumn
? columnsStore.visibleColumns.length + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ describe("Datagrid", () => {
filterList: [],
configurationStorageType: "attribute",
configurationAttribute: undefined,
loadingType: "spinner"
loadingType: "spinner",
storeFilterValues: true,
storeOperatorValues: true
};
const user = userEvent.setup();
let renderCount = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class ColumnGroupStore implements IColumnGroupStore, IColumnParentStore {
isResizing: boolean = false;

constructor(
props: Pick<DatagridContainerProps, "columns" | "datasource">,
props: Pick<DatagridContainerProps, "columns" | "datasource" | "storeFilterValues" | "storeOperatorValues">,
info: StaticInfo,
dsViewState: Array<FilterCondition | undefined> | null
) {
Expand All @@ -55,7 +55,13 @@ export class ColumnGroupStore implements IColumnGroupStore, IColumnParentStore {
const column = new ColumnStore(i, columnProps, this);
this._allColumnsById.set(column.columnId, column);
this._allColumns[i] = column;
this.columnFilters[i] = new ColumnFilterStore(columnProps, info, initCond);
this.columnFilters[i] = new ColumnFilterStore(
columnProps,
info,
initCond,
props.storeFilterValues,
props.storeOperatorValues
);
});

this.sorting = new ColumnsSortingStore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ export class ColumnFilterStore implements IColumnFilterStore {
private _widget: ReactNode;
private _filterStore: FilterStore | null = null;
private _context: FilterAPIv2;

constructor(props: ColumnsType, info: StaticInfo, dsViewState: FilterCondition | null) {
private storeFilterValue: boolean;
private storeOperatorValue: boolean;

constructor(
props: ColumnsType,
info: StaticInfo,
dsViewState: FilterCondition | null,
storeFilterValue: boolean,
storeOperatorValue: boolean
) {
this._widget = props.filter;
this._filterStore = this.createFilterStore(props, dsViewState);
this._context = this.createContext(this._filterStore, info);
this.storeFilterValue = storeFilterValue;
this.storeOperatorValue = storeOperatorValue;

makeObservable<this, "_updateStore">(this, {
_updateStore: action,
Expand Down Expand Up @@ -96,7 +106,29 @@ export class ColumnFilterStore implements IColumnFilterStore {
}

get settings(): FilterData | undefined {
return this._filterStore?.toJSON();
switch (this._filterStore?.type) {
case "date":
case "number":
case "string":
const settings = this._filterStore?.toJSON();
if (settings && !this.storeOperatorValue) {
settings[0] = this._filterStore?.defaultState[0];
}

if (settings && !this.storeFilterValue) {
settings[1] = null;
settings[2] = null;
}
return settings;
case "refselect":
case "select":
if (!this.storeFilterValue) {
return [];
}
return this._filterStore?.toJSON();
default:
return undefined;
}
}

set settings(data: FilterData | undefined) {
Expand Down

0 comments on commit 0be971b

Please sign in to comment.