Fix try page removing global variables.

This commit is contained in:
Paulo Gustavo Veiga 2022-02-22 15:54:57 -08:00
parent 935a529bf4
commit a75962373c
5 changed files with 21 additions and 21 deletions

View File

@ -129,9 +129,9 @@ class CacheDecoratorClient implements Client {
revertHistory(id: number, cid: number): Promise<void> { revertHistory(id: number, cid: number): Promise<void> {
return this.client.revertHistory(id, cid); return this.client.revertHistory(id, cid);
} }
buildPersistenceManager(): PersistenceManager { buildPersistenceManager(isTryMode: boolean): PersistenceManager {
return this.client.buildPersistenceManager(); return this.client.buildPersistenceManager(isTryMode);
} }
removePersistenceManager(): void { removePersistenceManager(): void {

View File

@ -107,9 +107,9 @@ interface Client {
fetchHistory(id: number): Promise<ChangeHistory[]>; fetchHistory(id: number): Promise<ChangeHistory[]>;
revertHistory(id: number, cid: number): Promise<void>; revertHistory(id: number, cid: number): Promise<void>;
fetchMindmap(id:number): Mindmap; fetchMindmap(id: number): Mindmap;
buildPersistenceManager(): PersistenceManager; buildPersistenceManager(isTryMode: boolean): PersistenceManager;
removePersistenceManager(): void; removePersistenceManager(): void;
onSessionExpired(callback?: () => void): () => void; onSessionExpired(callback?: () => void): () => void;

View File

@ -36,7 +36,7 @@ class MockClient implements Client {
private labels: Label[] = []; private labels: Label[] = [];
private permissionsByMap: Map<number, Permission[]> = new Map(); private permissionsByMap: Map<number, Permission[]> = new Map();
private persistenceManager: PersistenceManager; private persistenceManager: PersistenceManager;
constructor() { constructor() {
// Remove, just for develop .... // Remove, just for develop ....
function createMapInfo( function createMapInfo(
@ -98,7 +98,7 @@ class MockClient implements Client {
12, 12,
false, false,
'El Mapa3', 'El Mapa3',
[label2, label3], [label2, label3],
'Paulo3', 'Paulo3',
'2008-06-02T00:00:00Z', '2008-06-02T00:00:00Z',
'Berna', 'Berna',
@ -115,7 +115,7 @@ class MockClient implements Client {
onSessionExpired(callback?: () => void): () => void { onSessionExpired(callback?: () => void): () => void {
return callback; return callback;
} }
fetchMindmap(id: number): Mindmap { fetchMindmap(id: number): Mindmap {
const parser = new DOMParser(); const parser = new DOMParser();
const xmlDoc = parser.parseFromString(` const xmlDoc = parser.parseFromString(`
@ -335,7 +335,7 @@ class MockClient implements Client {
createLabel(title: string, color: string): Promise<number> { createLabel(title: string, color: string): Promise<number> {
const newId = Math.max.apply(Number, this.labels.map(l => l.id)) + 1; const newId = Math.max.apply(Number, this.labels.map(l => l.id)) + 1;
this.labels.push({ this.labels.push({
id: newId, id: newId,
title, title,
color, color,
@ -346,8 +346,8 @@ class MockClient implements Client {
deleteLabel(id: number): Promise<void> { deleteLabel(id: number): Promise<void> {
this.labels = this.labels.filter((l) => l.id != id); this.labels = this.labels.filter((l) => l.id != id);
this.maps = this.maps.map(m => { this.maps = this.maps.map(m => {
return { return {
...m, ...m,
labels: m.labels.filter((l) => l.id != id) labels: m.labels.filter((l) => l.id != id)
}; };
}); });
@ -357,7 +357,7 @@ class MockClient implements Client {
addLabelToMap(labelId: number, mapId: number): Promise<void> { addLabelToMap(labelId: number, mapId: number): Promise<void> {
const labelToAdd = this.labels.find((l) => l.id === labelId); const labelToAdd = this.labels.find((l) => l.id === labelId);
if (!labelToAdd) { if (!labelToAdd) {
return Promise.reject({ msg: `unable to find label with id ${labelId}`}); return Promise.reject({ msg: `unable to find label with id ${labelId}` });
} }
const map = this.maps.find((m) => m.id === mapId); const map = this.maps.find((m) => m.id === mapId);
if (!map) { if (!map) {
@ -400,14 +400,14 @@ class MockClient implements Client {
} }
buildPersistenceManager(): PersistenceManager { buildPersistenceManager(): PersistenceManager {
if (this.persistenceManager){ if (this.persistenceManager) {
return this.persistenceManager; return this.persistenceManager;
} }
const persistence: PersistenceManager = new MockPersistenceManager(exampleMap); const persistence: PersistenceManager = new MockPersistenceManager(exampleMap);
this.persistenceManager = persistence; this.persistenceManager = persistence;
return persistence; return persistence;
} }
removePersistenceManager(): void { removePersistenceManager(): void {
if (this.persistenceManager) { if (this.persistenceManager) {
delete this.persistenceManager; delete this.persistenceManager;

View File

@ -39,12 +39,12 @@ export default class RestClient implements Client {
} }
this.axios.interceptors.response.use((r) => r, (r) => this.checkResponseForSessionExpired(r)); this.axios.interceptors.response.use((r) => r, (r) => this.checkResponseForSessionExpired(r));
} }
private _onSessionExpired : () => void; private _onSessionExpired: () => void;
onSessionExpired(callback?: () => void): () => void { onSessionExpired(callback?: () => void): () => void {
if (callback) { if (callback) {
this._onSessionExpired = callback; this._onSessionExpired = callback;
} }
return this._onSessionExpired; return this._onSessionExpired;
} }
@ -611,13 +611,13 @@ export default class RestClient implements Client {
} }
} }
buildPersistenceManager(): PersistenceManager { buildPersistenceManager(isTryMode: boolean): PersistenceManager {
if (this.persistenceManager){ if (this.persistenceManager) {
return this.persistenceManager; return this.persistenceManager;
} }
// TODO: Move globals out, make urls configurable // TODO: Move globals out, make urls configurable
let persistence: PersistenceManager; let persistence: PersistenceManager;
if (!global.memoryPersistence && !global.readOnly) { if (!isTryMode) {
persistence = new RESTPersistenceManager({ persistence = new RESTPersistenceManager({
documentUrl: '/c/restful/maps/{id}/document', documentUrl: '/c/restful/maps/{id}/document',
revertUrl: '/c/restful/maps/{id}/history/latest', revertUrl: '/c/restful/maps/{id}/history/latest',

View File

@ -24,7 +24,7 @@ const EditorPage = ({ isTryMode }: EditorPropsType): React.ReactElement => {
useEffect(() => { useEffect(() => {
ReactGA.pageview(window.location.pathname + window.location.search); ReactGA.pageview(window.location.pathname + window.location.search);
const persistence = client.buildPersistenceManager(); const persistence = client.buildPersistenceManager(isTryMode);
setPersistenceManager(persistence); setPersistenceManager(persistence);
return () => client.removePersistenceManager(); return () => client.removePersistenceManager();
}, []); }, []);