Skip to content

Commit b51929e

Browse files
authored
Feature/domain container actions (#419)
* Added domain mutations. Added domain getDefaultState. * Added domain getters * Added domain getter to store * Added domain actions. Added domain component. Added container to App.
1 parent 5c34e1d commit b51929e

File tree

8 files changed

+269
-15
lines changed

8 files changed

+269
-15
lines changed

client/App.vue

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ import {
3131
NotificationBar,
3232
SelectInput,
3333
} from '~components';
34-
import { CrossRegion, DomainAutocomplete, SettingsModal } from '~containers';
34+
import {
35+
CrossRegion,
36+
Domain,
37+
DomainAutocomplete,
38+
SettingsModal,
39+
} from '~containers';
3540
import {
3641
DATE_FORMAT_MMM_D_YYYY,
3742
DATE_FORMAT_OPTIONS,
@@ -59,6 +64,7 @@ export default {
5964
components: {
6065
'button-icon': ButtonIcon,
6166
'cross-region': CrossRegion,
67+
domain: Domain,
6268
'domain-autocomplete': DomainAutocomplete,
6369
'feature-flag': FeatureFlag,
6470
'flex-grid': FlexGrid,
@@ -330,19 +336,21 @@ export default {
330336
</flex-grid>
331337
</header>
332338
<cross-region>
333-
<router-view
334-
:date-format="settings.dateFormat"
335-
:time-format="settings.timeFormat"
336-
:timezone="settings.timezone"
337-
:workflow-history-event-highlight-list="
338-
settings.workflowHistoryEventHighlightList
339-
"
340-
:workflow-history-event-highlight-list-enabled="
341-
settings.workflowHistoryEventHighlightListEnabled
342-
"
343-
@onWorkflowHistoryEventParamToggle="onWorkflowHistoryEventParamToggle"
344-
@onNotification="onNotification"
345-
></router-view>
339+
<domain>
340+
<router-view
341+
:date-format="settings.dateFormat"
342+
:time-format="settings.timeFormat"
343+
:timezone="settings.timezone"
344+
:workflow-history-event-highlight-list="
345+
settings.workflowHistoryEventHighlightList
346+
"
347+
:workflow-history-event-highlight-list-enabled="
348+
settings.workflowHistoryEventHighlightListEnabled
349+
"
350+
@onWorkflowHistoryEventParamToggle="onWorkflowHistoryEventParamToggle"
351+
@onNotification="onNotification"
352+
></router-view>
353+
</domain>
346354
</cross-region>
347355
<modals-container />
348356
<v-dialog />
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_CHANGE_ORIGIN = typePrefix('CHANGE_ORIGIN');
25+
export const DOMAIN_FETCH = typePrefix('FETCH');
26+
export const DOMAIN_ON_MOUNT = typePrefix('ON_MOUNT');
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
ROUTE_PARAMS_CLUSTER_NAME,
24+
ROUTE_PARAMS_DOMAIN,
25+
} from '../route/getter-types';
26+
import {
27+
CROSS_REGION_ALLOWED_CROSS_ORIGIN,
28+
CROSS_REGION_CLUSTER_ORIGIN_LIST,
29+
} from '../cross-region/getter-types';
30+
import {
31+
DOMAIN_CHANGE_ORIGIN,
32+
DOMAIN_FETCH,
33+
DOMAIN_ON_MOUNT,
34+
} from './action-types';
35+
import { DOMAIN_CROSS_ORIGIN, DOMAIN_IS_READY } from './getter-types';
36+
import {
37+
DOMAIN_RESET_STATE,
38+
DOMAIN_SET_DOMAIN,
39+
DOMAIN_SET_ERROR,
40+
} from './mutation-types';
41+
import { httpService } from '~services';
42+
import { getExpiryDateTimeFromNow } from '~helpers';
43+
44+
const actions = {
45+
[DOMAIN_FETCH]: async ({ commit, getters }) => {
46+
const clusterName = getters[ROUTE_PARAMS_CLUSTER_NAME];
47+
const domainName = getters[ROUTE_PARAMS_DOMAIN];
48+
const ready = getters[DOMAIN_IS_READY];
49+
const allowedCrossOrigin = getters[CROSS_REGION_ALLOWED_CROSS_ORIGIN];
50+
const clusterOriginList = getters[CROSS_REGION_CLUSTER_ORIGIN_LIST];
51+
52+
if (ready) {
53+
return;
54+
}
55+
56+
commit(DOMAIN_RESET_STATE, domainName);
57+
58+
const cluster =
59+
allowedCrossOrigin &&
60+
clusterName &&
61+
clusterOriginList &&
62+
clusterOriginList.find(
63+
({ clusterName: matchClusterName }) => matchClusterName === clusterName
64+
);
65+
const origin = (cluster && cluster.origin) || '';
66+
67+
try {
68+
const domain = await httpService.get(
69+
`${origin}/api/domains/${domainName}`
70+
);
71+
72+
if (allowedCrossOrigin && !domain.isGlobalDomain) {
73+
const fetchList = clusterOriginList
74+
.filter(
75+
({ clusterName }) =>
76+
clusterName !== domain.replicationConfiguration.activeClusterName
77+
)
78+
.map(({ origin }) => async () => {
79+
try {
80+
const domainConfig = await httpService.get(
81+
`${origin}/api/domains/${domainName}`
82+
);
83+
84+
return domainConfig;
85+
} catch (error) {
86+
console.warn(
87+
`Unable to resolve domain configuration for domain = "${domainName}" and origin = "${origin}".`
88+
);
89+
}
90+
});
91+
92+
const domainList = (
93+
await Promise.all(fetchList.map(callback => callback()))
94+
).filter(response => !!response);
95+
96+
domainList.forEach(localDomain => {
97+
localDomain.expiryDateTime = getExpiryDateTimeFromNow();
98+
commit(DOMAIN_SET_DOMAIN, localDomain);
99+
});
100+
}
101+
102+
domain.expiryDateTime = getExpiryDateTimeFromNow();
103+
commit(DOMAIN_SET_DOMAIN, domain);
104+
} catch (error) {
105+
console.warn(
106+
`Failed to fetch domain configuration for "${domainName}" from "${origin}".`
107+
);
108+
console.warn(error);
109+
commit(DOMAIN_SET_ERROR, {
110+
domainName,
111+
error: `An error occurred while trying to fetch domain "${domainName}". Please check the domain is correct and try again.`,
112+
});
113+
}
114+
},
115+
[DOMAIN_ON_MOUNT]: ({ dispatch }) => {
116+
dispatch(DOMAIN_CHANGE_ORIGIN);
117+
dispatch(DOMAIN_FETCH);
118+
},
119+
[DOMAIN_CHANGE_ORIGIN]: ({ getters }) => {
120+
const origin = getters[DOMAIN_CROSS_ORIGIN];
121+
122+
httpService.setOrigin(origin);
123+
},
124+
};
125+
126+
export default actions;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<script>
2+
// Copyright (c) 2021 Uber Technologies Inc.
3+
//
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
import { ErrorMessage } from '~components';
24+
25+
export default {
26+
name: 'domain',
27+
props: {
28+
clusterName: {
29+
type: String,
30+
},
31+
domainName: {
32+
type: String,
33+
},
34+
error: {
35+
type: String,
36+
},
37+
isLoading: {
38+
type: Boolean,
39+
},
40+
isReady: {
41+
type: Boolean,
42+
},
43+
origin: {
44+
type: String,
45+
},
46+
},
47+
components: {
48+
'error-message': ErrorMessage,
49+
},
50+
watch: {
51+
clusterName() {
52+
this.$emit('onClusterChange');
53+
},
54+
domainName() {
55+
this.$emit('onDomainChange');
56+
},
57+
origin() {
58+
this.$emit('onOriginChange');
59+
},
60+
},
61+
};
62+
</script>
63+
<template>
64+
<section class="domain" :class="{ loading: isLoading }">
65+
<slot v-if="isReady"></slot>
66+
<error-message :error="error" />
67+
</section>
68+
</template>

client/containers/domain/connector.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,24 @@ import {
2424
ROUTE_PARAMS_CLUSTER_NAME,
2525
ROUTE_PARAMS_DOMAIN,
2626
} from '../route/getter-types';
27+
import {
28+
DOMAIN_FETCH,
29+
DOMAIN_ON_MOUNT,
30+
DOMAIN_CHANGE_ORIGIN,
31+
} from './action-types';
2732
import {
2833
DOMAIN_ERROR,
2934
DOMAIN_IS_LOADING,
3035
DOMAIN_IS_READY,
3136
DOMAIN_CROSS_ORIGIN,
3237
} from './getter-types';
3338

39+
const actionsToEvents = {
40+
onClusterChange: DOMAIN_FETCH,
41+
onDomainChange: DOMAIN_FETCH,
42+
onOriginChange: DOMAIN_CHANGE_ORIGIN,
43+
};
44+
3445
const gettersToProps = {
3546
clusterName: ROUTE_PARAMS_CLUSTER_NAME,
3647
domainName: ROUTE_PARAMS_DOMAIN,
@@ -40,6 +51,12 @@ const gettersToProps = {
4051
origin: DOMAIN_CROSS_ORIGIN,
4152
};
4253

54+
const lifecycle = {
55+
mounted: ({ dispatch }) => dispatch(DOMAIN_ON_MOUNT),
56+
};
57+
4358
export default connect({
59+
actionsToEvents,
4460
gettersToProps,
61+
lifecycle,
4562
});

client/containers/domain/index.js

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

22+
import actions from './actions';
23+
import Component from './component';
24+
import connector from './connector';
2225
import getDefaultState from './get-default-state';
2326
import getters from './getters';
2427
import mutations from './mutations';
2528

26-
export { getDefaultState, getters, mutations };
29+
const container = connector(Component);
30+
31+
export { actions, container, getDefaultState, getters, mutations };

client/containers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export {
3333
mutations as crossRegionMutations,
3434
} from './cross-region';
3535
export {
36+
actions as domainActions,
37+
container as Domain,
3638
getDefaultState as getDomainDefaultState,
3739
getters as domainGetters,
3840
mutations as domainMutations,

client/store/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
crossRegionMutations,
3838

3939
// domain
40+
domainActions,
4041
getDomainDefaultState,
4142
domainGetters,
4243
domainMutations,
@@ -127,6 +128,7 @@ const getStoreConfig = ({ router, state }) => {
127128
actions: {
128129
...clusterActions,
129130
...crossRegionActions,
131+
...domainActions,
130132
...domainAutocompleteActions,
131133
...routeActionCreator(router),
132134
...workflowListActions,

0 commit comments

Comments
 (0)