From b891325a78b801f94d7d782a3a1ffe1910d9c55c Mon Sep 17 00:00:00 2001 From: Kuba Orlik Date: Mon, 12 Feb 2024 21:29:24 +0100 Subject: [PATCH] Fixes in state in component debugger --- package-lock.json | 8 ++++---- package.json | 2 +- src/back/jdd-components/components.ts | 3 +++ src/back/routes/components.sreact.tsx | 24 ++++++++++++++++++------ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 37af7fa..2fef5d2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15,7 +15,7 @@ "@koa/router": "^12.0.1", "@playwright/test": "^1.36.1", "@sealcode/jdd": "^0.2.13", - "@sealcode/sealgen": "^0.12.7", + "@sealcode/sealgen": "^0.12.8", "@sealcode/ts-predicates": "^0.4.3", "@types/kill-port": "^2.0.0", "get-port": "^7.0.0", @@ -1302,9 +1302,9 @@ } }, "node_modules/@sealcode/sealgen": { - "version": "0.12.7", - "resolved": "https://registry.npmjs.org/@sealcode/sealgen/-/sealgen-0.12.7.tgz", - "integrity": "sha512-RWVWiaj1/yXPdtNGedw58nKL4DYsU1JpnU6F78Ihm5cvFL8e3d3I7QLBcZAga+TN9cNZSjZCp04ABt8iXjzeqA==", + "version": "0.12.8", + "resolved": "https://registry.npmjs.org/@sealcode/sealgen/-/sealgen-0.12.8.tgz", + "integrity": "sha512-OyYBc3phnbpso/IjNNvRtR4BsIMrDFiiPmKjUp6aGWy/1b6jYcj5nu60kXcNb/pQDWJeQZzxZNypeBtP3Z+1Rg==", "dependencies": { "@koa/router": "^12.0.1", "@sealcode/ts-predicates": "^0.4.3", diff --git a/package.json b/package.json index d7e8b8f..22d3279 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "@koa/router": "^12.0.1", "@playwright/test": "^1.36.1", "@sealcode/jdd": "^0.2.13", - "@sealcode/sealgen": "^0.12.7", + "@sealcode/sealgen": "^0.12.8", "@sealcode/ts-predicates": "^0.4.3", "@types/kill-port": "^2.0.0", "get-port": "^7.0.0", diff --git a/src/back/jdd-components/components.ts b/src/back/jdd-components/components.ts index c63b7a9..528b0d2 100644 --- a/src/back/jdd-components/components.ts +++ b/src/back/jdd-components/components.ts @@ -5,3 +5,6 @@ export const registry = new Registry(); import { NiceBox } from "./nice-box/nice-box.jdd.js"; registry.add("nice-box", NiceBox); + +import { SomeOtherComponent } from "./some-other-component/some-other-component.jdd.js"; +registry.add("some-other-component", SomeOtherComponent); diff --git a/src/back/routes/components.sreact.tsx b/src/back/routes/components.sreact.tsx index fb73ae2..3936913 100644 --- a/src/back/routes/components.sreact.tsx +++ b/src/back/routes/components.sreact.tsx @@ -15,8 +15,6 @@ import objectPath from "object-path"; export const actionName = "Components"; -const rerender = "this.closest('form').requestSubmit()"; - const actions = { add_array_item: ( state: State, @@ -49,6 +47,15 @@ const actions = { args, }; }, + change_component: (state: State, inputs: Record) => { + const component_name = inputs.component; + const component = registry.get(component_name); + return { + ...state, + component: component_name, + args: component?.getExampleValues() || {}, + }; + }, } as const; type State = { @@ -60,7 +67,8 @@ export default new (class ComponentsPage extends StatefulPage {arg.values.map((v) => (