@vc-shell/framework 1.1.22 → 1.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/core/composables/useAppInsights/index.ts +11 -1
- package/core/composables/useBladeRegistry/index.ts +176 -0
- package/core/composables/useDynamicProperties/index.ts +380 -255
- package/core/composables/useErrorHandler/index.ts +2 -3
- package/core/composables/useLanguages/index.ts +78 -78
- package/core/plugins/modularity/index.ts +17 -6
- package/core/services/global-search-service/index.ts +36 -0
- package/dist/core/composables/useAppInsights/index.d.ts +5 -2
- package/dist/core/composables/useAppInsights/index.d.ts.map +1 -1
- package/dist/core/composables/useBladeRegistry/index.d.ts +48 -0
- package/dist/core/composables/useBladeRegistry/index.d.ts.map +1 -0
- package/dist/core/composables/useDynamicProperties/index.d.ts +12 -9
- package/dist/core/composables/useDynamicProperties/index.d.ts.map +1 -1
- package/dist/core/composables/useErrorHandler/index.d.ts.map +1 -1
- package/dist/core/plugins/modularity/index.d.ts.map +1 -1
- package/dist/core/services/global-search-service/index.d.ts +10 -0
- package/dist/core/services/global-search-service/index.d.ts.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/index.d.ts +7 -12
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/index.d.ts.map +1 -1
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeActions.d.ts +15 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeActions.d.ts.map +1 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeRouteResolver.d.ts +11 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeRouteResolver.d.ts.map +1 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeState.d.ts +15 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeState.d.ts.map +1 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeWatchers.d.ts +6 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeWatchers.d.ts.map +1 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/routerUtils.d.ts +28 -0
- package/dist/shared/components/blade-navigation/composables/useBladeNavigation/internal/routerUtils.d.ts.map +1 -0
- package/dist/shared/components/blade-navigation/plugin.d.ts.map +1 -1
- package/dist/shared/components/blade-navigation/types/index.d.ts +5 -5
- package/dist/shared/components/blade-navigation/types/index.d.ts.map +1 -1
- package/dist/shared/components/notification-template/notification-template.vue.d.ts +2 -2
- package/dist/shared/components/notification-template/notification-template.vue.d.ts.map +1 -1
- package/dist/shared/components/notifications/components/notification-container/index.d.ts +6 -6
- package/dist/shared/components/notifications/components/notification-container/index.d.ts.map +1 -1
- package/dist/shared/modules/assets-manager/components/assets-manager/assets-manager.vue.d.ts +2 -2
- package/dist/shared/modules/dynamic/index.d.ts.map +1 -1
- package/dist/shared/modules/dynamic/pages/dynamic-blade-list.vue.d.ts +2 -2
- package/dist/shared/pages/InvitePage/components/invite/Invite.vue.d.ts +1 -1
- package/dist/shared/pages/InvitePage/components/invite/Invite.vue.d.ts.map +1 -1
- package/dist/shared/pages/ResetPasswordPage/components/reset-password/ResetPassword.vue.d.ts +1 -1
- package/dist/shared/pages/ResetPasswordPage/components/reset-password/ResetPassword.vue.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui/components/atoms/vc-badge/vc-badge.vue.d.ts +1 -1
- package/dist/ui/components/atoms/vc-badge/vc-badge.vue.d.ts.map +1 -1
- package/dist/ui/components/atoms/vc-container/vc-container.vue.d.ts +2 -2
- package/dist/ui/components/atoms/vc-icon/vc-icon.vue.d.ts +1 -1
- package/dist/ui/components/atoms/vc-icon/vc-icon.vue.d.ts.map +1 -1
- package/dist/ui/components/atoms/vc-icon/vc-material-icon.vue.d.ts +1 -1
- package/dist/ui/components/atoms/vc-icon/vc-material-icon.vue.d.ts.map +1 -1
- package/dist/ui/components/atoms/vc-progress/vc-progress.vue.d.ts +1 -1
- package/dist/ui/components/atoms/vc-progress/vc-progress.vue.d.ts.map +1 -1
- package/dist/ui/components/molecules/vc-editor/vc-editor.vue.d.ts +2 -2
- package/dist/ui/components/molecules/vc-file-upload/vc-file-upload.vue.d.ts +2 -2
- package/dist/ui/components/molecules/vc-file-upload/vc-file-upload.vue.d.ts.map +1 -1
- package/dist/ui/components/molecules/vc-input/vc-input.vue.d.ts +2 -2
- package/dist/ui/components/molecules/vc-input/vc-input.vue.d.ts.map +1 -1
- package/dist/ui/components/molecules/vc-input-dropdown/vc-input-dropdown.vue.d.ts +2 -0
- package/dist/ui/components/molecules/vc-input-dropdown/vc-input-dropdown.vue.d.ts.map +1 -1
- package/dist/ui/components/molecules/vc-pagination/vc-pagination.vue.d.ts +1 -1
- package/dist/ui/components/molecules/vc-pagination/vc-pagination.vue.d.ts.map +1 -1
- package/dist/ui/components/molecules/vc-rating/vc-rating.vue.d.ts +1 -1
- package/dist/ui/components/molecules/vc-rating/vc-rating.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-app/_internal/vc-app-menu/_internal/vc-app-menu-item/vc-app-menu-item.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-app/_internal/vc-app-menu/_internal/vc-app-menu-item/vc-app-menu-item.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-app/vc-app.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-toolbar/_internal/vc-blade-toolbar-buttons/_internal/vc-blade-toolbar-button/vc-blade-toolbar-base-button.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-toolbar/_internal/vc-blade-toolbar-buttons/_internal/vc-blade-toolbar-button/vc-blade-toolbar-button.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-toolbar/_internal/vc-blade-toolbar-buttons/_internal/vc-blade-toolbar-button/vc-blade-toolbar-button.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-toolbar/_internal/vc-blade-toolbar-buttons/_internal/vc-blade-toolbar-button/vc-blade-toolbar-circle-button.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-blade/_internal/vc-blade-toolbar/_internal/vc-blade-toolbar-buttons/_internal/vc-blade-toolbar-button/vc-blade-toolbar-circle-button.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-blade/vc-blade.backupsb.d.ts +3 -3
- package/dist/ui/components/organisms/vc-blade/vc-blade.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-blade/vc-blade.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-dynamic-property/vc-dynamic-property.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-gallery/_internal/vc-gallery-item/vc-gallery-item.vue.d.ts +2 -2
- package/dist/ui/components/organisms/vc-gallery/_internal/vc-gallery-preview/vc-gallery-preview.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-gallery/_internal/vc-gallery-preview/vc-gallery-preview.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-gallery/vc-gallery.vue.d.ts +3 -3
- package/dist/ui/components/organisms/vc-gallery/vc-gallery.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-popup/vc-popup.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-popup/vc-popup.vue.d.ts.map +1 -1
- package/dist/ui/components/organisms/vc-table/_internal/vc-table-counter/vc-table-counter.vue.d.ts +1 -1
- package/dist/ui/components/organisms/vc-table/_internal/vc-table-counter/vc-table-counter.vue.d.ts.map +1 -1
- package/package.json +4 -4
- package/shared/components/blade-navigation/composables/useBladeNavigation/index.ts +199 -597
- package/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeActions.ts +151 -0
- package/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeRouteResolver.ts +243 -0
- package/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeState.ts +93 -0
- package/shared/components/blade-navigation/composables/useBladeNavigation/internal/bladeWatchers.ts +90 -0
- package/shared/components/blade-navigation/composables/useBladeNavigation/internal/routerUtils.ts +150 -0
- package/shared/components/blade-navigation/plugin.ts +17 -12
- package/shared/components/blade-navigation/types/index.ts +2 -4
- package/shared/components/notification-template/notification-template.vue +2 -2
- package/shared/modules/dynamic/index.ts +2 -8
- package/ui/components/molecules/vc-input-dropdown/vc-input-dropdown.vue +4 -0
- package/ui/components/organisms/vc-app/vc-app.vue +11 -6
- package/ui/components/organisms/vc-dynamic-property/vc-dynamic-property.vue +10 -1
- package/dist/apl-B2DGVGxc.js +0 -76
- package/dist/asciiarmor-2LVJmxlE.js +0 -34
- package/dist/asn1-jKiBa2Ya.js +0 -95
- package/dist/asterisk-DS281yxp.js +0 -271
- package/dist/brainfuck-C_p9pTT8.js +0 -34
- package/dist/clike-DGTaUp48.js +0 -620
- package/dist/clojure-CCKyeQKf.js +0 -800
- package/dist/cmake-CuaCgAKt.js +0 -28
- package/dist/cobol-BlTKFDRj.js +0 -72
- package/dist/coffeescript-BVCvwO8I.js +0 -179
- package/dist/commonlisp-D_kxz07b.js +0 -75
- package/dist/crystal-D309uH6_.js +0 -217
- package/dist/css-BkF-NPzE.js +0 -1553
- package/dist/cypher-BMq4Fwjl.js +0 -68
- package/dist/d-BZcgY6La.js +0 -127
- package/dist/diff-Cg9d_RX2.js +0 -18
- package/dist/dockerfile-DIy8NleC.js +0 -194
- package/dist/dtd-CtLokQ-U.js +0 -84
- package/dist/dylan-QYeExnWK.js +0 -234
- package/dist/ebnf-DUPDuY4r.js +0 -78
- package/dist/ecl-CiXN-g_D.js +0 -121
- package/dist/eiffel-yQhjl4T1.js +0 -110
- package/dist/elm-CNT9vbN0.js +0 -108
- package/dist/erlang-CFOYdy9e.js +0 -487
- package/dist/factor-DDOC7X6P.js +0 -65
- package/dist/fcl-CPC2WYrI.js +0 -103
- package/dist/forth-BmxRyE9S.js +0 -60
- package/dist/fortran-9bvPyrOW.js +0 -442
- package/dist/framework.js +0 -290
- package/dist/gas-cpmYfFX2.js +0 -183
- package/dist/gherkin-CJuwpceU.js +0 -34
- package/dist/groovy-DZeT_VM-.js +0 -146
- package/dist/haskell-Bvt3Qq1t.js +0 -375
- package/dist/haxe-70NVW1pR.js +0 -359
- package/dist/http-D9LttvKF.js +0 -44
- package/dist/idl-B6TRFYjl.js +0 -947
- package/dist/index--F0eI_oT.js +0 -75
- package/dist/index--KQZx7Nr.js +0 -341
- package/dist/index-BAngL0ix.js +0 -299
- package/dist/index-BQtOyLub.js +0 -58
- package/dist/index-Bf4s6An9.js +0 -308
- package/dist/index-BxrA7EzT.js +0 -288
- package/dist/index-C-y5H4_R.js +0 -147509
- package/dist/index-C_zSZ2pX.js +0 -611
- package/dist/index-DFdFt54f.js +0 -71
- package/dist/index-DI3UVoln.js +0 -93
- package/dist/index-DL0-yUXC.js +0 -538
- package/dist/index-DoHQrH4a.js +0 -98
- package/dist/index-DqDgL4W3.js +0 -156
- package/dist/index-DwjKpYAo.js +0 -137
- package/dist/index-d16x5dY_.js +0 -268
- package/dist/index-wjw1DwqR.js +0 -134
- package/dist/index-xCbUzsUb.js +0 -249
- package/dist/index.css +0 -9
- package/dist/javascript-C2yteZeJ.js +0 -691
- package/dist/jinja2-DnB6dQmV.js +0 -154
- package/dist/julia-DpvXAuO6.js +0 -241
- package/dist/livescript-CanGTf8u.js +0 -272
- package/dist/lua-XplVlWi_.js +0 -217
- package/dist/mathematica-jaRHnSxC.js +0 -35
- package/dist/mbox-BctzC1hL.js +0 -76
- package/dist/mirc-CFBPAOaF.js +0 -72
- package/dist/mllike-BSnXJBGA.js +0 -272
- package/dist/modelica-vUgVs--1.js +0 -93
- package/dist/mscgen-Cpl0NYLN.js +0 -104
- package/dist/mumps-CQoS1kWX.js +0 -25
- package/dist/nginx-zDPm3Z74.js +0 -89
- package/dist/nsis-fePjrhq7.js +0 -62
- package/dist/ntriples-CsNjv2QF.js +0 -79
- package/dist/octave-C8PmmSRH.js +0 -143
- package/dist/oz-Ce8aN8oE.js +0 -151
- package/dist/pascal-De0D6mP7.js +0 -77
- package/dist/perl-B4bSCe1C.js +0 -915
- package/dist/pig-D24Z8EXi.js +0 -54
- package/dist/powershell-DkYVfTzP.js +0 -249
- package/dist/properties-Dn9wna3M.js +0 -26
- package/dist/protobuf-BPIjwpzm.js +0 -49
- package/dist/pug-CwAQJzGR.js +0 -248
- package/dist/puppet-nyd4dhjf.js +0 -45
- package/dist/python-BkR3uSy8.js +0 -313
- package/dist/q-DXjKs-tC.js +0 -83
- package/dist/r-LKEuhEGI.js +0 -104
- package/dist/rpm-IznJm2Xc.js +0 -57
- package/dist/ruby-CcYfvIk6.js +0 -228
- package/dist/sas-7E8yHoCW.js +0 -105
- package/dist/scheme-DjibxsNh.js +0 -124
- package/dist/shared/modules/dynamic/components/fields/storybook/pages/DynamicRender.d.ts +0 -110
- package/dist/shared/modules/dynamic/components/fields/storybook/pages/DynamicRender.d.ts.map +0 -1
- package/dist/shared/modules/dynamic/pages/dynamic-blade-form.vue.d.ts +0 -147
- package/dist/shared/modules/dynamic/pages/dynamic-blade-form.vue.d.ts.map +0 -1
- package/dist/shell-C0C2sNA_.js +0 -182
- package/dist/sieve-Bwz7vjP5.js +0 -72
- package/dist/simple-mode-B0dvCdAA.js +0 -89
- package/dist/smalltalk-Bhddl2pB.js +0 -48
- package/dist/solr-BNlsLglM.js +0 -41
- package/dist/sparql-FarWu_Gb.js +0 -197
- package/dist/spreadsheet-C-cy4P5N.js +0 -49
- package/dist/sql-CfG5lQ3l.js +0 -282
- package/dist/stex-Du4h4KAU.js +0 -129
- package/dist/stylus-CAdqWld3.js +0 -250
- package/dist/swift-DSxqR9R6.js +0 -230
- package/dist/tcl-xfoLljhY.js +0 -81
- package/dist/textile-D1AWE-pc.js +0 -295
- package/dist/tiddlywiki-5wqsXtSk.js +0 -155
- package/dist/tiki-__Kn3CeS.js +0 -181
- package/dist/toml-BHiuTcfn.js +0 -49
- package/dist/troff-D2UO-fKf.js +0 -35
- package/dist/ttcn-Bsa4sfRm.js +0 -123
- package/dist/ttcn-cfg-Bac_acMi.js +0 -88
- package/dist/turtle-xwJUxoPV.js +0 -80
- package/dist/vb-c2kQGd6-.js +0 -74
- package/dist/vbscript-1f_Dhg5H.js +0 -324
- package/dist/velocity-DJd0pTTC.js +0 -96
- package/dist/verilog-CiS1jyi5.js +0 -262
- package/dist/vhdl-T9HkrbI2.js +0 -106
- package/dist/webidl-CjfDENEo.js +0 -155
- package/dist/xquery-BUQdORAS.js +0 -422
- package/dist/yacas-C0absKBh.js +0 -73
- package/dist/z80-Pki2zAjW.js +0 -61
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useLoading } from "../useLoading";
|
|
2
2
|
import { useAsync } from "../useAsync";
|
|
3
|
-
import * as _ from "lodash-es";
|
|
4
3
|
import { ComputedRef } from "vue";
|
|
5
4
|
|
|
6
|
-
//
|
|
5
|
+
// === TYPE DEFINITIONS ===
|
|
6
|
+
|
|
7
7
|
export interface IBaseProperty<TPropertyValue> {
|
|
8
8
|
id?: string | null;
|
|
9
9
|
name?: string | null;
|
|
@@ -11,7 +11,7 @@ export interface IBaseProperty<TPropertyValue> {
|
|
|
11
11
|
multilanguage?: boolean | null;
|
|
12
12
|
multivalue?: boolean | null;
|
|
13
13
|
dictionary?: boolean | null;
|
|
14
|
-
valueType?: string | null;
|
|
14
|
+
valueType?: string | null;
|
|
15
15
|
unitOfMeasureId?: string | null;
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -68,26 +68,47 @@ export interface IUseDynamicProperties<
|
|
|
68
68
|
property: TProperty,
|
|
69
69
|
locale: string,
|
|
70
70
|
) => string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[];
|
|
71
|
-
setPropertyValue: (data:
|
|
72
|
-
property: TProperty;
|
|
73
|
-
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[];
|
|
74
|
-
dictionary?: TPropertyDictionaryItem[];
|
|
75
|
-
locale?: string;
|
|
76
|
-
initialProp?: TProperty;
|
|
77
|
-
}) => void;
|
|
71
|
+
setPropertyValue: (data: SetPropertyValueParams<TProperty, TPropertyValue, TPropertyDictionaryItem>) => void;
|
|
78
72
|
loadMeasurements(measureId: string, keyword?: string, locale?: string): Promise<TMeasurement[] | undefined>;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
75
|
+
interface SetPropertyValueParams<TProperty, TPropertyValue, TPropertyDictionaryItem> {
|
|
76
|
+
property: TProperty;
|
|
77
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[];
|
|
78
|
+
dictionary?: TPropertyDictionaryItem[];
|
|
79
|
+
locale?: string;
|
|
80
|
+
initialProp?: TProperty;
|
|
81
|
+
unitOfMeasureId?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// === UTILITY FUNCTIONS ===
|
|
85
|
+
|
|
86
|
+
function isEmptyValue(value: unknown): boolean {
|
|
87
|
+
if (value === undefined || value === null) return true;
|
|
88
|
+
if (typeof value === "number" && isNaN(value)) return true;
|
|
89
|
+
if (typeof value === "string" && value.trim().length === 0) return true;
|
|
90
|
+
if (typeof value === "object" && Object.keys(value).length === 0) return true;
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isMultilanguageProperty<T extends IBaseProperty<unknown>>(property: T): boolean {
|
|
95
|
+
return Boolean(property.multilanguage);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function isMultivalueProperty<T extends IBaseProperty<unknown>>(property: T): boolean {
|
|
99
|
+
return Boolean(property.multivalue);
|
|
89
100
|
}
|
|
90
101
|
|
|
102
|
+
function isDictionaryProperty<T extends IBaseProperty<unknown>>(property: T): boolean {
|
|
103
|
+
return Boolean(property.dictionary);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function isMeasureProperty<T extends IBaseProperty<unknown>>(property: T): boolean {
|
|
107
|
+
return property.valueType === "Measure";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// === MAIN COMPOSABLE ===
|
|
111
|
+
|
|
91
112
|
export const useDynamicProperties = <
|
|
92
113
|
TProperty extends IBaseProperty<TPropertyValue>,
|
|
93
114
|
TPropertyValue extends IBasePropertyValue,
|
|
@@ -102,274 +123,378 @@ export const useDynamicProperties = <
|
|
|
102
123
|
PropertyDictionaryItemConstructor: new (data?: Partial<TPropertyDictionaryItem>) => TPropertyDictionaryItem,
|
|
103
124
|
searchMeasurementFunction?: (measureId: string, locale?: string) => Promise<TMeasurement[] | undefined>,
|
|
104
125
|
): IUseDynamicProperties<TProperty, TPropertyValue, TPropertyDictionaryItem, TPropertyDictionaryItemSearchCriteria> => {
|
|
126
|
+
// === ASYNC OPERATIONS ===
|
|
127
|
+
|
|
105
128
|
const { loading: dictionaryItemsLoading, action: searchDictionaryItems } = useAsync<
|
|
106
129
|
TPropertyDictionaryItemSearchCriteria,
|
|
107
130
|
TPropertyDictionaryItem[] | undefined
|
|
108
131
|
>(async (args: TPropertyDictionaryItemSearchCriteria | undefined) => {
|
|
109
|
-
if (args
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
132
|
+
if (!args) return undefined;
|
|
112
133
|
return await searchDictionaryItemsFunction(args);
|
|
113
134
|
});
|
|
114
135
|
|
|
115
|
-
function
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
property.values?.push(
|
|
126
|
-
new PropertyValueConstructor({
|
|
127
|
-
propertyName: property.name,
|
|
128
|
-
propertyId: property.id,
|
|
129
|
-
languageCode: locale,
|
|
130
|
-
alias: aliasProp?.alias,
|
|
131
|
-
valueType: property.valueType,
|
|
132
|
-
valueId: aliasProp?.valueId,
|
|
133
|
-
} as unknown as Partial<TPropertyValue>),
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
136
|
+
async function loadDictionaries(propertyId: string, keyword?: string, locale?: string) {
|
|
137
|
+
if (!propertyId) return undefined;
|
|
138
|
+
|
|
139
|
+
const dictionaryItems = await searchDictionaryItems({
|
|
140
|
+
propertyIds: [propertyId],
|
|
141
|
+
keyword,
|
|
142
|
+
skip: 0,
|
|
143
|
+
} as TPropertyDictionaryItemSearchCriteria);
|
|
144
|
+
|
|
145
|
+
if (!locale || !dictionaryItems) return dictionaryItems;
|
|
137
146
|
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
return dictionaryItems.map((item: TPropertyDictionaryItem) => {
|
|
148
|
+
const localizedValue = item.localizedValues?.find((localized) => localized.languageCode === locale)?.value;
|
|
149
|
+
|
|
150
|
+
return Object.assign(new PropertyDictionaryItemConstructor(item), {
|
|
151
|
+
value: localizedValue ?? item.alias,
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function loadMeasurements(measureId: string, locale?: string) {
|
|
157
|
+
if (!measureId || !searchMeasurementFunction) return undefined;
|
|
158
|
+
return await searchMeasurementFunction(measureId, locale);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// === VALUE GETTERS ===
|
|
162
|
+
|
|
163
|
+
function getMultilanguageValue(property: TProperty, locale: string): string | TPropertyValue[] {
|
|
164
|
+
const valueForLocale = property.values?.find((x) => x.languageCode === locale);
|
|
165
|
+
|
|
166
|
+
if (isMultivalueProperty(property)) {
|
|
167
|
+
return property.values?.filter((x) => x.languageCode === locale) as TPropertyValue[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Create default value if not exists
|
|
171
|
+
if (!valueForLocale) {
|
|
172
|
+
const aliasValue = property.values?.find((x) => x.propertyId === property.id);
|
|
173
|
+
if (aliasValue) {
|
|
174
|
+
const newValue = new PropertyValueConstructor({
|
|
175
|
+
propertyName: property.name,
|
|
176
|
+
propertyId: property.id,
|
|
177
|
+
languageCode: locale,
|
|
178
|
+
alias: aliasValue.alias,
|
|
179
|
+
valueType: property.valueType,
|
|
180
|
+
valueId: aliasValue.valueId,
|
|
181
|
+
} as unknown as Partial<TPropertyValue>);
|
|
182
|
+
|
|
183
|
+
property.values?.push(newValue);
|
|
140
184
|
}
|
|
141
|
-
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (isDictionaryProperty(property)) {
|
|
188
|
+
return valueForLocale?.valueId as string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return valueForLocale?.value as string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function getSingleLanguageValue(property: TProperty): string | TPropertyValue[] {
|
|
195
|
+
if (isMultivalueProperty(property)) {
|
|
196
|
+
return property.values as TPropertyValue[];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const firstValue = property.values?.[0];
|
|
200
|
+
if (!firstValue) return "";
|
|
201
|
+
|
|
202
|
+
if (isDictionaryProperty(property)) {
|
|
203
|
+
return firstValue.valueId as string;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return firstValue.value as string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function getPropertyValue(property: TProperty, locale: string) {
|
|
210
|
+
if (isMultilanguageProperty(property)) {
|
|
211
|
+
return getMultilanguageValue(property, locale);
|
|
212
|
+
}
|
|
213
|
+
return getSingleLanguageValue(property);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// === VALUE SETTERS ===
|
|
217
|
+
|
|
218
|
+
function createPropertyValue(params: Partial<TPropertyValue>): TPropertyValue {
|
|
219
|
+
return new PropertyValueConstructor({
|
|
220
|
+
isInherited: false,
|
|
221
|
+
...params,
|
|
222
|
+
} as unknown as Partial<TPropertyValue>);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function setMeasurePropertyValue(property: TProperty, value: unknown, unitOfMeasureId?: string): void {
|
|
226
|
+
property.values = [
|
|
227
|
+
createPropertyValue({
|
|
228
|
+
value,
|
|
229
|
+
unitOfMeasureId,
|
|
230
|
+
} as Partial<TPropertyValue>),
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function setDictionaryPropertyValue(
|
|
235
|
+
property: TProperty,
|
|
236
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[],
|
|
237
|
+
dictionary: TPropertyDictionaryItem[],
|
|
238
|
+
): void {
|
|
239
|
+
const dict = dictionary.map((x) => new PropertyDictionaryItemConstructor(x));
|
|
240
|
+
|
|
241
|
+
if (isMultilanguageProperty(property)) {
|
|
242
|
+
handleMultilanguageDictionary(property, value, dict);
|
|
142
243
|
} else {
|
|
143
|
-
|
|
144
|
-
|
|
244
|
+
handleSingleLanguageDictionary(property, value, dict);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function handleMultilanguageDictionary(
|
|
249
|
+
property: TProperty,
|
|
250
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[],
|
|
251
|
+
dict: TPropertyDictionaryItem[],
|
|
252
|
+
): void {
|
|
253
|
+
if (Array.isArray(value)) {
|
|
254
|
+
handleMultilanguageMultivalueDictionary(property, value as (TPropertyDictionaryItem & { value: string })[], dict);
|
|
255
|
+
} else {
|
|
256
|
+
handleMultilanguageSingleValueDictionary(property, value as string, dict);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function handleMultilanguageMultivalueDictionary(
|
|
261
|
+
property: TProperty,
|
|
262
|
+
values: (TPropertyDictionaryItem & { value: string })[],
|
|
263
|
+
dict: TPropertyDictionaryItem[],
|
|
264
|
+
): void {
|
|
265
|
+
property.values = values.flatMap((item) => {
|
|
266
|
+
const dictItem = dict.find((x) => x.id === (item as unknown as TPropertyValue).valueId || x.id === item.id);
|
|
267
|
+
|
|
268
|
+
if (dictItem?.localizedValues?.length) {
|
|
269
|
+
return dictItem.localizedValues.map((locValue) =>
|
|
270
|
+
createPropertyValue({
|
|
271
|
+
propertyId: dictItem.propertyId,
|
|
272
|
+
alias: dictItem.alias,
|
|
273
|
+
languageCode: locValue.languageCode,
|
|
274
|
+
value: locValue.value ?? dictItem.alias,
|
|
275
|
+
valueId: dictItem.id,
|
|
276
|
+
} as Partial<TPropertyValue>),
|
|
277
|
+
);
|
|
145
278
|
}
|
|
146
|
-
|
|
147
|
-
|
|
279
|
+
|
|
280
|
+
return createPropertyValue(item as unknown as Partial<TPropertyValue>);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function handleMultilanguageSingleValueDictionary(
|
|
285
|
+
property: TProperty,
|
|
286
|
+
value: string,
|
|
287
|
+
dict: TPropertyDictionaryItem[],
|
|
288
|
+
): void {
|
|
289
|
+
const dictionaryItem = dict.find((x) => x.id === value);
|
|
290
|
+
|
|
291
|
+
if (dictionaryItem?.localizedValues) {
|
|
292
|
+
property.values = dictionaryItem.localizedValues.map((locValue) =>
|
|
293
|
+
createPropertyValue({
|
|
294
|
+
propertyId: dictionaryItem.propertyId,
|
|
295
|
+
alias: dictionaryItem.alias,
|
|
296
|
+
languageCode: locValue.languageCode,
|
|
297
|
+
value: locValue.value ?? dictionaryItem.alias,
|
|
298
|
+
valueId: dictionaryItem.id,
|
|
299
|
+
} as Partial<TPropertyValue>),
|
|
300
|
+
);
|
|
301
|
+
} else {
|
|
302
|
+
property.values = [];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function handleSingleLanguageDictionary(
|
|
307
|
+
property: TProperty,
|
|
308
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[],
|
|
309
|
+
dict: TPropertyDictionaryItem[],
|
|
310
|
+
): void {
|
|
311
|
+
if (Array.isArray(value)) {
|
|
312
|
+
handleSingleLanguageMultivalueDictionary(
|
|
313
|
+
property,
|
|
314
|
+
value as (TPropertyDictionaryItem & { value: string })[],
|
|
315
|
+
dict,
|
|
316
|
+
);
|
|
317
|
+
} else {
|
|
318
|
+
handleSingleLanguageSingleValueDictionary(property, value as string, dict);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function handleSingleLanguageMultivalueDictionary(
|
|
323
|
+
property: TProperty,
|
|
324
|
+
values: (TPropertyDictionaryItem & { value: string })[],
|
|
325
|
+
dict: TPropertyDictionaryItem[],
|
|
326
|
+
): void {
|
|
327
|
+
property.values = values.flatMap((item) => {
|
|
328
|
+
const dictItem = dict.find((x) => x.id === (item as unknown as TPropertyValue).valueId || x.id === item.id);
|
|
329
|
+
|
|
330
|
+
if (dictItem) {
|
|
331
|
+
return createPropertyValue({
|
|
332
|
+
propertyId: dictItem.propertyId,
|
|
333
|
+
alias: dictItem.alias,
|
|
334
|
+
value: item.value ?? dictItem.alias,
|
|
335
|
+
valueId: dictItem.id,
|
|
336
|
+
} as Partial<TPropertyValue>);
|
|
148
337
|
}
|
|
149
|
-
|
|
338
|
+
|
|
339
|
+
return createPropertyValue(item as unknown as Partial<TPropertyValue>);
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function handleSingleLanguageSingleValueDictionary(
|
|
344
|
+
property: TProperty,
|
|
345
|
+
value: string,
|
|
346
|
+
dict: TPropertyDictionaryItem[],
|
|
347
|
+
): void {
|
|
348
|
+
if (isEmptyValue(value)) {
|
|
349
|
+
property.values = [];
|
|
350
|
+
return;
|
|
150
351
|
}
|
|
352
|
+
|
|
353
|
+
const dictionaryItem = dict.find((x) => x.id === value);
|
|
354
|
+
property.values = [
|
|
355
|
+
createPropertyValue({
|
|
356
|
+
propertyId: dictionaryItem?.propertyId,
|
|
357
|
+
alias: dictionaryItem?.alias,
|
|
358
|
+
value: (dictionaryItem as TPropertyDictionaryItem & { value: string })?.value ?? dictionaryItem?.alias,
|
|
359
|
+
valueId: value,
|
|
360
|
+
} as Partial<TPropertyValue>),
|
|
361
|
+
];
|
|
151
362
|
}
|
|
152
363
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
364
|
+
function setRegularPropertyValue(
|
|
365
|
+
property: TProperty,
|
|
366
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[],
|
|
367
|
+
locale?: string,
|
|
368
|
+
initialProp?: TProperty,
|
|
369
|
+
): void {
|
|
370
|
+
if (isMultilanguageProperty(property)) {
|
|
371
|
+
handleMultilanguageRegularProperty(property, value, locale);
|
|
372
|
+
} else {
|
|
373
|
+
handleSingleLanguageRegularProperty(property, value, locale, initialProp);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function handleMultilanguageRegularProperty(
|
|
378
|
+
property: TProperty,
|
|
379
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[],
|
|
380
|
+
locale?: string,
|
|
381
|
+
): void {
|
|
382
|
+
if (Array.isArray(value)) {
|
|
383
|
+
// Multivalue multilanguage
|
|
384
|
+
property.values =
|
|
385
|
+
property.values &&
|
|
386
|
+
([
|
|
387
|
+
...property.values.filter((x) => x.languageCode !== locale),
|
|
388
|
+
...(value as TPropertyValue[]).map((item) =>
|
|
389
|
+
createPropertyValue({ ...item, languageCode: locale } as Partial<TPropertyValue>),
|
|
390
|
+
),
|
|
391
|
+
] as TPropertyValue[]);
|
|
392
|
+
} else {
|
|
393
|
+
// Single value multilanguage
|
|
394
|
+
const existingValue = property.values?.find((x) => x.languageCode === locale);
|
|
395
|
+
if (existingValue) {
|
|
396
|
+
existingValue.value = value as string;
|
|
397
|
+
} else {
|
|
398
|
+
property.values = [
|
|
399
|
+
createPropertyValue({
|
|
400
|
+
value: value as string,
|
|
401
|
+
languageCode: locale,
|
|
402
|
+
} as Partial<TPropertyValue>),
|
|
403
|
+
];
|
|
169
404
|
}
|
|
170
|
-
return dictionaryItems;
|
|
171
405
|
}
|
|
172
406
|
}
|
|
173
407
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
408
|
+
function handleSingleLanguageRegularProperty(
|
|
409
|
+
property: TProperty,
|
|
410
|
+
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[],
|
|
411
|
+
locale?: string,
|
|
412
|
+
initialProp?: TProperty,
|
|
413
|
+
): void {
|
|
414
|
+
if (Array.isArray(value)) {
|
|
415
|
+
// Multivalue
|
|
416
|
+
property.values = (value as TPropertyValue[]).map((item) => createPropertyValue(item as Partial<TPropertyValue>));
|
|
417
|
+
} else {
|
|
418
|
+
handleSingleValueRegularProperty(property, value, locale, initialProp);
|
|
419
|
+
}
|
|
177
420
|
}
|
|
178
421
|
|
|
179
|
-
function
|
|
180
|
-
|
|
422
|
+
function handleSingleValueRegularProperty(
|
|
423
|
+
property: TProperty,
|
|
424
|
+
value: string | (TPropertyDictionaryItem & { value: string }),
|
|
425
|
+
locale?: string,
|
|
426
|
+
initialProp?: TProperty,
|
|
427
|
+
): void {
|
|
428
|
+
if (typeof value === "boolean") {
|
|
429
|
+
handleBooleanValue(property, value, initialProp);
|
|
430
|
+
} else if (isEmptyValue(value)) {
|
|
431
|
+
handleEmptyValue(property, value, locale, initialProp);
|
|
432
|
+
} else {
|
|
433
|
+
handleNonEmptyValue(property, value as string);
|
|
434
|
+
}
|
|
181
435
|
}
|
|
182
436
|
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
value: string | TPropertyValue[] | (TPropertyDictionaryItem & { value: string })[];
|
|
186
|
-
dictionary?: TPropertyDictionaryItem[];
|
|
187
|
-
locale?: string;
|
|
188
|
-
initialProp?: TProperty;
|
|
189
|
-
unitOfMeasureId?: string;
|
|
190
|
-
}) {
|
|
191
|
-
const { property, value, dictionary, locale } = data;
|
|
192
|
-
|
|
193
|
-
if (property.valueType === "Measure") {
|
|
437
|
+
function handleBooleanValue(property: TProperty, value: boolean, initialProp?: TProperty): void {
|
|
438
|
+
if (initialProp?.values?.length) {
|
|
194
439
|
property.values = [
|
|
195
|
-
|
|
196
|
-
value
|
|
197
|
-
|
|
198
|
-
isInherited: false,
|
|
199
|
-
} as unknown as Partial<TPropertyValue>),
|
|
440
|
+
property.values?.[0]
|
|
441
|
+
? Object.assign(property.values[0], { value })
|
|
442
|
+
: createPropertyValue({ value } as Partial<TPropertyValue>),
|
|
200
443
|
];
|
|
201
|
-
|
|
444
|
+
} else if (value) {
|
|
445
|
+
property.values = [createPropertyValue({ value } as Partial<TPropertyValue>)];
|
|
446
|
+
} else {
|
|
447
|
+
property.values = [];
|
|
202
448
|
}
|
|
449
|
+
}
|
|
203
450
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
languageCode: x.languageCode,
|
|
219
|
-
value: x.value ?? dictItem.alias,
|
|
220
|
-
valueId: dictItem.id,
|
|
221
|
-
} as unknown as Partial<TPropertyValue>),
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return new PropertyValueConstructor(item as unknown as Partial<TPropertyValue>);
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
// Single value Dictionary Multilanguage
|
|
228
|
-
else {
|
|
229
|
-
const dictionaryItem = dictionary.find((x) => x.id === (value as string));
|
|
230
|
-
if (dictionaryItem) {
|
|
231
|
-
property.values = dictionaryItem?.localizedValues?.map(
|
|
232
|
-
(x) =>
|
|
233
|
-
new PropertyValueConstructor({
|
|
234
|
-
propertyId: dictionaryItem.propertyId,
|
|
235
|
-
alias: dictionaryItem.alias,
|
|
236
|
-
languageCode: x.languageCode,
|
|
237
|
-
value: x.value ?? dictionaryItem.alias,
|
|
238
|
-
valueId: dictionaryItem.id,
|
|
239
|
-
} as unknown as Partial<TPropertyValue>),
|
|
240
|
-
);
|
|
241
|
-
} else {
|
|
242
|
-
property.values = [];
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
// Multivalue Dictionary
|
|
247
|
-
if (Array.isArray(value)) {
|
|
248
|
-
property.values = (value as (TPropertyDictionaryItem & { value: string })[]).flatMap((item) => {
|
|
249
|
-
const dictItem = dict.find((x) => x.id === (item as unknown as TPropertyValue).valueId || x.id === item.id);
|
|
250
|
-
if (dictItem) {
|
|
251
|
-
return new PropertyValueConstructor({
|
|
252
|
-
propertyId: dictItem.propertyId,
|
|
253
|
-
alias: dictItem.alias,
|
|
254
|
-
value: item.value ?? dictItem.alias,
|
|
255
|
-
valueId: dictItem.id,
|
|
256
|
-
} as unknown as Partial<TPropertyValue>);
|
|
257
|
-
}
|
|
258
|
-
return new PropertyValueConstructor(item as unknown as Partial<TPropertyValue>);
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
// Single value Dictionary
|
|
262
|
-
else {
|
|
263
|
-
const dictionaryItem = dictionary.find((x) => x.id === (value as string));
|
|
264
|
-
|
|
265
|
-
if (isEmptyValues(value)) {
|
|
266
|
-
property.values = [];
|
|
267
|
-
} else {
|
|
268
|
-
property.values = [
|
|
269
|
-
new PropertyValueConstructor({
|
|
270
|
-
propertyId: dictionaryItem?.propertyId,
|
|
271
|
-
alias: dictionaryItem?.alias,
|
|
272
|
-
value: (dictionaryItem as TPropertyDictionaryItem & { value: string })?.value ?? dictionaryItem?.alias,
|
|
273
|
-
valueId: value as string,
|
|
274
|
-
} as unknown as Partial<TPropertyValue>),
|
|
275
|
-
];
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
451
|
+
function handleEmptyValue(property: TProperty, value: unknown, locale?: string, initialProp?: TProperty): void {
|
|
452
|
+
const hadOriginalValue = initialProp?.values?.find((v) =>
|
|
453
|
+
isMultilanguageProperty(property) ? v.languageCode === locale : true,
|
|
454
|
+
)?.value;
|
|
455
|
+
|
|
456
|
+
const originalWasEmpty = isEmptyValue(hadOriginalValue);
|
|
457
|
+
|
|
458
|
+
if (originalWasEmpty) {
|
|
459
|
+
property.values = [
|
|
460
|
+
createPropertyValue({
|
|
461
|
+
value: value as string,
|
|
462
|
+
languageCode: isMultilanguageProperty(property) ? locale : undefined,
|
|
463
|
+
} as Partial<TPropertyValue>),
|
|
464
|
+
];
|
|
279
465
|
} else {
|
|
280
|
-
|
|
281
|
-
// Multivalue Multilanguage
|
|
282
|
-
if (Array.isArray(value)) {
|
|
283
|
-
property.values =
|
|
284
|
-
property.values &&
|
|
285
|
-
([
|
|
286
|
-
...property.values.filter((x) => x.languageCode !== locale),
|
|
287
|
-
...(value as TPropertyValue[]).map(
|
|
288
|
-
(item) =>
|
|
289
|
-
new PropertyValueConstructor({ ...item, languageCode: locale } as unknown as Partial<TPropertyValue>),
|
|
290
|
-
),
|
|
291
|
-
] as TPropertyValue[]);
|
|
292
|
-
}
|
|
293
|
-
// Single value Multilanguage
|
|
294
|
-
else {
|
|
295
|
-
const propValue = property.values?.find((x) => x.languageCode == locale);
|
|
296
|
-
if (propValue) {
|
|
297
|
-
propValue.value = value as string;
|
|
298
|
-
} else {
|
|
299
|
-
property.values = [
|
|
300
|
-
new PropertyValueConstructor({
|
|
301
|
-
value: value as string,
|
|
302
|
-
isInherited: false,
|
|
303
|
-
languageCode: locale,
|
|
304
|
-
} as unknown as Partial<TPropertyValue>),
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
} else {
|
|
309
|
-
// Multivalue
|
|
310
|
-
if (Array.isArray(value)) {
|
|
311
|
-
property.values = (value as TPropertyValue[]).map(
|
|
312
|
-
(item) => new PropertyValueConstructor(item as unknown as Partial<TPropertyValue>),
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
// Single value
|
|
316
|
-
else {
|
|
317
|
-
if (typeof value === "boolean") {
|
|
318
|
-
if (data.initialProp?.values?.length) {
|
|
319
|
-
property.values = [
|
|
320
|
-
property.values?.[0]
|
|
321
|
-
? Object.assign(property.values[0], { value })
|
|
322
|
-
: new PropertyValueConstructor({
|
|
323
|
-
value: value,
|
|
324
|
-
isInherited: false,
|
|
325
|
-
} as unknown as Partial<TPropertyValue>),
|
|
326
|
-
];
|
|
327
|
-
} else {
|
|
328
|
-
if (value) {
|
|
329
|
-
property.values = [
|
|
330
|
-
new PropertyValueConstructor({
|
|
331
|
-
value: value,
|
|
332
|
-
isInherited: false,
|
|
333
|
-
} as unknown as Partial<TPropertyValue>),
|
|
334
|
-
];
|
|
335
|
-
} else {
|
|
336
|
-
property.values = [];
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
} else if (isEmptyValues(value)) {
|
|
340
|
-
// Ensure we create an empty PropertyValue if the original value was also empty, to signify an explicit clear.
|
|
341
|
-
// Otherwise, if there was a value and now it's empty, we clear the values array.
|
|
342
|
-
const hadOriginalValue = data.initialProp?.values?.find((v) =>
|
|
343
|
-
property.multilanguage ? v.languageCode === locale : true,
|
|
344
|
-
)?.value;
|
|
345
|
-
const originalValueWasEmpty = isEmptyValues(hadOriginalValue);
|
|
346
|
-
|
|
347
|
-
if (originalValueWasEmpty) {
|
|
348
|
-
property.values = [
|
|
349
|
-
new PropertyValueConstructor({
|
|
350
|
-
value: value as string,
|
|
351
|
-
isInherited: false,
|
|
352
|
-
languageCode: property.multilanguage ? locale : undefined,
|
|
353
|
-
} as unknown as Partial<TPropertyValue>),
|
|
354
|
-
];
|
|
355
|
-
} else {
|
|
356
|
-
property.values = [];
|
|
357
|
-
}
|
|
358
|
-
} else {
|
|
359
|
-
property.values = property.values?.[0]
|
|
360
|
-
? [Object.assign(property.values[0], { value: value as string })]
|
|
361
|
-
: [
|
|
362
|
-
new PropertyValueConstructor({
|
|
363
|
-
value: value as string,
|
|
364
|
-
isInherited: false,
|
|
365
|
-
} as unknown as Partial<TPropertyValue>),
|
|
366
|
-
];
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
466
|
+
property.values = [];
|
|
370
467
|
}
|
|
371
468
|
}
|
|
372
469
|
|
|
470
|
+
function handleNonEmptyValue(property: TProperty, value: string): void {
|
|
471
|
+
if (property.values?.[0]) {
|
|
472
|
+
Object.assign(property.values[0], { value });
|
|
473
|
+
} else {
|
|
474
|
+
property.values = [createPropertyValue({ value } as Partial<TPropertyValue>)];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// === MAIN SET PROPERTY VALUE FUNCTION ===
|
|
479
|
+
|
|
480
|
+
function setPropertyValue(params: SetPropertyValueParams<TProperty, TPropertyValue, TPropertyDictionaryItem>): void {
|
|
481
|
+
const { property, value, dictionary, locale, initialProp, unitOfMeasureId } = params;
|
|
482
|
+
|
|
483
|
+
if (isMeasureProperty(property)) {
|
|
484
|
+
setMeasurePropertyValue(property, value, unitOfMeasureId);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
if (dictionary?.length) {
|
|
489
|
+
setDictionaryPropertyValue(property, value, dictionary);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
setRegularPropertyValue(property, value, locale, initialProp);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// === RETURN API ===
|
|
497
|
+
|
|
373
498
|
const loading = useLoading(dictionaryItemsLoading);
|
|
374
499
|
|
|
375
500
|
return {
|