Skip to content

Commit

Permalink
feat(datagrid-web): control over stored string filter
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelreichert committed Dec 19, 2024
1 parent f98e82f commit 0b4c05e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 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
18 changes: 14 additions & 4 deletions packages/shared/widget-plugin-filtering/src/providers/LegacyPv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ export class LegacyPv implements LegacyProvider {
filterMap: FilterMap;
filterList: FilterList;

constructor(attrs: ListAttributeValue[], dsViewState: Array<FilterCondition | undefined> | null) {
constructor(
attrs: ListAttributeValue[],
dsViewState: Array<FilterCondition | undefined> | null,
storeFilterValues: boolean,
storeOperatorValues: boolean
) {
this._attrs = attrs;
const map = (this.filterMap = createMap(attrs, dsViewState));
const map = (this.filterMap = createMap(attrs, dsViewState, storeFilterValues, storeOperatorValues));
this.filterList = [map[Ft.STRING], map[Ft.NUMBER], map[Ft.DATE], map[Ft.ENUMERATION]];
makeObservable<this, "_attrs">(this, {
_attrs: observable.ref,
Expand Down Expand Up @@ -90,12 +95,17 @@ export class LegacyPv implements LegacyProvider {
}
}

function createMap(attrs: ListAttributeValue[], dsViewState: Array<FilterCondition | undefined> | null): FilterMap {
function createMap(
attrs: ListAttributeValue[],
dsViewState: Array<FilterCondition | undefined> | null,
filter: boolean,
operator: boolean
): FilterMap {
const [ini1 = null, ini2 = null, ini3 = null, ini4 = null] = dsViewState ?? [];
const [str, num, dte, enm] = groupByType(attrs);

const r: FilterMap = {
[Ft.STRING]: str.length > 0 ? new StringInputFilterStore(str, ini1) : null,
[Ft.STRING]: str.length > 0 ? new StringInputFilterStore(str, ini1, filter, operator) : null,
[Ft.NUMBER]: num.length > 0 ? new NumberInputFilterStore(num, ini2) : null,
[Ft.DATE]: dte.length > 0 ? new DateInputFilterStore(dte, ini3) : null,
[Ft.ENUMERATION]: enm.length > 0 ? new StaticSelectFilterStore(enm, ini4) : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface FilterListType {
export interface HeaderFiltersStoreProps {
filterList: FilterListType[];
parentChannelName?: string;
storeFilterValues: boolean;
storeOperatorValues: boolean;
}

export interface StaticInfo {
Expand All @@ -24,7 +26,6 @@ export interface StaticInfo {
export class HeaderFiltersStore {
private provider: Result<LegacyPv, APIError>;
context: FilterAPIv2;

constructor(
props: HeaderFiltersStoreProps,
info: StaticInfo,
Expand Down Expand Up @@ -65,7 +66,9 @@ export class HeaderFiltersStore {
return value(
new LegacyPv(
props.filterList.map(f => f.filter),
dsViewState
dsViewState,
props.storeFilterValues,
props.storeOperatorValues
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export class StringInputFilterStore
{
readonly storeType = "input";
readonly type = "string";
private storeFilterValue: boolean;
private storeOperatorValue: boolean;

constructor(attributes: Array<ListAttributeValue<string>>, initCond: FilterCondition | null) {
constructor(
attributes: Array<ListAttributeValue<string>>,
initCond: FilterCondition | null,
filter: boolean,
operator: boolean
) {
const { formatter } = attributes[0];
super(new StringArgument(formatter), new StringArgument(formatter), "equal", attributes);
makeObservable(this, {
Expand All @@ -33,6 +40,8 @@ export class StringInputFilterStore
if (initCond) {
this.fromViewState(initCond);
}
this.storeFilterValue = filter;
this.storeOperatorValue = operator;
}

updateProps(attributes: ListAttributeValue[]): void {
Expand All @@ -45,7 +54,11 @@ export class StringInputFilterStore
}

toJSON(): InputData {
return [this.filterFunction, this.arg1.value ?? null, this.arg2.value ?? null];
return [
this.storeOperatorValue ? this.filterFunction : this.defaultState[0],
this.storeFilterValue ? this.arg1.value ?? null : null,
this.storeFilterValue ? this.arg2.value ?? null : null
];
}

fromJSON(data: FilterData): void {
Expand Down

0 comments on commit 0b4c05e

Please sign in to comment.