From 14db85ec5a5aee0cbe074d25144816af73ab1957 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 27 Jan 2022 19:07:43 -0800 Subject: [PATCH] Fix history render --- .../src/classes/client/rest-client/index.ts | 28 +++++++++++++++++-- .../history-dialog/index.tsx | 2 +- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/webapp/src/classes/client/rest-client/index.ts b/packages/webapp/src/classes/client/rest-client/index.ts index 7632ebe6..9b79a148 100644 --- a/packages/webapp/src/classes/client/rest-client/index.ts +++ b/packages/webapp/src/classes/client/rest-client/index.ts @@ -252,7 +252,7 @@ export default class RestClient implements Client { revertHistory(id: number, hid: number): Promise { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { axios - .post(`${this.baseUrl}/maps/${id}/history/${hid}`, null, { + .post(`${this.baseUrl}/c/restful/maps/${id}/history/${hid}`, null, { headers: { 'Content-Type': 'text/pain' }, }) .then(() => { @@ -267,7 +267,31 @@ export default class RestClient implements Client { } fetchHistory(id: number): Promise { - throw new Error(`Method not implemented. ${id}`); + const handler = ( + success: (historyList: ChangeHistory[]) => void, + reject: (error: ErrorInfo) => void + ) => { + axios + .get(`${this.baseUrl}/c/restful/maps/${id}/history/`, { + headers: { 'Content-Type': 'application/json' }, + }) + .then((response) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const historyList: ChangeHistory[] = (response.data.changes as any[]).map((h) => { + return { + id: h.id, + lastModificationBy: h.creator, + lastModificationTime: h.creationTime, + }; + }); + success(historyList); + }) + .catch((error) => { + const errorInfo = this.parseResponseOnError(error.response); + reject(errorInfo); + }); + }; + return new Promise(handler); } renameMap(id: number, basicInfo: BasicMapInfo): Promise { diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx index 0993ebc4..11c9ebd3 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/history-dialog/index.tsx @@ -99,7 +99,7 @@ const HistoryDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElemen