From 66b9e63d9b8ec17ca7c5501f087e63642e1fc71c Mon Sep 17 00:00:00 2001 From: Emi Grady-Willis Date: Mon, 26 Jul 2021 12:13:56 -0400 Subject: [PATCH 1/4] Update client code to handle Django workspace API --- src/store/index.ts | 21 +++++++++++++++------ src/views/TableDetail.vue | 8 +++++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index 94ca1ec3..1261525b 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -76,27 +76,36 @@ const { async fetchWorkspaces(context) { const { commit } = rootActionContext(context); const workspaces = await api.workspaces(); - commit.setWorkspaces(workspaces); + commit.setWorkspaces(workspaces.results.map((h) => h.name)); }, async fetchWorkspace(context, workspace: string) { const { commit } = rootActionContext(context); commit.unsetCurrentWorkspace(); - const nodeTables = await api.tables(workspace, { type: 'node' }); - const edgeTables = await api.tables(workspace, { type: 'edge' }); const graphs = await api.graphs(workspace); + const tables = (await api.tables(workspace)).results; + const nodeTables = tables.filter((table) => table.edge === false); + const edgeTables = tables.filter((table) => table.edge === true); commit.setCurrentWorkspace({ - name: workspace, nodeTables, edgeTables, graphs, + name: workspace, nodeTables: nodeTables.map((h) => h.name), edgeTables: edgeTables.map((h) => h.name), graphs: graphs.results.map((h) => h.name), }); }, async fetchUserInfo(context) { const { commit } = rootActionContext(context); - const info = await api.userInfo(); - commit.setUserInfo(info); + try { + const info = await api.userInfo(); + commit.setUserInfo(info); + } catch (error) { + if (error.response.status === 401) { + commit.setUserInfo(null); + } else { + throw new Error(error); + } + } }, async logout(context) { diff --git a/src/views/TableDetail.vue b/src/views/TableDetail.vue index af5e21ad..aa73221d 100644 --- a/src/views/TableDetail.vue +++ b/src/views/TableDetail.vue @@ -242,10 +242,12 @@ export default Vue.extend({ }); const { - rows, + results, count, } = result; + const rows = results; + this.tableSize = count; const rowKeys: KeyValue[][] = []; @@ -272,9 +274,9 @@ export default Vue.extend({ this.headers = headers; // Roni to convert these lines to computed function - this.tables = await api.tables(this.workspace, { + this.tables = (await api.tables(this.workspace, { type: 'all', - }); + })).results.map((table) => table.name); this.loading = false; }, From e4b66789deb382015409b77e2002bc8c446e8e78 Mon Sep 17 00:00:00 2001 From: Emi Grady-Willis Date: Mon, 2 Aug 2021 14:42:28 -0400 Subject: [PATCH 2/4] Move key/value assignments to individual lines --- src/store/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/store/index.ts b/src/store/index.ts index 1261525b..6a8b2d4a 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -89,7 +89,10 @@ const { const edgeTables = tables.filter((table) => table.edge === true); commit.setCurrentWorkspace({ - name: workspace, nodeTables: nodeTables.map((h) => h.name), edgeTables: edgeTables.map((h) => h.name), graphs: graphs.results.map((h) => h.name), + name: workspace, + nodeTables: nodeTables.map((h) => h.name), + edgeTables: edgeTables.map((h) => h.name), + graphs: graphs.results.map((h) => h.name), }); }, From 657fd143a25c218ff3ebbcb902f665e72bf9418e Mon Sep 17 00:00:00 2001 From: eagw <87092433+eagw@users.noreply.github.com> Date: Mon, 2 Aug 2021 15:18:39 -0400 Subject: [PATCH 3/4] Consolidate "rows" variable assignment Co-authored-by: Roni Choudhury <2903332+waxlamp@users.noreply.github.com> --- src/views/TableDetail.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/views/TableDetail.vue b/src/views/TableDetail.vue index aa73221d..1d997383 100644 --- a/src/views/TableDetail.vue +++ b/src/views/TableDetail.vue @@ -242,12 +242,10 @@ export default Vue.extend({ }); const { - results, + results: rows, count, } = result; - const rows = results; - this.tableSize = count; const rowKeys: KeyValue[][] = []; From 3fd89b8ab14366e7a67800ccb94476e37ea56c42 Mon Sep 17 00:00:00 2001 From: Emi Grady-Willis Date: Mon, 2 Aug 2021 15:42:42 -0400 Subject: [PATCH 4/4] Use more descriptive variable names in map() calls --- src/store/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index 6a8b2d4a..96a36f8b 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -76,7 +76,7 @@ const { async fetchWorkspaces(context) { const { commit } = rootActionContext(context); const workspaces = await api.workspaces(); - commit.setWorkspaces(workspaces.results.map((h) => h.name)); + commit.setWorkspaces(workspaces.results.map((w) => w.name)); }, async fetchWorkspace(context, workspace: string) { @@ -90,9 +90,9 @@ const { commit.setCurrentWorkspace({ name: workspace, - nodeTables: nodeTables.map((h) => h.name), - edgeTables: edgeTables.map((h) => h.name), - graphs: graphs.results.map((h) => h.name), + nodeTables: nodeTables.map((table) => table.name), + edgeTables: edgeTables.map((table) => table.name), + graphs: graphs.results.map((graph) => graph.name), }); },