|
1 |
| -import { useEffect, createElement } from "react"; |
2 | 1 | import { Alert } from "@mendix/widget-plugin-component-kit/Alert";
|
3 | 2 | import { RefFilterStore } from "@mendix/widget-plugin-dropdown-filter/stores/RefFilterStore";
|
4 | 3 | import { FilterAPI, useFilterAPI } from "@mendix/widget-plugin-filtering/context";
|
5 | 4 | import { BaseStoreProvider } from "@mendix/widget-plugin-filtering/custom-filter-api/BaseStoreProvider";
|
6 |
| -import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate"; |
7 | 5 | import { GateProvider } from "@mendix/widget-plugin-mobx-kit/GateProvider";
|
| 6 | +import { DerivedPropsGate } from "@mendix/widget-plugin-mobx-kit/props-gate"; |
8 | 7 | import { useConst } from "@mendix/widget-plugin-mobx-kit/react/useConst";
|
9 |
| -import { ListValue, ListAttributeValue, AssociationMetaData } from "mendix"; |
10 |
| -import { DatagridDropdownFilterContainerProps } from "../../typings/DatagridDropdownFilterProps"; |
11 | 8 | 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"; |
12 | 12 | import { RefFilterProps } from "../components/typings";
|
13 | 13 |
|
14 |
| -type WidgetProps = Pick<DatagridDropdownFilterContainerProps, "name" | "refEntity" | "refOptions" | "refCaption">; |
| 14 | +type WidgetProps = Pick< |
| 15 | + DatagridDropdownFilterContainerProps, |
| 16 | + "name" | "refEntity" | "refOptions" | "refCaption" | "refCaptionExp" | "refCaptionSource" | "refSearchAttr" |
| 17 | +>; |
15 | 18 |
|
16 | 19 | export interface RequiredProps {
|
17 | 20 | name: string;
|
18 | 21 | refEntity: AssociationMetaData;
|
19 | 22 | refOptions: ListValue;
|
20 |
| - refCaption: ListAttributeValue<string>; |
21 |
| - searchAttrId: ListAttributeValue["id"]; |
| 23 | + refCaption: ListAttributeValue<string> | ListExpressionValue<string>; |
| 24 | + searchAttrId?: ListAttributeValue["id"]; |
22 | 25 | }
|
23 | 26 |
|
24 | 27 | type Component<P extends object> = (props: P) => React.ReactElement;
|
@@ -49,16 +52,29 @@ function mapProps(props: WidgetProps): RequiredProps {
|
49 | 52 | throw new Error("RefFilterStoreProvider: refOptions is required");
|
50 | 53 | }
|
51 | 54 |
|
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 | + }; |
54 | 77 | }
|
55 |
| - return { |
56 |
| - name: props.name, |
57 |
| - refEntity: props.refEntity, |
58 |
| - refOptions: props.refOptions, |
59 |
| - refCaption: props.refCaption, |
60 |
| - searchAttrId: props.refCaption.id |
61 |
| - }; |
62 | 78 | }
|
63 | 79 |
|
64 | 80 | function useGate(props: WidgetProps): DerivedPropsGate<RequiredProps> {
|
|
0 commit comments