diff --git a/src/App.tsx b/src/App.tsx
index 213d272de..6d77afa1c 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -85,9 +85,9 @@ function App() {
,
,
,
+ ,
,
,
- ,
,
,
,
diff --git a/src/ThreeEditor/components/Dialog/ClearHistoryDialog.tsx b/src/ThreeEditor/components/Dialog/ClearHistoryDialog.tsx
index 6603bafb5..e5e594ee4 100644
--- a/src/ThreeEditor/components/Dialog/ClearHistoryDialog.tsx
+++ b/src/ThreeEditor/components/Dialog/ClearHistoryDialog.tsx
@@ -1,11 +1,12 @@
import { Button } from '@mui/material';
-import { useStore } from '../../../services/StoreService';
+import { StoreContext } from '../../../services/StoreService';
import { ConcreteDialogProps, CustomDialog } from './CustomDialog';
-export function ClearHistoryDialog({ onClose }: ConcreteDialogProps) {
- const { yaptideEditor } = useStore();
-
+export function ClearHistoryDialog({
+ onClose,
+ yaptideEditor
+}: ConcreteDialogProps>>) {
return (
>>) {
const [title, setTitle] = useState(yaptideEditor?.config.getKey('project/title'));
const [description, setDescription] = useState(
yaptideEditor?.config.getKey('project/description')
diff --git a/src/ThreeEditor/components/Dialog/LoadFileDialog.tsx b/src/ThreeEditor/components/Dialog/LoadFileDialog.tsx
index 4c8ae48d0..9ae869a82 100644
--- a/src/ThreeEditor/components/Dialog/LoadFileDialog.tsx
+++ b/src/ThreeEditor/components/Dialog/LoadFileDialog.tsx
@@ -1,20 +1,21 @@
import { Button } from '@mui/material';
import Typography from '@mui/material/Typography';
-import { useStore } from '../../../services/StoreService';
+import { StoreContext } from '../../../services/StoreService';
import { EditorJson } from '../../js/EditorJson';
import { ConcreteDialogProps, CustomDialog } from './CustomDialog';
export function LoadFileDialog({
onClose,
validVersion = true,
- data
-}: ConcreteDialogProps<{
- validVersion: boolean;
- data: EditorJson;
-}>) {
- const { yaptideEditor } = useStore();
-
+ data,
+ yaptideEditor
+}: ConcreteDialogProps<
+ {
+ validVersion: boolean;
+ data: EditorJson;
+ } & Required>
+>) {
return (
>>) {
return (
) {
return (
diff --git a/src/WrapperApp/components/Simulation/SimulationCardGrid.tsx b/src/WrapperApp/components/Simulation/SimulationCardGrid.tsx
index b2206b93d..d0fca4466 100644
--- a/src/WrapperApp/components/Simulation/SimulationCardGrid.tsx
+++ b/src/WrapperApp/components/Simulation/SimulationCardGrid.tsx
@@ -14,6 +14,7 @@ import {
import { FC, useState } from 'react';
import { useDialog } from '../../../services/DialogService';
+import { useShSimulation } from '../../../services/ShSimulatorService';
import { useStore } from '../../../services/StoreService';
import { SimulatorType } from '../../../types/RequestTypes';
import { JobStatusData, SimulationInputFiles } from '../../../types/ResponseTypes';
@@ -210,7 +211,9 @@ export function PaginatedSimulationsFromBackend({
...other
}: SimulationsFromBackendProps) {
const { setTrackedId } = useStore();
- const [open] = useDialog('runSimulation');
+ const { open: openRunSimulationDialog } = useDialog('runSimulation');
+ const { yaptideEditor } = useStore();
+ const { postJobDirect, postJobBatch } = useShSimulation();
return (
@@ -222,11 +225,15 @@ export function PaginatedSimulationsFromBackend({
variant='contained'
color='info'
startIcon={}
- disabled={!isBackendAlive}
+ disabled={!Boolean(isBackendAlive && yaptideEditor)}
onClick={() =>
- open({
+ yaptideEditor &&
+ openRunSimulationDialog({
onSubmit: setTrackedId,
- simulator: SimulatorType.SHIELDHIT
+ simulator: SimulatorType.SHIELDHIT,
+ yaptideEditor,
+ postJobDirect,
+ postJobBatch
})
}>
Run new simulation
diff --git a/src/services/AuthService.tsx b/src/services/AuthService.tsx
index c74e75da0..acb4b1d73 100644
--- a/src/services/AuthService.tsx
+++ b/src/services/AuthService.tsx
@@ -84,7 +84,7 @@ const Auth = ({ children }: GenericContextProviderProps) => {
const [keyCloakInterval, setKeyCloakInterval] = useState();
const [isServerReachable, setIsServerReachable] = useState(null);
const { enqueueSnackbar } = useSnackbar();
- const [open] = useDialog('rejectKeycloak');
+ const { open: openRejectKeycloakDialog } = useDialog('rejectKeycloak');
const isAuthorized = useMemo(() => user !== null || demoMode, [demoMode, user]);
@@ -186,8 +186,9 @@ const Auth = ({ children }: GenericContextProviderProps) => {
const validUser = true;
if (!validUser)
- open({
- reason: 'You are not authorized to use this application.'
+ openRejectKeycloakDialog({
+ reason: 'You are not authorized to use this application.',
+ keycloakAuth: { keycloak, initialized }
});
else if (initialized)
return kyRef
@@ -208,14 +209,15 @@ const Auth = ({ children }: GenericContextProviderProps) => {
.catch((err: HTTPError) => {
setUser(null);
setRefreshInterval(undefined);
- open({
+ openRejectKeycloakDialog({
reason:
err.response?.status === 403
? 'You are not authorized to use this application.'
- : err.message
+ : err.message,
+ keycloakAuth: { keycloak, initialized }
});
});
- }, [initialized, keycloak, kyRef, open]);
+ }, [initialized, keycloak, kyRef, openRejectKeycloakDialog]);
useEffect(() => {
if (initialized && keycloak.authenticated)
diff --git a/src/services/DialogService.tsx b/src/services/DialogService.tsx
index ce258d06a..387449122 100644
--- a/src/services/DialogService.tsx
+++ b/src/services/DialogService.tsx
@@ -45,17 +45,21 @@ const [useDialogContext, DialogContextProvider] = createGenericContext(
name: T
-): readonly [(props: RestDialogPropsType[T]) => void, () => void, boolean];
+): {
+ open: (props: RestDialogPropsType[T]) => void;
+ close: () => void;
+ isOpen: boolean;
+};
function useDialog(
name: T
-): readonly [(props?: RestDialogPropsType[T]) => void, () => void, boolean];
+): { open: (props?: RestDialogPropsType[T]) => void; close: () => void; isOpen: boolean };
function useDialog(
name: T
-): readonly [
- ((props?: RestDialogPropsType[T]) => void) | ((props: RestDialogPropsType[T]) => void),
- () => void,
- boolean
-] {
+): {
+ open: ((props?: RestDialogPropsType[T]) => void) | ((props: RestDialogPropsType[T]) => void);
+ close: () => void;
+ isOpen: boolean;
+} {
const { openDialog, closeDialog, getIsOpen } = useDialogContext();
const open = useCallback(
(props: RestDialogPropsType[T] = {} as RestDialogPropsType[T]) => {
@@ -69,7 +73,7 @@ function useDialog(
}, [name, closeDialog]);
const isOpen = useMemo(() => getIsOpen(name), [name, getIsOpen]);
- return [open, close, isOpen] as const;
+ return { open, close, isOpen };
}
const DialogProvider = ({ children }: GenericContextProviderProps) => {
diff --git a/src/services/LoaderService.tsx b/src/services/LoaderService.tsx
index cc9658717..cfcf17b1d 100644
--- a/src/services/LoaderService.tsx
+++ b/src/services/LoaderService.tsx
@@ -43,7 +43,7 @@ const readFile = (file: File) => {
};
const Loader = ({ children }: GenericContextProviderProps) => {
- const [open] = useDialog('loadFile');
+ const { open: openLoadFileDialog } = useDialog('loadFile');
const { yaptideEditor, setResultsSimulationData, setLocalResultsSimulationData } = useStore();
const [, setUrlInPath] = useState();
@@ -53,10 +53,12 @@ const Loader = ({ children }: GenericContextProviderProps) => {
switch (type) {
case 'Editor':
- open({
- data: json,
- validVersion: json.metadata.version === JSON_VERSION
- });
+ if (yaptideEditor)
+ openLoadFileDialog({
+ data: json,
+ validVersion: json.metadata.version === JSON_VERSION,
+ yaptideEditor
+ });
break;
default:
@@ -65,7 +67,7 @@ const Loader = ({ children }: GenericContextProviderProps) => {
break;
}
},
- [open]
+ [openLoadFileDialog, yaptideEditor]
);
const loadData = useCallback(