diff --git a/src/Components/API/api.ts b/src/Components/API/api.ts index b366e6e..6d5ac3b 100644 --- a/src/Components/API/api.ts +++ b/src/Components/API/api.ts @@ -33,8 +33,8 @@ export async function FetchConfiguration(): Promise { }); } -export async function SetContainerList(request: ISetContainerListRequest): Promise { - const url = import.meta.env.VITE_API_SET_CONTAINER_LIST_URL; +export async function SetContainerList(request: ISetContainerListRequest, configurationUrl?: string): Promise { + const url = configurationUrl ?? import.meta.env.VITE_API_SET_CONTAINER_LIST_URL; const dataParsed = JSON.stringify(request, GetCircularReplacerToDotnet()); // The test library cannot use the Fetch API // @ts-expect-error diff --git a/src/Components/App/Actions/MenuActions.ts b/src/Components/App/Actions/MenuActions.ts index 500269a..2187b47 100644 --- a/src/Components/App/Actions/MenuActions.ts +++ b/src/Components/App/Actions/MenuActions.ts @@ -6,6 +6,7 @@ import { LoadState } from './Load'; import { DISABLE_API, GetDefaultEditorState } from '../../../utils/default'; export function NewEditor( + editorState: IEditorState, setEditorState: Dispatch>, setLoaded: Dispatch> ): void { @@ -14,6 +15,10 @@ export function NewEditor( return; } + if (editorState.configuration !== undefined) { + return; + } + // Fetch the configuration from the API FetchConfiguration() .then((configuration: IConfiguration) => { diff --git a/src/Components/App/App.tsx b/src/Components/App/App.tsx index 4c52c8e..639d1de 100644 --- a/src/Components/App/App.tsx +++ b/src/Components/App/App.tsx @@ -130,7 +130,7 @@ export function App(props: IAppProps): JSX.Element { > NewEditor( - setEditorState, setLoaded + editorState, setEditorState, setLoaded )} loadEditor={(files: FileList | null) => LoadEditor( files, diff --git a/src/Components/Editor/Actions/ContextMenuActions.ts b/src/Components/Editor/Actions/ContextMenuActions.ts index 6b0d24d..e5f8ea0 100644 --- a/src/Components/Editor/Actions/ContextMenuActions.ts +++ b/src/Components/Editor/Actions/ContextMenuActions.ts @@ -44,7 +44,7 @@ export function GetAction( }; /* eslint-enable */ - SetContainerList(request) + SetContainerList(request, configuration.APIConfiguration?.apiSetContainerListUrl) .then((response: ISetContainerListResponse) => { HandleSetContainerList( action, diff --git a/src/Components/Editor/Editor.tsx b/src/Components/Editor/Editor.tsx index 11aabd2..507fa58 100644 --- a/src/Components/Editor/Editor.tsx +++ b/src/Components/Editor/Editor.tsx @@ -286,6 +286,7 @@ export function Editor(props: IEditorProps): JSX.Element { availableContainers={configuration.AvailableContainers} availableSymbols={configuration.AvailableSymbols} categories={configuration.Categories} + apiConfiguration={configuration.APIConfiguration} selectContainer={(container) => setNewHistory( SelectContainer( container, diff --git a/src/Components/UI/UI.tsx b/src/Components/UI/UI.tsx index 988dca2..c9afe1e 100644 --- a/src/Components/UI/UI.tsx +++ b/src/Components/UI/UI.tsx @@ -19,6 +19,7 @@ import { IMessage } from '../../Interfaces/IMessage'; import { DISABLE_API } from '../../utils/default'; import { UseWorker, UseAsync } from './UseWorker'; import { FindContainerById } from '../../utils/itertools'; +import { IAPIConfiguration } from '../../Interfaces/IAPIConfiguration'; export interface IUIProps { selectedContainer: IContainerModel | undefined @@ -28,6 +29,7 @@ export interface IUIProps { availableContainers: IAvailableContainer[] availableSymbols: IAvailableSymbol[] categories: ICategory[] + apiConfiguration: IAPIConfiguration | undefined selectContainer: (containerId: string) => void deleteContainer: (containerId: string) => void onPropertyChange: (key: string, value: string | number | boolean | number[], type?: PropertyType) => void @@ -73,11 +75,13 @@ export function UI(props: IUIProps): JSX.Element { if (window.Worker && !DISABLE_API) { UseWorker( props.current, + props.apiConfiguration?.apiGetFeedbackUrl, setMessages ); } else if (!DISABLE_API) { UseAsync( props.current, + props.apiConfiguration?.apiGetFeedbackUrl, setMessages ); } diff --git a/src/Components/UI/UseWorker.tsx b/src/Components/UI/UseWorker.tsx index 5047bcb..7a6a8f0 100644 --- a/src/Components/UI/UseWorker.tsx +++ b/src/Components/UI/UseWorker.tsx @@ -10,6 +10,7 @@ const myWorker = window.Worker && new Worker('workers/message_worker.js'); export function UseWorker( state: IHistoryState, + configurationUrl: string | undefined, setMessages: React.Dispatch>): void { React.useEffect(() => { // use webworker for the stringify to avoid freezing @@ -30,6 +31,7 @@ export function UseWorker( } export function UseAsync( state: IHistoryState, + configurationUrl: string | undefined, setMessages: React.Dispatch>): void { React.useEffect(() => { const request: IGetFeedbackRequest = { diff --git a/src/Interfaces/IAPIConfiguration.ts b/src/Interfaces/IAPIConfiguration.ts new file mode 100644 index 0000000..1a553fc --- /dev/null +++ b/src/Interfaces/IAPIConfiguration.ts @@ -0,0 +1,5 @@ +export interface IAPIConfiguration { + apiFetchUrl?: string + apiSetContainerListUrl?: string + apiGetFeedbackUrl?: string +} diff --git a/src/Interfaces/IConfiguration.ts b/src/Interfaces/IConfiguration.ts index 98e0eea..12b0452 100644 --- a/src/Interfaces/IConfiguration.ts +++ b/src/Interfaces/IConfiguration.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ +import { IAPIConfiguration } from './IAPIConfiguration'; import { IAvailableContainer } from './IAvailableContainer'; import { IAvailableSymbol } from './IAvailableSymbol'; import { ICategory } from './ICategory'; @@ -11,4 +12,5 @@ export interface IConfiguration { Categories: ICategory[] Patterns: IPattern[] MainContainer: IAvailableContainer + APIConfiguration?: IAPIConfiguration }