Skip to content
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

fix(web): Ensuring that we can deal with JSON.Objects in propSpecs #5553

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions app/web/src/api/sdf/dal/property_editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum PropertyEditorPropKind {
Object = "object",
String = "string",
Map = "map",
Json = "json",
}

export interface PropertyEditorPropWidgetKindCodeEditor {
Expand Down
3 changes: 2 additions & 1 deletion app/web/src/assets/static/editor_typescript.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ type PropDefinitionKind =
| "boolean"
| "float"
| "integer"
| "json"
| "map"
| "object"
| "string";
Expand Down Expand Up @@ -582,7 +583,7 @@ declare class PropBuilder implements IPropBuilder {
/**
* The type of the prop
*
* @param {string} kind [array | boolean | float | integer | map | object | string]
* @param {string} kind [array | boolean | float | integer | json | map | object | string]
*
* @returns this
*
Expand Down
8 changes: 7 additions & 1 deletion app/web/src/components/AttributesPanel/TreeFormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1427,7 +1427,13 @@ const sourceTooltipText = computed(() => {

function resetNewValueToCurrentValue() {
newValueBoolean.value = !!currentValue.value;
newValueString.value = currentValue.value?.toString() || "";
if (currentValue.value instanceof Object) {
newValueString.value = JSON.stringify(currentValue.value, null, 2);
} else if (currentValue.value) {
newValueString.value = "";
} else {
newValueString.value = currentValue.value?.toString() || "";
}
const valAsNumber = parseFloat(currentValue.value?.toString() || "");
newValueNumber.value = Number.isNaN(valAsNumber) ? undefined : valAsNumber;
showValidationDetails.value = false;
Expand Down
13 changes: 13 additions & 0 deletions app/web/src/store/component_attributes.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ export const useComponentAttributesStore = (componentId: ComponentId) => {

const isInsert = "insert" in updatePayload;

if (!isInsert) {
const propId = updatePayload.update.propId;
const prop = this.schema?.props[propId];
if (
prop?.kind === "json" &&
typeof updatePayload.update.value === "string"
) {
updatePayload.update.value = JSON.parse(
updatePayload.update.value,
);
}
}

// If the valueid for this update does not exist in the values tree,
// we shouldn't perform the update!
if (
Expand Down
3 changes: 2 additions & 1 deletion bin/lang-js/src/asset_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ export type PropDefinitionKind =
| "boolean"
| "float"
| "integer"
| "json"
| "map"
| "object"
| "string";
Expand Down Expand Up @@ -757,7 +758,7 @@ export class PropBuilder implements IPropBuilder {
/**
* The type of the prop
*
* @param kind {PropDefinitionKind} [array | boolean | float | integer | map | object | string]
* @param kind {PropDefinitionKind} [array | boolean | float | integer | json | map | object | string]
*
* @returns this
*
Expand Down