Skip to content

Commit babb38e

Browse files
iobuhovgjulivan
authored andcommitted
feat: dropdown filter caption expressions
1 parent 0ce5e87 commit babb38e

File tree

4 files changed

+80
-18
lines changed

4 files changed

+80
-18
lines changed

packages/pluggableWidgets/datagrid-dropdown-filter-web/src/DatagridDropdownFilter.editorConfig.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ export function getProperties(values: DatagridDropdownFilterPreviewProps, defaul
2424
hidePropertyIn(defaultProperties, values, "emptyOptionCaption");
2525
}
2626

27+
if (!values.filterable) {
28+
hidePropertyIn(defaultProperties, values, "refSearchAttr");
29+
}
30+
31+
if (values.refCaptionSource === "attr") {
32+
hidePropertiesIn(defaultProperties, values, ["refCaptionExp", "refSearchAttr"]);
33+
} else {
34+
hidePropertyIn(defaultProperties, values, "refCaption");
35+
}
36+
2737
if (!showSelectedItemsStyle) {
2838
hidePropertyIn(defaultProperties, values, "selectedItemsStyle");
2939
}
@@ -36,7 +46,15 @@ export function getProperties(values: DatagridDropdownFilterPreviewProps, defaul
3646
}
3747

3848
function attrGroupProperties(values: DatagridDropdownFilterPreviewProps, defaultProperties: Properties): Properties {
39-
hidePropertiesIn(defaultProperties, values, ["refEntity", "refOptions", "refCaption", "fetchOptionsLazy"]);
49+
hidePropertiesIn(defaultProperties, values, [
50+
"fetchOptionsLazy",
51+
"refCaption",
52+
"refCaptionExp",
53+
"refCaptionSource",
54+
"refEntity",
55+
"refOptions",
56+
"refSearchAttr"
57+
]);
4058

4159
if (values.attrChoice === "auto") {
4260
hidePropertyIn(defaultProperties, {} as { linkedDs: unknown }, "linkedDs");

packages/pluggableWidgets/datagrid-dropdown-filter-web/src/DatagridDropdownFilter.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,33 @@
7474
<caption>Selectable objects</caption>
7575
<description>The options to show in the Drop-down filter widget.</description>
7676
</property>
77+
<property key="refCaptionSource" type="enumeration" defaultValue="attr">
78+
<caption>Caption source</caption>
79+
<description />
80+
<enumerationValues>
81+
<enumerationValue key="attr">Attribute</enumerationValue>
82+
<enumerationValue key="exp">Expression</enumerationValue>
83+
</enumerationValues>
84+
</property>
7785
<property key="refCaption" type="attribute" dataSource="refOptions" required="false">
7886
<caption>Caption</caption>
7987
<description />
8088
<attributeTypes>
8189
<attributeType name="String" />
8290
</attributeTypes>
8391
</property>
92+
<property key="refCaptionExp" type="expression" dataSource="refOptions" required="false">
93+
<caption>Caption</caption>
94+
<description />
95+
<returnType type="String" />
96+
</property>
97+
<property key="refSearchAttr" type="attribute" dataSource="refOptions" required="true">
98+
<caption>Search attribute</caption>
99+
<description>Required when Filterable is set to yes</description>
100+
<attributeTypes>
101+
<attributeType name="String" />
102+
</attributeTypes>
103+
</property>
84104
<property key="fetchOptionsLazy" type="boolean" defaultValue="false">
85105
<caption>Use lazy load</caption>
86106
<description>Lazy loading enables faster parent loading, but with personalization enabled, value restoration will be limited.</description>

packages/pluggableWidgets/datagrid-dropdown-filter-web/src/hocs/withLinkedRefStore.tsx

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
import { useEffect, createElement } from "react";
21
import { Alert } from "@mendix/widget-plugin-component-kit/Alert";
32
import { RefFilterStore } from "@mendix/widget-plugin-dropdown-filter/stores/RefFilterStore";
43
import { FilterAPI, useFilterAPI } from "@mendix/widget-plugin-filtering/context";
54
import { BaseStoreProvider } from "@mendix/widget-plugin-filtering/custom-filter-api/BaseStoreProvider";
6-
import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate";
75
import { GateProvider } from "@mendix/widget-plugin-mobx-kit/GateProvider";
6+
import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate";
87
import { useConst } from "@mendix/widget-plugin-mobx-kit/react/useConst";
9-
import { ListValue, ListAttributeValue, AssociationMetaData } from "mendix";
10-
import { DatagridDropdownFilterContainerProps } from "../../typings/DatagridDropdownFilterProps";
118
import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup";
9+
import { AssociationMetaData, ListAttributeValue, ListExpressionValue, ListValue } from "mendix";
10+
import { createElement, useEffect } from "react";
11+
import { DatagridDropdownFilterContainerProps } from "../../typings/DatagridDropdownFilterProps";
1212
import { RefFilterProps } from "../components/typings";
1313

14-
type WidgetProps = Pick<DatagridDropdownFilterContainerProps, "name" | "refEntity" | "refOptions" | "refCaption">;
14+
type WidgetProps = Pick<
15+
DatagridDropdownFilterContainerProps,
16+
"name" | "refEntity" | "refOptions" | "refCaption" | "refCaptionExp" | "refCaptionSource" | "refSearchAttr"
17+
>;
1518

1619
export interface RequiredProps {
1720
name: string;
1821
refEntity: AssociationMetaData;
1922
refOptions: ListValue;
20-
refCaption: ListAttributeValue<string>;
21-
searchAttrId: ListAttributeValue["id"];
23+
refCaption: ListAttributeValue<string> | ListExpressionValue<string>;
24+
searchAttrId?: ListAttributeValue["id"];
2225
}
2326

2427
type Component<P extends object> = (props: P) => React.ReactElement;
@@ -49,16 +52,29 @@ function mapProps(props: WidgetProps): RequiredProps {
4952
throw new Error("RefFilterStoreProvider: refOptions is required");
5053
}
5154

52-
if (!props.refCaption) {
53-
throw new Error("RefFilterStoreProvider: refCaption is required");
55+
if (props.refCaptionSource === "attr") {
56+
if (!props.refCaption) {
57+
throw new Error("RefFilterStoreProvider: 'Caption' settings is required");
58+
}
59+
return {
60+
name: props.name,
61+
refEntity: props.refEntity,
62+
refOptions: props.refOptions,
63+
refCaption: props.refCaption,
64+
searchAttrId: props.refCaption.id
65+
};
66+
} else {
67+
if (!props.refCaptionExp) {
68+
throw new Error("RefFilterStoreProvider: 'Caption' settings is required");
69+
}
70+
return {
71+
name: props.name,
72+
refEntity: props.refEntity,
73+
refOptions: props.refOptions,
74+
refCaption: props.refCaptionExp,
75+
searchAttrId: props.refSearchAttr?.id
76+
};
5477
}
55-
return {
56-
name: props.name,
57-
refEntity: props.refEntity,
58-
refOptions: props.refOptions,
59-
refCaption: props.refCaption,
60-
searchAttrId: props.refCaption.id
61-
};
6278
}
6379

6480
function useGate(props: WidgetProps): DerivedPropsGate<RequiredProps> {

packages/pluggableWidgets/datagrid-dropdown-filter-web/typings/DatagridDropdownFilterProps.d.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author Mendix Widgets Framework Team
55
*/
66
import { CSSProperties } from "react";
7-
import { ActionValue, AssociationMetaData, AttributeMetaData, DynamicValue, EditableValue, ListValue, ListAttributeValue } from "mendix";
7+
import { ActionValue, AssociationMetaData, AttributeMetaData, DynamicValue, EditableValue, ListValue, ListAttributeValue, ListExpressionValue } from "mendix";
88

99
export type BaseTypeEnum = "attr" | "ref";
1010

@@ -15,6 +15,8 @@ export interface FilterOptionsType {
1515
value: DynamicValue<string>;
1616
}
1717

18+
export type RefCaptionSourceEnum = "attr" | "exp";
19+
1820
export type SelectedItemsStyleEnum = "text" | "boxes";
1921

2022
export type SelectionMethodEnum = "checkbox" | "rowClick";
@@ -36,7 +38,10 @@ export interface DatagridDropdownFilterContainerProps {
3638
filterOptions: FilterOptionsType[];
3739
refEntity: AssociationMetaData;
3840
refOptions?: ListValue;
41+
refCaptionSource: RefCaptionSourceEnum;
3942
refCaption?: ListAttributeValue<string>;
43+
refCaptionExp?: ListExpressionValue<string>;
44+
refSearchAttr?: ListAttributeValue<string>;
4045
fetchOptionsLazy: boolean;
4146
defaultValue?: DynamicValue<string>;
4247
filterable: boolean;
@@ -68,7 +73,10 @@ export interface DatagridDropdownFilterPreviewProps {
6873
filterOptions: FilterOptionsPreviewType[];
6974
refEntity: string;
7075
refOptions: {} | { caption: string } | { type: string } | null;
76+
refCaptionSource: RefCaptionSourceEnum;
7177
refCaption: string;
78+
refCaptionExp: string;
79+
refSearchAttr: string;
7280
fetchOptionsLazy: boolean;
7381
defaultValue: string;
7482
filterable: boolean;

0 commit comments

Comments
 (0)