From 5ae38f63ce67a21cfcabd033f45c1f6a145a720d Mon Sep 17 00:00:00 2001 From: andreas Date: Fri, 27 Dec 2024 18:34:23 +0100 Subject: [PATCH] handle multiple addons with the same url in user app dialog --- viewer/components/EditDialog.jsx | 4 ++- viewer/components/UserAppDialog.jsx | 45 +++++++++++++++++++---------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/viewer/components/EditDialog.jsx b/viewer/components/EditDialog.jsx index 99260b01..b7da49be 100644 --- a/viewer/components/EditDialog.jsx +++ b/viewer/components/EditDialog.jsx @@ -18,6 +18,8 @@ export const EditDialog = ({data, title, language, resolveFunction, saveFunction const flask = useRef(); const editElement = useRef(); const [changed, setChanged] = useState(false); + const everChanged=useRef(false); + if (changed)everChanged.current=true; const dialogContext = useDialogContext(); const [uploadSequence, setUploadSequence] = useState(0); useEffect(() => { @@ -82,7 +84,7 @@ export const EditDialog = ({data, title, language, resolveFunction, saveFunction DBCancel(), DBOk(() => { promiseResolveHelper({ok: dialogContext.closeDialog}, resolveFunction, flask.current.getCode()); - }, {disabled: !changed, close: false} + }, {disabled: !everChanged.current, close: false} ) ]}> diff --git a/viewer/components/UserAppDialog.jsx b/viewer/components/UserAppDialog.jsx index 14e8ead8..77515c82 100644 --- a/viewer/components/UserAppDialog.jsx +++ b/viewer/components/UserAppDialog.jsx @@ -2,8 +2,7 @@ import React, {useEffect, useState} from 'react'; import PropTypes from 'prop-types'; import OverlayDialog, { DialogRow, - promiseResolveHelper, SelectDialog, - SelectList, + promiseResolveHelper, SelectList, showPromiseDialog, useDialogContext } from './OverlayDialog.jsx'; @@ -199,31 +198,48 @@ const TranslateUrlDialog=({resolveFunction,current})=>{ return } +const SelectExistingDialog=({existingAddons,resolveFunction})=>{ + const dialogContext=useDialogContext(); + const selist = []; + existingAddons.forEach((addon) => { + selist.push({value: addon, label: addon.title, icon: addon.icon}); + }) + return + { + dialogContext.closeDialog(); + resolveFunction(elem.value); + }}> + resolveFunction() + }, + DBCancel() + ]}/> + +} + const UserAppDialog = (props) => { const [currentAddon, setCurrentAddon] = useState({...props.addon, ...props.fixed}); const dialogContext = useDialogContext(); - const initiallyLoaded = (props.fixed || {}).url === undefined || props.addon !== undefined; - const [loaded, setLoaded] = useState(initiallyLoaded); - const [internal, setInternal] = useState(!(initiallyLoaded && (props.addon || {}).keepUrl)); + const fixed = props.fixed || {}; + const shouldFind = ! fixed.name && ( fixed.url && ! props.addon); + const [loaded, setLoaded] = useState(!shouldFind); + const [internal, setInternal] = useState(!(!shouldFind && (props.addon || {}).keepUrl)); const fillLists = () => { if (!loaded) Addons.readAddOns() .then((addons) => { let current = Addons.findAddonByUrl(addons, props.fixed.url,true) if (current.length) { - const selist = []; - selist.push({label: '--Create New --'}); - current.forEach((addon) => { - selist.push({value: addon, label: addon.title, icon: addon.icon}); - }) showPromiseDialog(dialogContext, (props) => - ) .then((selected) => { - if (selected.value !== undefined) { - setCurrentAddon({...selected.value, ...props.fixed}); + if (selected !== undefined) { + setCurrentAddon({...selected, ...props.fixed}); } }) .catch(() => { @@ -238,7 +254,6 @@ const UserAppDialog = (props) => { useEffect(() => { fillLists(); }, []); - let fixed = props.fixed || {}; let canEdit = unsetOrTrue(currentAddon.canDelete); if (!loaded) canEdit = false; let fixedUrl = fixed.url !== undefined;