diff --git a/.eslintrc.js b/.eslintrc.js index 3db637c39..63d3caa95 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,6 +1,8 @@ module.exports = { extends: 'erb', rules: { + // Javascript can handle cycles in dependencies + 'import/no-cycle': 'off', // A temporary hack related to IDE not resolving correct package.json 'import/no-extraneous-dependencies': 'off', 'import/no-unresolved': 'error', diff --git a/assets/locales/en/genericComponents.json b/assets/locales/en/genericComponents.json index 5b7d5165d..f0249eb4a 100644 --- a/assets/locales/en/genericComponents.json +++ b/assets/locales/en/genericComponents.json @@ -9,6 +9,7 @@ "Hide" : "Hide", "Language": "Language", "LaunchOnStartup": "Launch on startup", + "LearnMore": "Learn more", "LightMode": "Light mode", "loadingDotDotDot": "loading...", "MinorityClient" : "Minority Client", diff --git a/assets/locales/es/genericComponents.json b/assets/locales/es/genericComponents.json index 81776045a..98761f9cc 100644 --- a/assets/locales/es/genericComponents.json +++ b/assets/locales/es/genericComponents.json @@ -6,6 +6,7 @@ "FinishingUp" : "Finishing arriba...", "Language" : "Idioma", "LaunchOnStartup" : "Empieze en Startup", + "LearnMore": "Aprender más", "LightMode": "Luz modo", "MinorityClient" : "Mejor Client", "NextStep" : "Proxima step", diff --git a/src/common/nodeConfig.ts b/src/common/nodeConfig.ts index a421d4601..46e09203e 100644 --- a/src/common/nodeConfig.ts +++ b/src/common/nodeConfig.ts @@ -1,15 +1,16 @@ -type FilePathControl = { +export const FilePathControlType = 'filePath'; +export type FilePathControl = { type: 'filePath'; }; -type TextControl = { +export type TextControl = { type: 'text'; }; -type SelectTranslation = { value: string; config?: string }; -type SelectControl = { +export type SelectTranslation = { value: string; config?: string }; +export type SelectControl = { type: 'select/single'; controlTranslations: SelectTranslation[]; }; -type MultiSelectControl = { +export type MultiSelectControl = { type: 'select/multiple'; controlTranslations: SelectTranslation[]; }; diff --git a/src/renderer/Footer/DynamicNodeConfig.tsx b/src/renderer/Footer/DynamicNodeConfig.tsx deleted file mode 100644 index 0b8ef262e..000000000 --- a/src/renderer/Footer/DynamicNodeConfig.tsx +++ /dev/null @@ -1,229 +0,0 @@ -import { useEffect, useState } from 'react'; - -import { useAppSelector } from '../state/hooks'; -import { selectSelectedNode } from '../state/node'; -import { - ConfigValue, - ConfigTranslationMap, - ConfigTranslation, - ConfigTranslationControl, -} from '../../common/nodeConfig'; -import electron from '../electronGlobal'; -import Select from '../DynamicControls/Select'; -import TextArea from '../DynamicControls/TextArea'; -import Warning from '../Warning'; -import { InfoModal } from '../InfoIconButton'; -import ExternalLink from '../Generics/ExternalLink'; - -type CategoryConfig = { - category: string; - configTranslationMap: ConfigTranslationMap; -}; -const DynamicNodeConfig = () => { - const selectedNode = useAppSelector(selectSelectedNode); - const [sIsConfigDisabled, setIsConfigDisabled] = useState(true); - const [sConfigTranslationMap, setConfigTranslationMap] = - useState(); - const [sCategoryConfigs, setCategoryConfigs] = useState(); - - useEffect(() => { - let isDisabled = true; - let configTranslationMap; - console.log(selectedNode); - if (selectedNode) { - isDisabled = selectedNode.status === 'running'; - configTranslationMap = selectedNode.spec.configTranslation; - } - console.log('NodeConfig isDisabled? ', isDisabled); - setIsConfigDisabled(isDisabled); - setConfigTranslationMap(configTranslationMap); - }, [selectedNode]); - - useEffect(() => { - // category to configs - const categoryMap: Record = {}; - if (sConfigTranslationMap) { - Object.keys(sConfigTranslationMap).forEach((configKey) => { - const configTranslation: ConfigTranslation = - sConfigTranslationMap[configKey]; - const category = configTranslation.category ?? 'Other'; - if (!categoryMap[category]) { - categoryMap[category] = {}; - } - categoryMap[category][configKey] = configTranslation; - }); - } - const arr = Object.keys(categoryMap).map((category) => { - return { - category, - configTranslationMap: categoryMap[category], - }; - }); - - // Put 'Other' category at the bottom - arr.sort((x, y) => { - if (x.category === 'Other') { - return 1; - } - if (y.category === 'Other') { - return -1; - } - return 0; - }); - - setCategoryConfigs(arr); - }, [sConfigTranslationMap]); - - if (!selectedNode) { - return <>No node selected; - } - - const onNodeConfigChange = async ( - configKey: string, - newValue: ConfigValue - ) => { - // updateNode - console.log('updating node with newValue: ', newValue); - const { configValuesMap } = selectedNode.config; - const newConfig = { - ...selectedNode.config, - configValuesMap: { - ...configValuesMap, - [configKey]: newValue, - }, - }; - // console.log('updating node with newConfig: ', newConfig); - await electron.updateNode(selectedNode.id, { - config: newConfig, - }); - // console.log('updated node!!!: ', updateNode); - // todo: show user a success notification - }; - - return ( - <> - {sIsConfigDisabled && ( - -

The node must be stopped to make configuration changes.

-
- )} - {sCategoryConfigs && ( - <> - {sCategoryConfigs.map((categoryConfig) => { - const { configTranslationMap, category } = categoryConfig; - return ( -
-

{category}

- {configTranslationMap ? ( - <> - {Object.keys(configTranslationMap).map((configKey) => { - const configTranslation: ConfigTranslation = - configTranslationMap[configKey]; - - const configTranslationControl: ConfigTranslationControl = - configTranslation.uiControl; - let currentValue: string | string[] = - selectedNode.config?.configValuesMap?.[configKey]; - if (currentValue === undefined) { - if ( - configTranslation.niceNodeDefaultValue !== undefined - ) { - currentValue = configTranslation.niceNodeDefaultValue; - } else if ( - configTranslation.defaultValue !== undefined - ) { - currentValue = configTranslation.defaultValue; - } - // todo for mutli select? - } - // console.log( - // 'rendering config: ', - // configTranslation, - // currentValue - // ); - return ( -
-
- {configTranslation.displayName} - {(configTranslation.infoDescription || - configTranslation.documentation) && ( - - {configTranslation.infoDescription} - {configTranslation.defaultValue && ( -

- Default value:{' '} - {configTranslation.defaultValue} -

- )} - {configTranslation.documentation && ( - - )} -
- )} -
- {configTranslationControl?.type === 'filePath' && ( - <> - {`Current folder: ${currentValue}`} - - - )} - {configTranslationControl?.type === 'text' && ( -