Skip to content

Commit

Permalink
handle multiple addons with the same url in user app dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas committed Dec 27, 2024
1 parent 1d2359c commit 5ae38f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
4 changes: 3 additions & 1 deletion viewer/components/EditDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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}
)
]}></DialogButtons>
</DialogFrame>
Expand Down
45 changes: 30 additions & 15 deletions viewer/components/UserAppDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -199,31 +198,48 @@ const TranslateUrlDialog=({resolveFunction,current})=>{
return <DialogFrame title={"loading..."}/>
}

const SelectExistingDialog=({existingAddons,resolveFunction})=>{
const dialogContext=useDialogContext();
const selist = [];
existingAddons.forEach((addon) => {
selist.push({value: addon, label: addon.title, icon: addon.icon});
})
return <DialogFrame className="selectDialog" title="Select Addon to Edit">
<SelectList list={selist} onClick={(elem)=>{
dialogContext.closeDialog();
resolveFunction(elem.value);
}}></SelectList>
<DialogButtons buttonList={[
{
name:"new",
onClick:()=>resolveFunction()
},
DBCancel()
]}/>
</DialogFrame>
}

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) =>
<SelectDialog
<SelectExistingDialog
{...props}
list={selist}
existingAddons={current}
/>
)
.then((selected) => {
if (selected.value !== undefined) {
setCurrentAddon({...selected.value, ...props.fixed});
if (selected !== undefined) {
setCurrentAddon({...selected, ...props.fixed});
}
})
.catch(() => {
Expand All @@ -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;
Expand Down

0 comments on commit 5ae38f6

Please sign in to comment.