Skip to content

feat: generateFullPropertyTree #1507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: release/4.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion apis/nucleus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ListBoxPopoverWrapper, {
} from './components/listbox/ListBoxPopoverWrapper';

import createSessionObject from './object/create-session-object';
import createObject from './object/create-object';
import createObject, { createFullPropertyTree } from './object/create-object';
import get from './object/get-generic-object';
import flagsFn from './flags/flags';
import { create as typesFn } from './sn/types';
Expand Down Expand Up @@ -350,6 +350,21 @@ function nuked(configuration = {}) {
* );
*/
generateProperties: async (cfg) => createObject(cfg, halo, true),
/**
* Generates full property tree for a visualization, including its children.
* Note that this does not support passing in fields
* @param {EngineAPI.IGenericObjectEntry} properties The properties for the property tree??
* @experimental
* @returns {Promise<EngineAPI.IGenericObjectEntry>} The objects full property tree
* @example
* // generate properties for a layout container
* const properties = await n.generateProperties({
* qProperties: { components: [...]},
* qChildren: [...]
* },
* );
*/
generateFullPropertyTree: async (cfg) => createFullPropertyTree(cfg, halo),
/**
* Updates the current context of this embed instance.
* Use this when you want to change some part of the current context, like theme.
Expand Down
26 changes: 26 additions & 0 deletions apis/nucleus/src/object/create-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,29 @@ export default async function createObject(
}
return mergedProps;
}

export async function createFullPropertyTree(properties, halo) {
const createObjectFromTreeNode = async (props) =>
createObject(
{ type: props.qProperty.visualization, properties: props.qProperty, extendProperties: true },
halo,
true
);
const createChildrenProperties = async (qChildren) =>
Promise.all(
qChildren.map(async (child) => ({
// ...child,
qProperty: await createObjectFromTreeNode(child),
qChildren: await createChildrenProperties(child.qChildren),
}))
);

const qProperty = await createObjectFromTreeNode(properties);
const qChildren = await createChildrenProperties(properties.qChildren);

return {
// ...properties
qProperty,
qChildren,
};
}