Skip to content

Commit f76ec4a

Browse files
committed
fix: combobox database customcontent and value attribute runtime error
1 parent 5f8aad1 commit f76ec4a

File tree

7 files changed

+78
-15
lines changed

7 files changed

+78
-15
lines changed

packages/pluggableWidgets/combobox-web/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- We fixed an issue where database optional value attribute breaks on runtime when not being set.
12+
13+
- We fixed an issue where custom content not shown on design preview and runtime for database datasource.
14+
915
## [2.1.0] - 2024-10-29
1016

1117
### Added

packages/pluggableWidgets/combobox-web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@mendix/combobox-web",
33
"widgetName": "Combobox",
4-
"version": "2.1.0",
4+
"version": "2.1.1",
55
"description": "Configurable Combo box widget with suggestions and autocomplete.",
66
"copyright": "© Mendix Technology BV 2024. All rights reserved.",
77
"license": "Apache-2.0",

packages/pluggableWidgets/combobox-web/src/Combobox.editorPreview.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { SingleSelector, SelectionBaseProps } from "./helpers/types";
77
import "./ui/Combobox.scss";
88
import { AssociationPreviewSelector } from "./helpers/Association/Preview/AssociationPreviewSelector";
99
import { StaticPreviewSelector } from "./helpers/Static/Preview/StaticPreviewSelector";
10+
import { DatabasePreviewSelector } from "./helpers/Database/Preview/DatabasePreviewSelector";
1011

1112
export const preview = (props: ComboboxPreviewProps): ReactElement => {
1213
const id = generateUUID().toString();
@@ -44,6 +45,9 @@ export const preview = (props: ComboboxPreviewProps): ReactElement => {
4445
if (props.source === "static") {
4546
return new StaticPreviewSelector(props);
4647
}
48+
if (props.source === "database") {
49+
return new DatabasePreviewSelector(props);
50+
}
4751
return new AssociationPreviewSelector(props);
4852
}, [props]);
4953
return (

packages/pluggableWidgets/combobox-web/src/helpers/Database/DatabaseValuesProvider.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ export class DatabaseValuesProvider implements ValuesProvider<string | Big> {
2121
if (key === null) {
2222
return this.emptyValue?.value;
2323
}
24-
if (!this.attribute) {
25-
throw new Error("DatabaseValuesProvider: no formatter available.");
26-
}
24+
2725
const item = this.optionsMap.get(key);
2826
if (!item) {
2927
return this.emptyValue?.value;
3028
}
31-
const value = this.attribute.get(item);
32-
if (value.status === "unavailable") {
33-
return this.emptyValue?.value;
29+
30+
if (this.attribute) {
31+
const value = this.attribute.get(item);
32+
if (value.status === "unavailable") {
33+
return this.emptyValue?.value;
34+
}
35+
return value.value;
3436
}
35-
return value.value;
37+
38+
return this.emptyValue?.value;
3639
}
3740

3841
getEmptyValue(): string | Big | undefined {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
ComboboxContainerProps,
3+
ComboboxPreviewProps,
4+
LoadingTypeEnum,
5+
OptionsSourceAssociationCustomContentTypeEnum
6+
} from "../../../../typings/ComboboxProps";
7+
import { CaptionsProvider, OptionsProvider, SingleSelector, Status } from "../../../helpers/types";
8+
import { getDatasourcePlaceholderText } from "../../../helpers/utils";
9+
import { AssociationPreviewCaptionsProvider } from "../../Association/Preview/AssociationPreviewCaptionsProvider";
10+
import { AssociationPreviewOptionsProvider } from "../../Association/Preview/AssociationPreviewOptionsProvider";
11+
12+
export class DatabasePreviewSelector implements SingleSelector {
13+
attributeType?: "string" | "big" | "boolean" | "date";
14+
caption: CaptionsProvider;
15+
clearable: boolean;
16+
currentId: string | null;
17+
customContentType: OptionsSourceAssociationCustomContentTypeEnum;
18+
lazyLoading?: boolean = false;
19+
loadingType?: LoadingTypeEnum = "skeleton";
20+
options: OptionsProvider;
21+
readOnly: boolean;
22+
selectorType?: "context" | "database" | "static";
23+
status: Status = "available";
24+
type = "single" as const;
25+
validation?: string;
26+
27+
onEnterEvent?: () => void;
28+
onLeaveEvent?: () => void;
29+
30+
constructor(props: ComboboxPreviewProps) {
31+
this.caption = new AssociationPreviewCaptionsProvider(new Map());
32+
this.clearable = props.clearable;
33+
this.currentId = getDatasourcePlaceholderText(props);
34+
this.customContentType = props.optionsSourceDatabaseCustomContentType;
35+
this.options = new AssociationPreviewOptionsProvider(this.caption, new Map());
36+
this.readOnly = props.readOnly;
37+
(this.caption as AssociationPreviewCaptionsProvider).updatePreviewProps({
38+
customContentRenderer: props.optionsSourceDatabaseCustomContent.renderer,
39+
customContentType: props.optionsSourceDatabaseCustomContentType
40+
});
41+
42+
if (props.optionsSourceDatabaseCustomContentType === "listItem") {
43+
// always render custom content dropzone in design mode if type is options only
44+
this.customContentType = "yes";
45+
}
46+
}
47+
48+
setValue(_: string | null): void {
49+
throw new Error("Method not implemented.");
50+
}
51+
updateProps(_: ComboboxContainerProps): void {
52+
throw new Error("Method not implemented.");
53+
}
54+
}

packages/pluggableWidgets/combobox-web/src/helpers/Database/utils.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export function extractDatabaseProps(props: ComboboxContainerProps): ExtractionR
4545
const emptyOption = props.emptyOptionText;
4646
const emptyValue = props.optionsSourceDatabaseDefaultValue;
4747
const clearable = props.clearable;
48-
const customContent = props.optionsSourceAssociationCustomContent;
49-
const customContentType = props.optionsSourceAssociationCustomContentType;
48+
const customContent = props.optionsSourceDatabaseCustomContent;
49+
const customContentType = props.optionsSourceDatabaseCustomContentType;
5050
const valueSourceAttribute = props.optionsSourceDatabaseValueAttribute;
5151
const lazyLoading = (props.lazyLoading && props.optionsSourceDatabaseCaptionType !== "expression") ?? false;
5252
const loadingType = props.loadingType;
@@ -73,10 +73,6 @@ export function extractDatabaseProps(props: ComboboxContainerProps): ExtractionR
7373
}
7474
}
7575

76-
if (!valueSourceAttribute && props.optionsSourceDatabaseItemSelection?.type !== "Multi") {
77-
throw new Error("'valueAttribute' is not defined");
78-
}
79-
8076
return {
8177
targetAttribute,
8278
captionProvider: captionType === "attribute" ? captionAttribute : captionExpression,

packages/pluggableWidgets/combobox-web/src/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<package xmlns="http://www.mendix.com/package/1.0/">
3-
<clientModule name="Combobox" version="2.1.0" xmlns="http://www.mendix.com/clientModule/1.0/">
3+
<clientModule name="Combobox" version="2.1.1" xmlns="http://www.mendix.com/clientModule/1.0/">
44
<widgetFiles>
55
<widgetFile path="Combobox.xml" />
66
</widgetFiles>

0 commit comments

Comments
 (0)