From 8fe9a06bfa748e301483cad045ea4becb112773c Mon Sep 17 00:00:00 2001 From: malmert Date: Sun, 1 Mar 2026 00:29:05 +0100 Subject: [PATCH] start scripting frontend --- .../src/components/FirewallRulesetViewer.tsx | 5 +- frontend/src/components/ScriptManager.tsx | 458 ++++++++++++++++++ frontend/src/pages/Scripting.tsx | 55 ++- 3 files changed, 496 insertions(+), 22 deletions(-) create mode 100644 frontend/src/components/ScriptManager.tsx diff --git a/frontend/src/components/FirewallRulesetViewer.tsx b/frontend/src/components/FirewallRulesetViewer.tsx index 4d9200a..57fc057 100644 --- a/frontend/src/components/FirewallRulesetViewer.tsx +++ b/frontend/src/components/FirewallRulesetViewer.tsx @@ -292,7 +292,7 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }: {tablesToRender.length === 0 && ( @@ -310,7 +310,7 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }:
- Table "{table.name}" + Table {table.name} Family: {table.family ?? 'unknown'}   Chains: {table.chains.length}  {' '} @@ -405,6 +405,7 @@ export default function FirewallTables({ tables, error, refreshRules: refresh }: + + + + + + + + + {/* Upload Modal */} + { + setUploadModalVisible(false); + form.resetFields(); + }} + footer={null} + > +
+ + + + + + + false} maxCount={1}> + + + + + + + + false} maxCount={1}> + + + + + + + + + + + + + + + + +
+ + {/* Editor Modal (open existing script) */} + setEditorModalVisible(false)} + width={900} + footer={ + + + + + + ), + icon: null, + okButtonProps: { style: { display: 'none' } }, + cancelButtonProps: { style: { display: 'none' } }, + }); + }} + > + Save as... + + + + } + > + + + + {/* Enable Modal */} + { + setEnableModalVisible(false); + setEnableTarget(null); + }} + footer={null} + > +
+ + + + + + + + + + + + + + + + + + + + +
+ + ); +} diff --git a/frontend/src/pages/Scripting.tsx b/frontend/src/pages/Scripting.tsx index 18bd14f..a0364f9 100644 --- a/frontend/src/pages/Scripting.tsx +++ b/frontend/src/pages/Scripting.tsx @@ -1,31 +1,46 @@ import { Card, Tabs } from 'antd'; -import { useState } from 'react'; +import React, { useRef, useState } from 'react'; import PythonEditor from '../components/PythonEditor'; +import ScriptsManager from '../components/ScriptManager'; const TwoTabsPage: React.FC = () => { + // Editor state: when a saved script is "opened" from the list, we set this const [code, setCode] = useState("print('hello world')\n"); - - const tabItems = [ - { - key: '1', - label: 'Saved Scripts', - children: <>, - }, - { - key: '2', - label: 'Custom Script', - children: ( -
-

Python Editor

- -
- ), - }, - ]; + // A way for ScriptsManager to open a script into the editor: + const editorSetRef = useRef<(code: string) => void>(() => {}); return ( - + { + setCode(scriptCode); + // switch to editor tab programmatically? keep simple — user can switch + }} + /> + ), + }, + { + key: '2', + label: 'Custom Script', + children: ( +
+

Python Editor

+
+ {/* Buttons could be added here for "Run", "Save", "Upload" etc. */} +
+ +
+ ), + }, + ]} + />
); };