Skip to content

Commit 222c787

Browse files
authored
Merge pull request #570 from Theodo-UK/fix-all-resource-table-bug
2 parents 91a02ce + 3113354 commit 222c787

File tree

4 files changed

+40
-24
lines changed

4 files changed

+40
-24
lines changed

src/CLIMain.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from "./constants";
88

99
import { Map } from "./components";
10-
import { ResourceTable } from "./components/resourceTable";
10+
import { ResourceTable } from "./components/resourceTableComponent/resourceTable";
1111
import { DurationBarChart } from "./components/durationBarChart";
1212
import { getLambdaMetrics } from "./services/lambdaMetrics";
1313
import {

src/components/resourceTable.js src/components/resourceTableComponent/resourceTable.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
import { DASHBOARD_FOCUS_INDEX, DEPLOYMENT_STATUS } from "../../constants";
12
import {
2-
DEPLOYMENT_STATUS,
3+
RESOURCE_TABLE_CONFIG,
34
RESOURCE_TABLE_TYPE,
4-
DASHBOARD_FOCUS_INDEX,
5-
} from "../constants";
6-
import { getStackResources } from "../services/stackResources";
7-
import { padString } from "../utils/padString";
8-
import { lambdaStatisticsModal, lambdaInvokeModal } from "../modals";
9-
import { getLambdaFunctions } from "../services";
10-
import { abbreviateFunction } from "../utils/abbreviateFunction";
5+
switchTableConfig,
6+
} from "./resourceTableConfig";
7+
import { lambdaInvokeModal, lambdaStatisticsModal } from "../../modals";
8+
9+
import { abbreviateFunction } from "../../utils/abbreviateFunction";
10+
import { getLambdaFunctions } from "../../services";
11+
import { getStackResources } from "../../services/stackResources";
12+
import { padString } from "../../utils/padString";
1113

1214
const contrib = require("blessed-contrib");
1315
const open = require("open");
@@ -154,14 +156,10 @@ class ResourceTable {
154156
switchTable() {
155157
switch (this.type) {
156158
case RESOURCE_TABLE_TYPE.LAMBDA:
157-
this.type = RESOURCE_TABLE_TYPE.ALL_RESOURCES;
158-
this.table.setLabel("<- All Resources ->");
159-
this.table.options.columnWidth = [50, 30];
159+
switchTableConfig(this, RESOURCE_TABLE_TYPE.ALL_RESOURCES);
160160
break;
161161
case RESOURCE_TABLE_TYPE.ALL_RESOURCES:
162-
this.type = RESOURCE_TABLE_TYPE.LAMBDA;
163-
this.table.setLabel("<- Lambda Functions ->");
164-
this.table.options.columnWidth = [30, 30, 10, 10, 20];
162+
switchTableConfig(this, RESOURCE_TABLE_TYPE.LAMBDA);
165163
break;
166164
default:
167165
return 0;
@@ -173,9 +171,10 @@ class ResourceTable {
173171
return this.application.layoutGrid.set(0, 6, 4, 6, contrib.table, {
174172
keys: true,
175173
fg: "green",
176-
label: "<- Lambda Functions ->",
174+
label: RESOURCE_TABLE_CONFIG[RESOURCE_TABLE_TYPE.LAMBDA].label,
177175
columnSpacing: 1,
178-
columnWidth: [30, 30, 10, 10, 20, 10],
176+
columnWidth:
177+
RESOURCE_TABLE_CONFIG[RESOURCE_TABLE_TYPE.LAMBDA].columnWidth,
179178
style: {
180179
border: {
181180
fg: "yellow",
@@ -206,8 +205,7 @@ class ResourceTable {
206205
async updateData() {
207206
const stackResources = await getStackResources(
208207
this.program.stackName,
209-
this.cloudformation,
210-
this.application.setData
208+
this.cloudformation
211209
);
212210

213211
if (stackResources) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const RESOURCE_TABLE_TYPE = {
2+
LAMBDA: "LAMBDA",
3+
ALL_RESOURCES: "ALL_RESOURCES",
4+
};
5+
6+
export const RESOURCE_TABLE_CONFIG = {
7+
[RESOURCE_TABLE_TYPE.LAMBDA]: {
8+
label: "<- Lambda Functions ->",
9+
columnWidth: [30, 30, 10, 10, 20, 10],
10+
},
11+
[RESOURCE_TABLE_TYPE.ALL_RESOURCES]: {
12+
label: "<- All Resources ->",
13+
columnWidth: [50, 30],
14+
},
15+
};
16+
17+
export const switchTableConfig = (application, tableType) => {
18+
application.type = tableType;
19+
application.table.setLabel(RESOURCE_TABLE_CONFIG[tableType].label);
20+
application.options.columnWidth =
21+
RESOURCE_TABLE_CONFIG[tableType].columnWidth;
22+
this.table.options.columnWidth = [30, 30, 10, 10, 20, 10];
23+
};

src/constants.js

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export const DEPLOYMENT_STATUS = {
3434
ERROR: "ERROR",
3535
};
3636

37-
export const RESOURCE_TABLE_TYPE = {
38-
LAMBDA: "LAMBDA",
39-
ALL_RESOURCES: "ALL_RESOURCES",
40-
};
41-
4237
export const DASHBOARD_FOCUS_INDEX = {
4338
RESOURCE_TABLE: 0,
4439
EVENT_BRIDGE_TREE: 1,

0 commit comments

Comments
 (0)