From 481a31f846f2191b58b32853dd4e5f966501ecce Mon Sep 17 00:00:00 2001 From: Baxter Date: Mon, 28 Apr 2025 16:13:05 -0400 Subject: [PATCH 1/2] feat(renderer): streamline variable creation for notebook, cell, and block --- libs/renderer/src/store/state/state.store.ts | 28 +++++++++++++++++++ .../components/designer/AddBlocksMenuCard.tsx | 16 ++++++++++- .../designer/DeleteDuplicateMask.tsx | 22 ++++++++++++++- .../components/notebook/NewQueryOverlay.tsx | 4 +-- .../components/notebook/NotebookAddCell.tsx | 11 ++++++++ 5 files changed, 77 insertions(+), 4 deletions(-) diff --git a/libs/renderer/src/store/state/state.store.ts b/libs/renderer/src/store/state/state.store.ts index dd3d8954a3..0c62e5b0b4 100644 --- a/libs/renderer/src/store/state/state.store.ts +++ b/libs/renderer/src/store/state/state.store.ts @@ -1300,8 +1300,36 @@ export class StateStore { this, ); + // TODO: Do we want this to be done here + + // Automate variable creation for notebook and new cell + this.dispatch({ + message: ActionMessages.ADD_VARIABLE, + payload: { + id: queryId, + type: "query", + to: queryId, + isOutput: true + } + }) + + Object.entries(this._store.queries[queryId].cells).forEach((c) => { + // Automate variable creation for notebook and new cell + const cId = c[0] + this.dispatch({ + message: ActionMessages.ADD_VARIABLE, + payload: { + id: `${queryId}--${cId}`, + type: "cell", + to: queryId, + cellId: cId + } + }) + }) + this._store.executionOrder.push(queryId); + return queryId; }; diff --git a/packages/client/src/components/designer/AddBlocksMenuCard.tsx b/packages/client/src/components/designer/AddBlocksMenuCard.tsx index 92aa48884e..8275dc87ae 100644 --- a/packages/client/src/components/designer/AddBlocksMenuCard.tsx +++ b/packages/client/src/components/designer/AddBlocksMenuCard.tsx @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react'; import { observer } from 'mobx-react-lite'; import { ReportRounded } from '@mui/icons-material'; -import { ActionMessages, useBlocks } from '@semoss/renderer'; +import { ActionMessages, INPUT_BLOCK_TYPES, useBlocks } from '@semoss/renderer'; import { styled, Card, @@ -182,6 +182,20 @@ export const AddBlocksMenuCard = observer((props: AddBlocksMenuItemProps) => { } } + // TODO: REFACTOR + // Add variables for all blocks that are inputs from user + if (INPUT_BLOCK_TYPES.indexOf(item.json.widget) > -1) { + state.dispatch({ + message: ActionMessages.ADD_VARIABLE, + payload: { + id: id, + type: 'block', + to: id, + isInput: true, + }, + }); + } + // clear the drag designer.deactivateDrag(); diff --git a/packages/client/src/components/designer/DeleteDuplicateMask.tsx b/packages/client/src/components/designer/DeleteDuplicateMask.tsx index 8142495aaa..05a30e0ce1 100644 --- a/packages/client/src/components/designer/DeleteDuplicateMask.tsx +++ b/packages/client/src/components/designer/DeleteDuplicateMask.tsx @@ -8,7 +8,12 @@ import { ContentCopy, Delete, DeleteOutline } from '@mui/icons-material'; import { getRelativeSize, getBlockElement } from '@/stores'; import { useDesigner } from '@/hooks'; -import { BlockJSON, ActionMessages, useBlocks } from '@semoss/renderer'; +import { + BlockJSON, + ActionMessages, + useBlocks, + INPUT_BLOCK_TYPES, +} from '@semoss/renderer'; const STYLED_BUTTON_GROUP_ICON_BUTTON_WIDTH = 48; const STYLED_BUTTON_GROUP_ICON_BUTTON_HEIGHT = 32; @@ -236,6 +241,21 @@ export const DeleteDuplicateMask = observer( }, }); + // TODO: REFACTOR + // Add variables for all blocks that are inputs from user + // TODO: What about grouping of inputs + if (INPUT_BLOCK_TYPES.indexOf(block.widget) > -1) { + state.dispatch({ + message: ActionMessages.ADD_VARIABLE, + payload: { + id: id as string, + type: 'block', + to: id as string, + isInput: true, + }, + }); + } + designer.setSelected(id ? (id as string) : ''); }; diff --git a/packages/client/src/components/notebook/NewQueryOverlay.tsx b/packages/client/src/components/notebook/NewQueryOverlay.tsx index 6c897793f2..56f5f3c08c 100644 --- a/packages/client/src/components/notebook/NewQueryOverlay.tsx +++ b/packages/client/src/components/notebook/NewQueryOverlay.tsx @@ -58,7 +58,7 @@ export const NewQueryOverlay = observer( if (!data.ID) { setError('ID', { type: 'manual', - message: `Query Id is required`, + message: `Notebook Id is required`, }); return; } @@ -67,7 +67,7 @@ export const NewQueryOverlay = observer( if (state.queries[data.ID] || state.blocks[data.ID]) { setError('ID', { type: 'manual', - message: `Query Id ${data.ID} already exists`, + message: `Notebook Id ${data.ID} already exists`, }); return; } diff --git a/packages/client/src/components/notebook/NotebookAddCell.tsx b/packages/client/src/components/notebook/NotebookAddCell.tsx index b3eb27daf6..311cb09e84 100644 --- a/packages/client/src/components/notebook/NotebookAddCell.tsx +++ b/packages/client/src/components/notebook/NotebookAddCell.tsx @@ -213,6 +213,17 @@ export const NotebookAddCell = observer( config: config as Omit, }, }); + + state.dispatch({ + message: ActionMessages.ADD_VARIABLE, + payload: { + id: `${query.id}--${newCellId}`, + type: 'cell', + to: query.id, + cellId: newCellId, + }, + }); + notebook.selectCell(query.id, newCellId); } catch (e) { console.error(e); From cd04e253ead6333433bf16538f45d9441e1fd993 Mon Sep 17 00:00:00 2001 From: Baxter Date: Tue, 29 Apr 2025 10:27:32 -0400 Subject: [PATCH 2/2] fix(renderer): fix queryInputSettings for when it searches for a cell that doesn't exist --- .../custom/QueryInputSettings.tsx | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/libs/renderer/src/components/block-settings/custom/QueryInputSettings.tsx b/libs/renderer/src/components/block-settings/custom/QueryInputSettings.tsx index d0baebdfea..bf47890dd3 100644 --- a/libs/renderer/src/components/block-settings/custom/QueryInputSettings.tsx +++ b/libs/renderer/src/components/block-settings/custom/QueryInputSettings.tsx @@ -279,33 +279,38 @@ export const QueryInputSettings = observer( if (variable.type === "query") { const q = state.getQuery(variable.to); - for (const f in q._exposed) { - pathMap[`${alias}.${f}`] = { - id: `${alias}.${f}`, - path: `${alias}.${f}`, - type: typeof q[f], // TODO: get value - display: `${alias}.${f}`, - blockType: "query-prop", - variabilized: true, - groupAlias: groupAliasMapper("query-prop"), - }; + if(q) { + for (const f in q._exposed) { + pathMap[`${alias}.${f}`] = { + id: `${alias}.${f}`, + path: `${alias}.${f}`, + type: typeof q[f], // TODO: get value + display: `${alias}.${f}`, + blockType: "query-prop", + variabilized: true, + groupAlias: groupAliasMapper("query-prop"), + }; + } } } if (variable.type === "cell") { const q = state.getQuery(variable.to); - const c = q.getCell(variable.cellId); - for (const f in c._exposed) { - pathMap[`${alias}.${f}`] = { - id: `${alias}.${f}`, - path: `${alias}.${f}`, - type: typeof c[f], // TODO: get value - display: `${alias}.${f}`, - blockType: "cell-prop", - variabilized: true, - groupAlias: groupAliasMapper("cell-prop"), - }; + if(q) { + const c = q.getCell(variable.cellId); + + for (const f in c._exposed) { + pathMap[`${alias}.${f}`] = { + id: `${alias}.${f}`, + path: `${alias}.${f}`, + type: typeof c[f], // TODO: get value + display: `${alias}.${f}`, + blockType: "cell-prop", + variabilized: true, + groupAlias: groupAliasMapper("cell-prop"), + }; + } } } },