Merged PR 194: Added option to disable any API call

Added option to disable any API call
Fix http.js and node-http.js
Fix MainContainer not using IAvailableContainer from MainContainer
Fix generate_dts.py script
More docs
Fix MainContainer default style. Extend config will now be taken into account. But Main container can still have its own type.
This commit is contained in:
Eric Nguyen 2022-09-23 15:59:42 +00:00
parent 8ba19cc96b
commit 3ecff4cf01
10 changed files with 648 additions and 570 deletions

View file

@ -3,12 +3,17 @@ import { IConfiguration } from '../../../Interfaces/IConfiguration';
import { FetchConfiguration } from '../../API/api';
import { IEditorState } from '../../../Interfaces/IEditorState';
import { LoadState } from './Load';
import { GetDefaultEditorState } from '../../../utils/default';
import { DISABLE_API, GetDefaultEditorState } from '../../../utils/default';
export function NewEditor(
setEditorState: Dispatch<SetStateAction<IEditorState>>,
setLoaded: Dispatch<SetStateAction<boolean>>
): void {
if (DISABLE_API) {
setLoaded(true);
return;
}
// Fetch the configuration from the API
FetchConfiguration()
.then((configuration: IConfiguration) => {

View file

@ -33,20 +33,7 @@ export function GetAction(
}
/* eslint-disable @typescript-eslint/naming-convention */
let prev;
let next;
if (container.parent !== undefined &&
container.parent !== null &&
container.parent.children.length > 1
) {
const index = container.parent.children.indexOf(container);
if (index > 0) {
prev = container.parent.children[index - 1];
}
if (index < container.parent.children.length - 1) {
next = container.parent.children[index + 1];
}
}
const { prev, next } = GetPreviousAndNextSiblings(container);
const request: ISetContainerListRequest = {
Container: container,
@ -72,6 +59,23 @@ export function GetAction(
};
}
function GetPreviousAndNextSiblings(container: IContainerModel): { prev: IContainerModel | undefined; next: IContainerModel | undefined; } {
let prev;
let next;
if (container.parent !== undefined &&
container.parent !== null &&
container.parent.children.length > 1) {
const index = container.parent.children.indexOf(container);
if (index > 0) {
prev = container.parent.children[index - 1];
}
if (index < container.parent.children.length - 1) {
next = container.parent.children[index + 1];
}
}
return { prev, next };
}
function HandleSetContainerList(
action: IAction,
selectedContainer: IContainerModel,

View file

@ -9,7 +9,7 @@ import { SaveEditorAsJSON, SaveEditorAsSVG } from './Actions/Save';
import { OnKey } from './Actions/Shortcuts';
import { events as EVENTS } from '../../Events/EditorEvents';
import { IEditorState } from '../../Interfaces/IEditorState';
import { MAX_HISTORY } from '../../utils/default';
import { DISABLE_API, MAX_HISTORY } from '../../utils/default';
import { AddSymbol, OnPropertyChange as OnSymbolPropertyChange, DeleteSymbol, SelectSymbol } from './Actions/SymbolOperations';
import { FindContainerById } from '../../utils/itertools';
import { IMenuAction, Menu } from '../Menu/Menu';
@ -62,6 +62,10 @@ function InitActions(
);
// API Actions
if (DISABLE_API) {
return;
}
for (const availableContainer of configuration.AvailableContainers) {
if (availableContainer.Actions === undefined || availableContainer.Actions === null) {
continue;

View file

@ -6,6 +6,7 @@ import { IGetFeedbackRequest } from '../../Interfaces/IGetFeedbackRequest';
import { IGetFeedbackResponse } from '../../Interfaces/IGetFeedbackResponse';
import { IHistoryState } from '../../Interfaces/IHistoryState';
import { IMessage } from '../../Interfaces/IMessage';
import { DISABLE_API } from '../../utils/default';
import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload';
interface IMessagesSidebarProps {
@ -68,12 +69,12 @@ export function MessagesSidebar(props: IMessagesSidebarProps): JSX.Element {
const [messages, setMessages] = React.useState<IMessage[]>([]);
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (window.Worker) {
if (window.Worker && !DISABLE_API) {
UseWorker(
props.historyState,
setMessages
);
} else {
} else if (!DISABLE_API) {
UseAsync(
props.historyState,
setMessages