Skip to content

Commit 65c2e92

Browse files
authored
Feature/domain container mutations (#417)
* Added domain mutations. Added domain getDefaultState. * added type prefix
1 parent d6b64cd commit 65c2e92

File tree

9 files changed

+253
-1
lines changed

9 files changed

+253
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
export const DOMAIN_TYPE_PREFIX = 'DOMAIN';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
domainHash: {},
24+
...state,
25+
});
26+
27+
export default getDefaultState;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
export { default as typePrefix } from './type-prefix';
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 { DOMAIN_TYPE_PREFIX } from '../constants';
23+
24+
const typePrefix = term => `${DOMAIN_TYPE_PREFIX}_${term}`;
25+
26+
export default typePrefix;

client/containers/domain/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 mutations from './mutations';
24+
25+
export { getDefaultState, mutations };
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 { typePrefix } from './helpers';
23+
24+
export const DOMAIN_RESET_STATE = typePrefix('RESET_STATE');
25+
export const DOMAIN_SET_DOMAIN = typePrefix('SET_DOMAIN');
26+
export const DOMAIN_SET_ERROR = typePrefix('SET_ERROR');
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 {
23+
DOMAIN_RESET_STATE,
24+
DOMAIN_SET_DOMAIN,
25+
DOMAIN_SET_ERROR,
26+
} from './mutation-types';
27+
28+
const mutations = {
29+
[DOMAIN_RESET_STATE]: (state, domainName) => {
30+
state.domain.domainHash = {
31+
...state.domain.domainHash,
32+
[domainName]: {},
33+
};
34+
},
35+
[DOMAIN_SET_DOMAIN]: (state, domain) => {
36+
const {
37+
domainInfo: { name: domainName },
38+
isGlobalDomain,
39+
replicationConfiguration: { activeClusterName },
40+
} = domain;
41+
42+
if (isGlobalDomain) {
43+
return (state.domain.domainHash = {
44+
...state.domain.domainHash,
45+
[domainName]: {
46+
global: domain,
47+
},
48+
});
49+
}
50+
51+
if (!state.domain.domainHash[domainName].local) {
52+
return (state.domain.domainHash = {
53+
...state.domain.domainHash,
54+
[domainName]: {
55+
local: [domain],
56+
},
57+
});
58+
}
59+
60+
const matchIndex = state.domain.domainHash[domainName].local.findIndex(
61+
({
62+
replicationConfiguration: { activeClusterName: matchActiveClusterName },
63+
}) => matchActiveClusterName === activeClusterName
64+
);
65+
66+
if (matchIndex === -1) {
67+
return (state.domain.domainHash = {
68+
...state.domain.domainHash,
69+
[domainName]: {
70+
local: [...state.domain.domainHash[domainName].local, domain],
71+
},
72+
});
73+
}
74+
75+
state.domain.domainHash[domainName].local.splice(matchIndex, 1, domain);
76+
77+
state.domain.domainHash = {
78+
...state.domain.domainHash,
79+
[domainName]: {
80+
local: [...state.domain.domainHash[domainName].local],
81+
},
82+
};
83+
},
84+
[DOMAIN_SET_ERROR]: (state, { domainName, error }) => {
85+
state.domain.domainHash = {
86+
...state.domain.domainHash,
87+
[domainName]: {
88+
error,
89+
},
90+
};
91+
},
92+
};
93+
94+
export default mutations;

client/containers/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export {
3232
getters as crossRegionGetters,
3333
mutations as crossRegionMutations,
3434
} from './cross-region';
35+
export {
36+
getDefaultState as getDomainDefaultState,
37+
mutations as domainMutations,
38+
} from './domain';
3539
export {
3640
actions as domainAutocompleteActions,
3741
container as DomainAutocomplete,

client/store/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ import {
3636
crossRegionGetters,
3737
crossRegionMutations,
3838

39+
// domain
40+
getDomainDefaultState,
41+
domainMutations,
42+
3943
// domain autocomplete
4044
domainAutocompleteActions,
4145
getDomainAutocompleteDefaultState,
@@ -77,6 +81,7 @@ import {
7781
const getDefaultState = (state = {}) => ({
7882
cluster: getClusterDefaultState(state.cluster),
7983
crossRegion: getCrossRegionDefaultState(state.crossRegion),
84+
domain: getDomainDefaultState(state.domain),
8085
domainAutocomplete: getDomainAutocompleteDefaultState(
8186
state.domainAutocomplete
8287
),
@@ -119,9 +124,9 @@ const getStoreConfig = ({ router, state }) => {
119124

120125
const storeConfig = {
121126
actions: {
122-
...domainAutocompleteActions,
123127
...clusterActions,
124128
...crossRegionActions,
129+
...domainAutocompleteActions,
125130
...routeActionCreator(router),
126131
...workflowListActions,
127132
...workflowPendingActions,
@@ -140,6 +145,7 @@ const getStoreConfig = ({ router, state }) => {
140145
mutations: {
141146
...clusterMutations,
142147
...crossRegionMutations,
148+
...domainMutations,
143149
...domainAutocompleteMutations,
144150
...graphMutations,
145151
...settingsWorkflowHistoryMutations,

0 commit comments

Comments
 (0)