From 9b4e5518c551d216a179ba568176c0405c2fff5b Mon Sep 17 00:00:00 2001 From: Jarek Danielak Date: Wed, 5 Mar 2025 20:14:19 +0100 Subject: [PATCH] feat: add Settings Plugin UI for app settings. Related to https://github.com/camunda/camunda-modeler/issues/2913 --- client/src/plugins/index.js | 4 +- client/src/plugins/settings/SettingsForm.js | 91 +++++++++++++++++++ client/src/plugins/settings/SettingsPlugin.js | 78 ++++++++++++++++ .../src/plugins/settings/SettingsPlugin.less | 15 +++ client/src/plugins/settings/index.js | 11 +++ 5 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 client/src/plugins/settings/SettingsForm.js create mode 100644 client/src/plugins/settings/SettingsPlugin.js create mode 100644 client/src/plugins/settings/SettingsPlugin.less create mode 100644 client/src/plugins/settings/index.js diff --git a/client/src/plugins/index.js b/client/src/plugins/index.js index dcbb66917a..c58040adb0 100644 --- a/client/src/plugins/index.js +++ b/client/src/plugins/index.js @@ -20,6 +20,7 @@ import UserJourneyStatistics from './user-journey-statistics'; import VersionInfo from './version-info'; import ZeebePlugin from './zeebe-plugin'; import ConnectorTemplates from './connector-templates'; +import Settings from './settings'; export default [ CamundaPlugin, @@ -33,5 +34,6 @@ export default [ VersionInfo, ZeebePlugin, UserJourneyStatistics, - ConnectorTemplates + ConnectorTemplates, + Settings ]; diff --git a/client/src/plugins/settings/SettingsForm.js b/client/src/plugins/settings/SettingsForm.js new file mode 100644 index 0000000000..3a1a36ac5c --- /dev/null +++ b/client/src/plugins/settings/SettingsForm.js @@ -0,0 +1,91 @@ +/** + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. + * + * Camunda licenses this file to you under the MIT; you may not use this file + * except in compliance with the MIT License. + */ + +import React, { useEffect } from 'react'; + +import { Field, Form, useFormikContext } from 'formik'; +import { Section, TextInput, CheckBox } from '../../shared/ui'; + + +export function SettingsForm(props) { + + const { schema, values } = props; + + const { setFieldValue } = useFormikContext(); + + useEffect(() => { + + Object.entries(values).forEach(([ id, value ]) => { + console.log('set', + id, + value + ); + setFieldValue(id, value); + }); + + }, [ values ]); + + return (
+ + {Object.entries(schema).map(([ id, { title, properties } ]) => ( +
+ { title } + + {Object.entries(properties).map(([ key, props ]) => ( + + ))} + +
+ ))} + +
+ +
+ +
+
+
+
); +} + +function SettingsField(props) { + + const { id, type, label, description } = props; + + if (type === 'text') { + return ; + } + + if (type === 'boolean') { + return ; + } + + return null; +} \ No newline at end of file diff --git a/client/src/plugins/settings/SettingsPlugin.js b/client/src/plugins/settings/SettingsPlugin.js new file mode 100644 index 0000000000..d51e53e7fb --- /dev/null +++ b/client/src/plugins/settings/SettingsPlugin.js @@ -0,0 +1,78 @@ +/** + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. + * + * Camunda licenses this file to you under the MIT; you may not use this file + * except in compliance with the MIT License. + */ + +import React, { useEffect, useState } from 'react'; + +import { forEach } from 'min-dash'; + +import { Formik } from 'formik'; + +import { Modal } from '../../shared/ui'; + +import { SettingsForm } from './SettingsForm'; + +import * as css from './SettingsPlugin.less'; + +export default function SettingsPlugin(props) { + + const { + settings: settingsProvider, + subscribe, + } = props; + + const [ open, setOpen ] = useState(false); + const [ schema, setSchema ] = useState({}); + const [ values, setValues ] = useState({}); + + const loadSettings = () => { + setSchema(settingsProvider.getSchema()); + setValues(settingsProvider.getAll()); + }; + + const handleSave = (values) => { + const flattenValues = {}; + + forEach(values, (properties, prefix) => { + forEach(properties, (value, name) => { + flattenValues[`${prefix}.${name}`] = value; + }); + }); + + settingsProvider.set(flattenValues); + }; + + useEffect(() => { + subscribe('app.settings-open', () => { + setOpen(true); + }); + }, [ ]); + + useEffect(() => { + loadSettings(); + }, [ open ]); + + if (!open) { + return null; + } + + return ( + setOpen(false) }> +
+

Settings

+ + + +
+
+ ); +} \ No newline at end of file diff --git a/client/src/plugins/settings/SettingsPlugin.less b/client/src/plugins/settings/SettingsPlugin.less new file mode 100644 index 0000000000..dec15af576 --- /dev/null +++ b/client/src/plugins/settings/SettingsPlugin.less @@ -0,0 +1,15 @@ +:local(.SettingsPlugin) { + margin: 20px; + + .form-group p { + margin-bottom: 15px !important; + } + + .controls { + height: 60px; + margin-right: 10px; + display: flex; + justify-content: flex-end; + align-items: center; + } +} \ No newline at end of file diff --git a/client/src/plugins/settings/index.js b/client/src/plugins/settings/index.js new file mode 100644 index 0000000000..9874c9570f --- /dev/null +++ b/client/src/plugins/settings/index.js @@ -0,0 +1,11 @@ +/** + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. + * + * Camunda licenses this file to you under the MIT; you may not use this file + * except in compliance with the MIT License. + */ + +export { default } from './SettingsPlugin'; \ No newline at end of file