Skip to content

Commit 3d70532

Browse files
committedMar 12, 2025
Revert "Move json fields processing at meta fetching stage"
This reverts commit 1e8c0b4.
1 parent 8d484ca commit 3d70532

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed
 

‎axelor-front/src/services/client/meta-utils.ts

+10-27
Original file line numberDiff line numberDiff line change
@@ -520,18 +520,13 @@ export function processView(
520520
}
521521
}
522522

523-
[
524-
"canNew",
525-
"canView",
526-
"canEdit",
527-
"canRemove",
528-
"canSelect",
529-
"canDelete",
530-
].forEach((name) => {
531-
if (item[name] === "false" || item[name] === "true") {
532-
item[name] = item[name] === "true";
533-
}
534-
});
523+
["canNew", "canView", "canEdit", "canRemove", "canSelect", "canDelete"].forEach(
524+
(name) => {
525+
if (item[name] === "false" || item[name] === "true") {
526+
item[name] = item[name] === "true";
527+
}
528+
},
529+
);
535530

536531
if (item.items) {
537532
processView(meta, item, view);
@@ -583,20 +578,13 @@ export function processView(
583578
};
584579
let panel: Schema | null = null;
585580
let panelTab: Schema | null = null;
586-
587-
let jsonFields: JsonField[] = item.jsonFields ?? [];
588-
589-
jsonFields = item.jsonFields.filter(
581+
item.jsonFields = item.jsonFields.filter(
590582
(x: JsonField) => !(x as JsonField).forceHidden,
591583
);
592-
jsonFields.sort((x: Schema, y: Schema) => {
584+
item.jsonFields.sort((x: Schema, y: Schema) => {
593585
return x.sequence - y.sequence;
594586
});
595-
jsonFields.forEach((field: Schema) => {
596-
if (field.nameField) {
597-
field.nameColumn = field.nameField;
598-
}
599-
587+
item.jsonFields.forEach((field: Schema) => {
600588
if (field.widgetAttrs) {
601589
if (typeof field.widgetAttrs === "string") {
602590
field.widgetAttrs = JSON.parse(field.widgetAttrs);
@@ -665,11 +653,6 @@ export function processView(
665653
}
666654
});
667655

668-
item.jsonFields = jsonFields.reduce(
669-
(acc, x) => ({ ...acc, [x.name]: x }),
670-
{},
671-
);
672-
673656
if (panelTab) {
674657
editor.items?.push(panelTab);
675658
}

‎axelor-front/src/services/client/meta.types.ts

-2
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,6 @@ export interface JsonField extends Omit<Field, "type"> {
423423
columnSequence: number;
424424
visibleInGrid?: boolean;
425425

426-
nameField?: boolean;
427-
428426
jsonTarget?: string;
429427
jsonField?: string;
430428
jsonPath?: string;

‎axelor-front/src/views/form/builder/form-editors.tsx

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Box, clsx } from "@axelor/ui";
2-
import { ScopeProvider } from "bunshi/react";
32
import { SetStateAction, atom, useAtom, useAtomValue, useSetAtom } from "jotai";
3+
import { ScopeProvider } from "bunshi/react";
44
import { atomFamily, selectAtom, useAtomCallback } from "jotai/utils";
5-
import filter from "lodash/filter";
65
import getObjValue from "lodash/get";
76
import isEqual from "lodash/isEqual";
87
import isNumber from "lodash/isNumber";
8+
import filter from "lodash/filter";
99
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
1010

1111
import { MaterialIcon } from "@axelor/ui/icons/material-icon";
@@ -18,8 +18,8 @@ import { i18n } from "@/services/client/i18n";
1818
import { ViewData } from "@/services/client/meta";
1919
import {
2020
Editor,
21+
Field,
2122
FormView,
22-
JsonField,
2323
Panel,
2424
Property,
2525
Schema,
@@ -1149,7 +1149,7 @@ function JsonEditor({
11491149
);
11501150
const model = useAtomValue(modelAtom);
11511151
const jsonModel = schema.jsonModel;
1152-
const jsonFields: Record<string, JsonField> = schema.jsonFields ?? {};
1152+
const jsonFields = processJsonFields(schema);
11531153
const jsonNameField = Object.values(jsonFields).find((x) => x.nameColumn);
11541154
const jsonValueRef = useRef<DataRecord>();
11551155

@@ -1241,6 +1241,17 @@ function JsonEditor({
12411241
);
12421242
}
12431243

1244+
function processJsonFields(schema: Schema) {
1245+
const fields: Record<string, Schema> = schema.jsonFields ?? {};
1246+
return Object.entries(fields).reduce((acc, [k, v]) => {
1247+
const { nameField: nameColumn, ...field } = v;
1248+
return {
1249+
...acc,
1250+
[k]: nameColumn ? { ...field, nameColumn } : field,
1251+
};
1252+
}, {}) as Record<string, Field>;
1253+
}
1254+
12441255
function processJsonView(schema: Schema, jsonFields: any) {
12451256
const result = { ...schema, $json: true } as Schema;
12461257

‎axelor-front/src/views/form/builder/utils.ts

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import uniqueId from "lodash/uniqueId";
12
import isUndefined from "lodash/isUndefined";
23
import pick from "lodash/pick";
34
import uniq from "lodash/uniq";
4-
import uniqueId from "lodash/uniqueId";
55

66
import { DataContext, DataRecord } from "@/services/client/data.types";
77
import {
@@ -15,8 +15,8 @@ import {
1515
View,
1616
Widget,
1717
} from "@/services/client/meta.types";
18-
import { getJSON } from "@/utils/data-record";
1918
import { toCamelCase, toKebabCase, toSnakeCase } from "@/utils/names";
19+
import { getJSON } from "@/utils/data-record";
2020

2121
import {
2222
getBaseDummy,
@@ -27,8 +27,8 @@ import { moment } from "@/services/client/l10n.ts";
2727
import { MetaData, ViewData } from "@/services/client/meta";
2828
import { LoadingCache } from "@/utils/cache";
2929
import convert from "@/utils/convert";
30-
import { findViewItems } from "@/utils/schema";
3130
import { Attrs, DEFAULT_ATTRS, FormState } from "./types";
31+
import { findViewItems } from "@/utils/schema";
3232

3333
import * as WIDGETS from "../widgets";
3434

@@ -251,21 +251,19 @@ export function processContextValues(
251251
values[fieldName] = value
252252
? compactJson(value, {
253253
findItem: (jsonPath: string) => {
254-
function findTargetNames(schema: Schema): string[] {
254+
function findTargetNames(schema: Schema): Schema[] {
255255
const items =
256256
schema.type !== "panel-related" ? (schema.items ?? []) : [];
257257
const nested = items.flatMap((item) => findTargetNames(item));
258258
return [
259259
...items
260260
.filter((item) => item.json && item.name === fieldName)
261-
.map((item) => {
262-
const itemFields: Record<string, JsonField> =
263-
item.jsonFields ?? {};
264-
return Object.values(itemFields).find(
265-
(jsonItem: JsonField) => jsonItem.name === jsonPath,
266-
)?.targetName as string;
267-
})
268-
.filter(Boolean),
261+
.map(
262+
(item) =>
263+
item.jsonFields?.find(
264+
(jsonItem: JsonField) => jsonItem.name === jsonPath,
265+
)?.targetName,
266+
),
269267
...nested,
270268
];
271269
}
@@ -435,6 +433,13 @@ export function processView(
435433
);
436434
}
437435

436+
if (Array.isArray(res.jsonFields)) {
437+
res.jsonFields = res.jsonFields.reduce(
438+
(prev, field) => ({ ...prev, [field.name!]: field }),
439+
{},
440+
);
441+
}
442+
438443
return res;
439444
}
440445

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
title: Revert json field processing improvements
2+
type: fix
3+
description: |
4+
Previous version introduce json field processing improvements. Due to the nature of the change, this introduced
5+
issue in json fields behavior. This has been reverted and will be re-added on further version.

0 commit comments

Comments
 (0)
Please sign in to comment.