From 8642879435da783ac8812b17ced8903d8a7b4f22 Mon Sep 17 00:00:00 2001 From: Eduard Carreras Date: Tue, 29 Oct 2024 14:47:12 +0100 Subject: [PATCH 1/4] feat(json): add json field (#645) [skip ci] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(json): add json field * fix: adjustments in json widget * fix: add onchange pending prop --------- Co-authored-by: Marc Güell Segarra --- src/common/Field.tsx | 2 +- src/widgets/WidgetFactory.tsx | 1 + src/widgets/custom/CodeEditor.tsx | 59 ++++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/src/common/Field.tsx b/src/common/Field.tsx index 588988e09..1b6ef97a2 100644 --- a/src/common/Field.tsx +++ b/src/common/Field.tsx @@ -1,4 +1,4 @@ -import React, { useContext } from "react"; +import React from "react"; import { Form, Row, Col } from "antd"; import { Field as FieldOoui, Label as LabelOoui } from "@gisce/ooui"; import Label from "@/widgets/base/Label"; diff --git a/src/widgets/WidgetFactory.tsx b/src/widgets/WidgetFactory.tsx index b21f7513e..c404296c2 100644 --- a/src/widgets/WidgetFactory.tsx +++ b/src/widgets/WidgetFactory.tsx @@ -122,6 +122,7 @@ const getWidgetType = (type: string) => { case "arrow_steps": return ArrowStepsField; case "codeeditor": + case "json": return CodeEditor; case "comments_timeline": return CommentsTimelineField; diff --git a/src/widgets/custom/CodeEditor.tsx b/src/widgets/custom/CodeEditor.tsx index 86cc9884f..92c105454 100644 --- a/src/widgets/custom/CodeEditor.tsx +++ b/src/widgets/custom/CodeEditor.tsx @@ -1,4 +1,4 @@ -import { useContext } from "react"; +import { useCallback, useContext, useMemo } from "react"; import Editor from "@monaco-editor/react"; import { FormContext, FormContextType } from "@/context/FormContext"; import { CodeEditor as CodeEditorOoui } from "@gisce/ooui"; @@ -6,30 +6,57 @@ import { CodeEditor as CodeEditorOoui } from "@gisce/ooui"; import Field from "@/common/Field"; import { WidgetProps } from "@/types"; -type CodeEditorProps = WidgetProps & { +export type CodeEditorProps = WidgetProps & { ooui: CodeEditorOoui; }; export const CodeEditor = (props: CodeEditorProps) => { - const { ooui } = props; + return ( + + + + ); +}; + +export const CodeEditorInput = ( + props: CodeEditorProps & { value?: any; onChange?: (value: any) => void }, +) => { + const { ooui, value, onChange } = props; const { lang, height, readOnly } = ooui; const formContext = useContext(FormContext) as FormContextType; const { elementHasLostFocus } = formContext || {}; - const onMount = (editor: any) => { - editor.onDidBlurEditorWidget(elementHasLostFocus); - }; + const onMount = useCallback( + (editor: any) => { + if (elementHasLostFocus) { + editor.onDidBlurEditorWidget(() => elementHasLostFocus()); + } + }, + [elementHasLostFocus], + ); + + const adjustedValue = useMemo(() => { + if (lang === "json" && typeof value === "object") { + try { + return JSON.stringify(value, null, "\t"); + } catch (error) { + console.error("Error stringifying JSON:", error); + return ""; + } + } + return value; + }, [lang, value]); return ( - - - + ); }; From 6b5cb2ec11dac9cf01efbfe68655c024056afa87 Mon Sep 17 00:00:00 2001 From: Gisce Date: Tue, 29 Oct 2024 15:03:15 +0100 Subject: [PATCH 2/4] feat: update gisce/ooui to v2.14.0 (#648) https://github.com/gisce/ooui/releases/tag/v2.14.0 Co-authored-by: mguellsegarra <5711443+mguellsegarra@users.noreply.github.com> --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7fbe5f75a..24233cc5c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "dependencies": { "@ant-design/plots": "^1.0.9", "@gisce/fiber-diagram": "2.1.1", - "@gisce/ooui": "2.13.2", + "@gisce/ooui": "2.14.0", "@gisce/react-formiga-components": "1.8.0", "@gisce/react-formiga-table": "1.8.3", "@monaco-editor/react": "^4.4.5", @@ -3370,9 +3370,9 @@ } }, "node_modules/@gisce/ooui": { - "version": "2.13.2", - "resolved": "https://registry.npmjs.org/@gisce/ooui/-/ooui-2.13.2.tgz", - "integrity": "sha512-GQgHANcpSnegI2/kv1qBq7FLpe/P95pDwPUcxj02/52dz1fbthqT5JbTrNbE6BwZNbRNoZKlnaRGI1EL/Ick3A==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/@gisce/ooui/-/ooui-2.14.0.tgz", + "integrity": "sha512-K+2hSzuyvHJspW6DMTHrz5TENribGnUcQxOGVgipqkUoAW4AkPGd7CUYSc9xdN62YmRF7sQ7sNJrd2rLZSPFwg==", "dependencies": { "@gisce/conscheck": "1.0.9", "html-entities": "^2.3.3", diff --git a/package.json b/package.json index b46594511..05d2b9d79 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "dependencies": { "@ant-design/plots": "^1.0.9", "@gisce/fiber-diagram": "2.1.1", - "@gisce/ooui": "2.13.2", + "@gisce/ooui": "2.14.0", "@gisce/react-formiga-components": "1.8.0", "@gisce/react-formiga-table": "1.8.3", "@monaco-editor/react": "^4.4.5", From 358c1e63bc19b096973e5c254ab5b2a273e5d397 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 29 Oct 2024 14:04:44 +0000 Subject: [PATCH 3/4] chore(release): 2.29.0 [skip ci] # [2.29.0](https://github.com/gisce/react-ooui/compare/v2.28.4...v2.29.0) (2024-10-29) ### Features * **json:** add json field ([#645](https://github.com/gisce/react-ooui/issues/645)) [skip ci] ([8642879](https://github.com/gisce/react-ooui/commit/8642879435da783ac8812b17ced8903d8a7b4f22)) * update gisce/ooui to v2.14.0 ([#648](https://github.com/gisce/react-ooui/issues/648)) ([6b5cb2e](https://github.com/gisce/react-ooui/commit/6b5cb2ec11dac9cf01efbfe68655c024056afa87)) --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 24233cc5c..294f8ff15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/react-ooui", - "version": "2.28.4", + "version": "2.29.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gisce/react-ooui", - "version": "2.28.4", + "version": "2.29.0", "dependencies": { "@ant-design/plots": "^1.0.9", "@gisce/fiber-diagram": "2.1.1", diff --git a/package.json b/package.json index 05d2b9d79..d6ffb7155 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/react-ooui", - "version": "2.28.4", + "version": "2.29.0", "engines": { "node": "20.5.0" }, From a15e850952a92cd68b7995cdfd242d57e4cfd789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Fri, 1 Nov 2024 10:13:05 +0100 Subject: [PATCH 4/4] fix: do not use infinite tree's when tree is expandable https://github.com/gisce/webclient/issues/1330 --- src/views/actionViews/TreeActionView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/actionViews/TreeActionView.tsx b/src/views/actionViews/TreeActionView.tsx index f9a45fc08..b66dfdaac 100644 --- a/src/views/actionViews/TreeActionView.tsx +++ b/src/views/actionViews/TreeActionView.tsx @@ -45,10 +45,10 @@ export const TreeActionView = (props: TreeActionViewProps) => { } = props; const isInfiniteTree = useMemo(() => { - if (!treeView?.arch) { + if (!treeView?.arch || treeView.isExpandable) { return false; } - const tagValue = extractTreeXmlAttribute(treeView?.arch, "infinite"); + const tagValue = extractTreeXmlAttribute(treeView.arch, "infinite"); return tagValue === "1"; }, [treeView]);