From 40db46c920bfc2b98d98fbffeb633fb580ece32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Thu, 10 Oct 2024 14:53:37 +0200 Subject: [PATCH] object-to-property-value-array --- .../src/packages/core/workspace/index.ts | 2 +- .../object-to-property-value-array.function.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/workspace/utils/object-to-property-value-array.function.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/index.ts index a568fc8775..974168832c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/index.ts @@ -7,10 +7,10 @@ export * from './entity/index.js'; export * from './modals/index.js'; export * from './paths.js'; export * from './submittable/index.js'; +export * from './utils/object-to-property-value-array.function.js'; export * from './workspace-context.interface.js'; export * from './workspace-property-dataset/index.js'; export * from './workspace.context-token.js'; export * from './workspace.element.js'; -export * from './workspace.element.js'; export type * from './conditions/index.js'; export type * from './types.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/utils/object-to-property-value-array.function.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/utils/object-to-property-value-array.function.ts new file mode 100644 index 0000000000..d35f34033f --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/utils/object-to-property-value-array.function.ts @@ -0,0 +1,14 @@ +import type { UmbPropertyValueData } from '../../property/types'; + +/** + * @function UmbObjectToPropertyValueArray + * @param {object} data - an object with properties to be converted. + * @returns {Array | undefined} - and array of property values or undefined + */ +export function umbObjectToPropertyValueArray(data: object | undefined): Array | undefined { + if (!data) return; + return Object.keys(data).map((key) => ({ + alias: key, + value: (data as any)[key], + })); +}