Final fix for Dictionnary serialization

This commit is contained in:
Eric NGUYEN 2022-10-12 16:50:20 +02:00
parent 147c02bdfd
commit 846f41829b
7 changed files with 55 additions and 14 deletions

View file

@ -64,14 +64,26 @@ function GetCircularReplacerKeepDataStructure()
}
if (key === 'containers') {
return Object.fromEntries(value);
return [...value.entries()].map((keyPair) => {
return {
Key: keyPair[0],
Value: keyPair[1]
};
});
}
if (key === 'symbols') {
return Object.fromEntries(value);
return [...value.entries()].map((keyPair) => {
return {
Key: keyPair[0],
Value: keyPair[1]
};
});
}
return value;
if (key === 'linkedContainers') {
return Array.from(value);
}
};
}

View file

@ -34,14 +34,26 @@ function GetCircularReplacerKeepDataStructure()
}
if (key === 'containers') {
return Object.fromEntries(value);
return [...value.entries()].map((keyPair) => {
return {
Key: keyPair[0],
Value: keyPair[1]
};
});
}
if (key === 'symbols') {
return Object.fromEntries(value);
return [...value.entries()].map((keyPair) => {
return {
Key: keyPair[0],
Value: keyPair[1]
};
});
}
return value;
if (key === 'linkedContainers') {
return Array.from(value);
}
};
}

View file

@ -2,7 +2,7 @@ import { API_FETCH_URL, API_SET_CONTAINER_LIST_URL } from '../../../public/svgld
import { IConfiguration } from '../../Interfaces/IConfiguration';
import { ISetContainerListRequest } from '../../Interfaces/ISetContainerListRequest';
import { ISetContainerListResponse } from '../../Interfaces/ISetContainerListResponse';
import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload';
import { GetCircularReplacerToDotnet } from '../../utils/saveload';
/**
* Fetch the configuration from the API
@ -36,7 +36,7 @@ export async function FetchConfiguration(): Promise<IConfiguration> {
export async function SetContainerList(request: ISetContainerListRequest): Promise<ISetContainerListResponse> {
const url = API_SET_CONTAINER_LIST_URL;
const dataParsed = JSON.stringify(request, GetCircularReplacerKeepDataStructure());
const dataParsed = JSON.stringify(request, GetCircularReplacerToDotnet());
// The test library cannot use the Fetch API
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions

View file

@ -5,7 +5,7 @@ import { MessageType } from '../../Enums/MessageType';
import { IHistoryState } from '../../Interfaces/IHistoryState';
import { IMessage } from '../../Interfaces/IMessage';
import { DISABLE_API } from '../../utils/default';
import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload';
import { GetCircularReplacerToDotnet } from '../../utils/saveload';
import { TITLE_BAR_HEIGHT } from '../Sidebar/Sidebar';
interface IMessagesProps {

View file

@ -3,7 +3,7 @@ import { IHistoryState } from '../../Interfaces/IHistoryState';
import { IGetFeedbackRequest } from '../../Interfaces/IGetFeedbackRequest';
import { IGetFeedbackResponse } from '../../Interfaces/IGetFeedbackResponse';
import { IMessage } from '../../Interfaces/IMessage';
import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload';
import { GetCircularReplacerToDotnet } from '../../utils/saveload';
import { API_GET_FEEDBACK_URL } from '../../../public/svgld-settings';
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
@ -37,7 +37,7 @@ export function UseAsync(
// eslint-disable-next-line @typescript-eslint/naming-convention
ApplicationState: state
};
const dataParsed = JSON.stringify(request, GetCircularReplacerKeepDataStructure());
const dataParsed = JSON.stringify(request, GetCircularReplacerToDotnet());
fetch(API_GET_FEEDBACK_URL, {
method: 'POST',
headers: new Headers({

View file

@ -16,6 +16,9 @@ function RenderRoot(root: Element | Document): void {
namespace SVGLayoutDesigner {
// eslint-disable-next-line @typescript-eslint/naming-convention
export const Render = RenderRoot;
export const API_FETCH_URL = 'http://localhost:5000';
export const API_SET_CONTAINER_LIST_URL = 'http://localhost:5000/SetContainerList';
export const API_GET_FEEDBACK_URL = 'http://localhost:5000/GetFeedback';
}
(window as any).SVGLayoutDesigner = SVGLayoutDesigner;

View file

@ -77,18 +77,32 @@ export function GetCircularReplacer(): (key: any, value: object | Map<string, an
};
}
export function GetCircularReplacerKeepDataStructure(): (key: any, value: object | Map<string, any> | null) => object | null | undefined {
export function GetCircularReplacerToDotnet(): (key: any, value: object | Map<string, any> | null) => object | null | undefined {
return (key: any, value: object | null) => {
if (key === 'parent') {
return;
}
if (key === 'containers') {
return Object.fromEntries(value as Map<string, any>);
return [...(value as Map<string, any>).entries()].map((keyPair: [string, any]) => {
return {
Key: keyPair[0],
Value: keyPair[1]
};
});
}
if (key === 'symbols') {
return Object.fromEntries((value as Map<string, any>));
return [...(value as Map<string, any>).entries()].map((keyPair: [string, any]) => {
return {
Key: keyPair[0],
Value: keyPair[1]
};
});
}
if (key === 'linkedContainers') {
return Array.from(value as Set<string>);
}
return value;