Skip to content

Commit 17e7d1d

Browse files
authored
Feature/graph container refactor (#273)
* move graph store into containers. Small refactor of store. Fix how tests initialize store. * small refactor to graph getters * accedently removed persist
1 parent e668511 commit 17e7d1d

File tree

9 files changed

+200
-79
lines changed

9 files changed

+200
-79
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
const getDefaultState = (state = {}) => ({
23+
childRoute: null,
24+
newExecutionId: null,
25+
parentRoute: null,
26+
hasChildBtn: false,
27+
childBtnText: null,
28+
parentBtnText: 'to parent',
29+
...state,
30+
});
31+
32+
export default getDefaultState;

client/containers/graph/getters.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import { get } from 'lodash-es';
23+
24+
const getters = {
25+
childRoute: state => get(state, 'graph.childRoute'),
26+
newExecutionId: state => get(state, 'graph.newExecutionId'),
27+
hasChildBtn: state => get(state, 'graph.hasChildBtn'),
28+
childBtnText: state => get(state, 'graph.childBtnText'),
29+
parentBtnText: state => get(state, 'graph.parentBtnText'),
30+
parentRoute: state => get(state, 'graph.parentRoute'),
31+
};
32+
33+
export default getters;

client/containers/graph/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import getDefaultState from './get-default-state';
23+
import getters from './getters';
24+
import mutations from './mutations';
25+
26+
export { getDefaultState, getters, mutations };
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
import getDefaultState from './get-default-state';
23+
24+
const mutations = {
25+
childRoute(state, param) {
26+
state.graph.childRoute = param.route;
27+
state.graph.hasChildBtn = true;
28+
state.graph.childBtnText = param.btnText;
29+
},
30+
newExecutionRoute(state, route) {
31+
(state.graph.newExecutionId = route),
32+
(state.graph.hasChildBtn = !state.graph.hasChildBtn);
33+
},
34+
previousExecutionRoute(state, route) {
35+
(state.graph.parentRoute = route),
36+
(state.graph.parentBtnText = 'previous execution');
37+
},
38+
toggleChildBtn(state) {
39+
state.graph.hasChildBtn = false;
40+
},
41+
parentRoute(state, route) {
42+
state.graph.parentRoute = route;
43+
},
44+
resetGraphState(state) {
45+
Object.assign(state.graph, getDefaultState());
46+
},
47+
};
48+
49+
export default mutations;

client/containers/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
export {
23+
getDefaultState as getGraphDefaultState,
24+
getters as graphGetters,
25+
mutations as graphMutations,
26+
} from './graph';
2227
export {
2328
container as SettingsWorkflowHistory,
2429
getDefaultState as getSettingsWorkflowHistoryDefaultState,

client/main.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import WorkflowArchivalBasic from './routes/domain/workflow-archival/basic';
5353
import WorkflowList from './routes/domain/workflow-list';
5454
import WorkflowSummary from './routes/workflow/summary';
5555
import WorkflowTabs from './routes/workflow';
56-
import store from './store/index.js';
56+
import initStore from './store';
5757
import { WorkflowHistory } from '~containers';
5858

5959
import { http, injectMomentDurationFormat, jsonTryParse } from '~helpers';
@@ -344,6 +344,8 @@ if (typeof mocha === 'undefined') {
344344
document.body.appendChild(document.createElement('main'));
345345
}
346346

347+
const store = initStore();
348+
347349
// eslint-disable-next-line no-new
348350
new Vue({
349351
el: 'main',

client/store/index.js

Lines changed: 41 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -23,84 +23,58 @@ import Vue from 'vue';
2323
import Vuex from 'vuex';
2424
import VuexPersistence from 'vuex-persist';
2525
import {
26+
// graph
27+
getGraphDefaultState,
28+
graphGetters,
29+
graphMutations,
30+
31+
// settings
2632
getSettingsWorkflowHistoryDefaultState,
27-
getWorkflowHistoryDefaultState,
2833
settingsWorkflowHistoryGetters,
2934
settingsWorkflowHistoryMutations,
30-
} from '~containers';
3135

32-
// Graph store
36+
// workflow history
37+
getWorkflowHistoryDefaultState,
38+
} from '~containers';
3339

34-
const getGraphDefaultState = () => ({
35-
childRoute: null,
36-
newExecutionId: null,
37-
parentRoute: null,
38-
hasChildBtn: false,
39-
childBtnText: null,
40-
parentBtnText: 'to parent',
40+
const getDefaultState = (state = {}) => ({
41+
graph: getGraphDefaultState(state.graph),
42+
settingsWorkflowHistory: getSettingsWorkflowHistoryDefaultState(
43+
state.settingsWorkflowHistory
44+
),
45+
workflowHistory: getWorkflowHistoryDefaultState(state.workflowHistory),
4146
});
4247

43-
const graphMutations = {
44-
childRoute(state, param) {
45-
state.graph.childRoute = param.route;
46-
state.graph.hasChildBtn = true;
47-
state.graph.childBtnText = param.btnText;
48-
},
49-
newExecutionRoute(state, route) {
50-
(state.graph.newExecutionId = route),
51-
(state.graph.hasChildBtn = !state.graph.hasChildBtn);
52-
},
53-
previousExecutionRoute(state, route) {
54-
(state.graph.parentRoute = route),
55-
(state.graph.parentBtnText = 'previous execution');
56-
},
57-
toggleChildBtn(state) {
58-
state.graph.hasChildBtn = false;
59-
},
60-
parentRoute(state, route) {
61-
state.graph.parentRoute = route;
62-
},
63-
resetGraphState(state) {
64-
Object.assign(state.graph, getGraphDefaultState());
65-
},
66-
};
48+
const getStoreConfig = ({ state }) => {
49+
const initialState = getDefaultState(state);
6750

68-
const graphGetters = {
69-
childRoute: state => state.graph.childRoute,
70-
newExecutionId: state => state.graph.newExecutionId,
71-
hasChildBtn: state => state.graph.hasChildBtn,
72-
childBtnText: state => state.graph.childBtnText,
73-
parentBtnText: state => state.graph.parentBtnText,
74-
parentRoute: state => state.graph.parentRoute,
75-
};
51+
const vuexLocal = new VuexPersistence({
52+
storage: window.localStorage,
53+
});
7654

77-
// Application store
55+
const storeConfig = {
56+
state: initialState,
57+
mutations: {
58+
...graphMutations,
59+
...settingsWorkflowHistoryMutations,
60+
},
61+
getters: {
62+
...graphGetters,
63+
...settingsWorkflowHistoryGetters,
64+
},
65+
plugins: [vuexLocal.plugin],
66+
};
7867

79-
const getDefaultState = () => ({
80-
graph: getGraphDefaultState(),
81-
settingsWorkflowHistory: getSettingsWorkflowHistoryDefaultState(),
82-
workflowHistory: getWorkflowHistoryDefaultState(),
83-
});
84-
85-
const state = getDefaultState();
68+
return storeConfig;
69+
};
8670

87-
Vue.use(Vuex);
71+
const initStore = ({ state } = {}) => {
72+
Vue.use(Vuex);
8873

89-
const vuexLocal = new VuexPersistence({
90-
storage: window.localStorage,
91-
});
74+
const storeConfig = getStoreConfig({ state });
75+
const store = new Vuex.Store(storeConfig);
9276

93-
const store = new Vuex.Store({
94-
state: state,
95-
mutations: {
96-
...graphMutations,
97-
...settingsWorkflowHistoryMutations,
98-
},
99-
getters: {
100-
...graphGetters,
101-
...settingsWorkflowHistoryGetters,
102-
},
103-
plugins: [vuexLocal.plugin],
104-
});
77+
return store;
78+
};
10579

106-
export default store;
80+
export default initStore;

client/test/scenario.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import Router from 'vue-router';
2323
import Vue from 'vue';
24-
import Vuex from 'vuex';
2524
import moment from 'moment';
2625
import fetchMock from 'fetch-mock';
2726
import qs from 'friendly-querystring';
@@ -30,12 +29,13 @@ import deepmerge from 'deepmerge';
3029

3130
import main from '../main';
3231
import { http } from '../helpers';
32+
import initStore from '../store';
3333
import fixtures from './fixtures';
3434

3535
export default function Scenario(test) {
3636
// eslint-disable-next-line no-param-reassign
3737
test.scenario = this;
38-
this.storeConfig = {};
38+
this.storeState = {};
3939
this.mochaTest = test;
4040
this.api = fetchMock.sandbox().catch((url, req, opts) => {
4141
let msg = `Unexpected request: ${url}${
@@ -66,7 +66,9 @@ Scenario.prototype.render = function render(attachToBody) {
6666

6767
const el = document.createElement('div');
6868

69-
const store = new Vuex.Store(this.storeConfig);
69+
const store = initStore({
70+
state: this.storeState,
71+
});
7072

7173
if (attachToBody || this.isDebuggingJustThisTest()) {
7274
document.body.appendChild(el);
@@ -232,8 +234,8 @@ Scenario.prototype.withNewsFeed = function withNewsFeed() {
232234
return this;
233235
};
234236

235-
Scenario.prototype.withStoreConfig = function withStoreConfig(config = {}) {
236-
this.storeConfig = config;
237+
Scenario.prototype.withStoreState = function withStoreState(state = {}) {
238+
this.storeState = state;
237239

238240
return this;
239241
};
@@ -289,7 +291,7 @@ Scenario.prototype.withWorkflow = function withWorkflow(
289291
this.workflowId = workflowId;
290292
this.runId = runId;
291293

292-
this.api.getOnce(this.execApiBase(), {
294+
this.api.get(this.execApiBase(), {
293295
executionConfiguration: {
294296
taskList: { name: 'ci_task_list' },
295297
executionStartToCloseTimeoutSeconds: 3600,

client/test/workflow.test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ describe('Workflow', () => {
4646
},
4747
])
4848
.withNewsFeed()
49-
.withStoreConfig({
50-
state: {
51-
workflowHistory: {
52-
graphEnabled: true,
53-
},
49+
.withStoreState({
50+
workflowHistory: {
51+
graphEnabled: true,
5452
},
5553
})
5654
.withWorkflow(

0 commit comments

Comments
 (0)