Skip to content

Commit f107658

Browse files
authored
Feature/active status getters (#420)
* adding expiry helpers for cache invalidation * dont forget to write tests * adding unit test for getExpiryDateTimeFromNow * adding unit test for has expired * domain container * app and vuex changes * removing unused file * Added active status getters * adding merge domain config list
1 parent 0f79127 commit f107658

File tree

13 files changed

+512
-0
lines changed

13 files changed

+512
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 { connect } from 'vuex-connect';
23+
import { DOMAIN_IS_READY } from '../domain/getter-types';
24+
import { CROSS_REGION } from '../cross-region/getter-types';
25+
import {
26+
ACTIVE_STATUS_CLUSTER,
27+
ACTIVE_STATUS_SELECT_LIST,
28+
ACTIVE_STATUS_CLASSNAME,
29+
ACTIVE_STATUS_LABEL,
30+
ACTIVE_STATUS_TAG,
31+
} from './getter-types';
32+
33+
const gettersToProps = {
34+
classname: ACTIVE_STATUS_CLASSNAME,
35+
cluster: ACTIVE_STATUS_CLUSTER,
36+
crossRegion: CROSS_REGION,
37+
selectList: ACTIVE_STATUS_SELECT_LIST,
38+
isReady: DOMAIN_IS_READY,
39+
label: ACTIVE_STATUS_LABEL,
40+
tag: ACTIVE_STATUS_TAG,
41+
};
42+
43+
export default connect({
44+
gettersToProps,
45+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 ACTIVE_STATUS_STATE_PREFIX = 'activeStatus';
23+
export const ACTIVE_STATUS_TYPE_PREFIX = 'ACTIVE_STATUS';
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 ACTIVE_STATUS_CLASSNAME = typePrefix('CLASSNAME');
25+
export const ACTIVE_STATUS_CLUSTER = typePrefix('CLUSTER');
26+
export const ACTIVE_STATUS_CLUSTER_LIST = typePrefix('CLUSTER_LIST');
27+
export const ACTIVE_STATUS_LABEL = typePrefix('LABEL');
28+
export const ACTIVE_STATUS_SELECT_LIST = typePrefix('SELECT_LIST');
29+
export const ACTIVE_STATUS_TAG = typePrefix('TAG');
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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_IS_READY, DOMAIN_HASH } from '../domain/getter-types';
23+
import {
24+
ROUTE_PARAMS_WORKFLOW_ID,
25+
ROUTE_PARAMS_CLUSTER_NAME,
26+
ROUTE_PARAMS_DOMAIN,
27+
} from '../route/getter-types';
28+
import {
29+
CROSS_REGION,
30+
CROSS_REGION_ALLOWED_CROSS_ORIGIN,
31+
CROSS_REGION_CLUSTER_ORIGIN_LIST,
32+
} from '../cross-region/getter-types';
33+
import {
34+
ACTIVE_STATUS_CLASSNAME,
35+
ACTIVE_STATUS_CLUSTER,
36+
ACTIVE_STATUS_CLUSTER_LIST,
37+
ACTIVE_STATUS_LABEL,
38+
ACTIVE_STATUS_SELECT_LIST,
39+
ACTIVE_STATUS_TAG,
40+
} from './getter-types';
41+
import {
42+
getClusterFromClusterList,
43+
getClusterListFromDomainConfigList,
44+
getFilteredClusterList,
45+
} from './helpers';
46+
47+
const getters = {
48+
[ACTIVE_STATUS_CLASSNAME]: (_, getters) => {
49+
const cluster = getters[ACTIVE_STATUS_CLUSTER];
50+
51+
return cluster && cluster.isActive ? 'active' : 'passive';
52+
},
53+
[ACTIVE_STATUS_CLUSTER]: (_, getters) => {
54+
const allowedCrossOrigin = getters[CROSS_REGION_ALLOWED_CROSS_ORIGIN];
55+
const clusterList = getters[ACTIVE_STATUS_CLUSTER_LIST];
56+
const clusterName = getters[ROUTE_PARAMS_CLUSTER_NAME];
57+
const { origin } = window.location;
58+
59+
return getClusterFromClusterList({
60+
allowedCrossOrigin,
61+
clusterList,
62+
clusterName,
63+
origin,
64+
});
65+
},
66+
[ACTIVE_STATUS_CLUSTER_LIST]: (_, getters) => {
67+
const clusterOriginList = getters[CROSS_REGION_CLUSTER_ORIGIN_LIST];
68+
const crossRegion = getters[CROSS_REGION];
69+
const domainHash = getters[DOMAIN_HASH];
70+
const domainName = getters[ROUTE_PARAMS_DOMAIN];
71+
const isReady = getters[DOMAIN_IS_READY];
72+
73+
const domainNamespace = domainHash[domainName];
74+
75+
if (!crossRegion || !isReady) {
76+
return [];
77+
}
78+
79+
const domainConfigList = domainNamespace.global
80+
? [domainNamespace.global]
81+
: domainNamespace.local;
82+
83+
return getClusterListFromDomainConfigList({
84+
clusterOriginList,
85+
domainConfigList,
86+
});
87+
},
88+
[ACTIVE_STATUS_LABEL]: (_, getters) => {
89+
const cluster = getters[ACTIVE_STATUS_CLUSTER];
90+
91+
return cluster && cluster.label;
92+
},
93+
[ACTIVE_STATUS_SELECT_LIST]: (_, getters) => {
94+
const allowedCrossOrigin = getters[CROSS_REGION_ALLOWED_CROSS_ORIGIN];
95+
const clusterList = getters[ACTIVE_STATUS_CLUSTER_LIST];
96+
const clusterName = getters[ROUTE_PARAMS_CLUSTER_NAME];
97+
const { origin } = window.location;
98+
99+
return getFilteredClusterList({
100+
allowedCrossOrigin,
101+
clusterList,
102+
clusterName,
103+
origin,
104+
});
105+
},
106+
[ACTIVE_STATUS_TAG]: (_, getters) => {
107+
const cluster = getters[ACTIVE_STATUS_CLUSTER];
108+
const isReady = getters[DOMAIN_IS_READY];
109+
const selectList = getters[ACTIVE_STATUS_SELECT_LIST];
110+
const workflowId = getters[ROUTE_PARAMS_WORKFLOW_ID];
111+
112+
if (!isReady || !cluster) {
113+
return 'span';
114+
}
115+
116+
const { isGlobalDomain } = cluster;
117+
118+
return (selectList && selectList.length === 0) ||
119+
(!isGlobalDomain && workflowId)
120+
? 'span'
121+
: 'select-input';
122+
},
123+
};
124+
125+
export default getters;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 getClusterFromClusterList = ({
23+
allowedCrossOrigin,
24+
clusterList,
25+
clusterName,
26+
origin,
27+
}) => {
28+
if (!clusterList || allowedCrossOrigin === undefined) {
29+
return;
30+
}
31+
32+
const matchParamName = allowedCrossOrigin
33+
? clusterName
34+
? 'clusterName'
35+
: 'isActive'
36+
: 'origin';
37+
const matchValue = allowedCrossOrigin
38+
? clusterName
39+
? clusterName
40+
: true
41+
: origin;
42+
43+
const cluster = clusterList.find(
44+
({ [matchParamName]: paramValue }) => paramValue === matchValue
45+
);
46+
47+
if (!cluster) {
48+
console.warn(
49+
`Could not find cluster "${matchParamName}:${matchValue}" in crossRegion.clusterOriginList configuration.`
50+
);
51+
}
52+
53+
return cluster;
54+
};
55+
56+
export default getClusterFromClusterList;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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 mergeDomainConfigList from './merge-domain-config-list';
23+
24+
const getClusterListFromDomainConfigList = ({
25+
clusterOriginList = [],
26+
domainConfigList = [],
27+
}) => {
28+
const {
29+
activeClusterNames,
30+
isGlobalDomain,
31+
clusters,
32+
} = mergeDomainConfigList(domainConfigList);
33+
34+
const clusterList = clusterOriginList
35+
.filter(({ clusterName }) =>
36+
clusters.find(
37+
({ clusterName: domainClusterName }) =>
38+
clusterName === domainClusterName
39+
)
40+
)
41+
.map(cluster => {
42+
const isActive = activeClusterNames.includes(cluster.clusterName);
43+
const label = !isGlobalDomain ? 'local' : isActive ? 'active' : 'passive';
44+
45+
return {
46+
...cluster,
47+
isActive,
48+
isGlobalDomain,
49+
label: `${label} - ${cluster.clusterName}`,
50+
};
51+
});
52+
53+
return clusterList;
54+
};
55+
56+
export default getClusterListFromDomainConfigList;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 getFilteredClusterList = ({
23+
allowedCrossOrigin,
24+
clusterName,
25+
clusterList,
26+
origin,
27+
}) =>
28+
clusterList.filter(
29+
allowedCrossOrigin
30+
? cluster => {
31+
if (cluster.clusterName === clusterName) {
32+
return false;
33+
}
34+
35+
if (cluster.isActive && !clusterName) {
36+
return false;
37+
}
38+
39+
return true;
40+
}
41+
: cluster => cluster.origin !== origin
42+
);
43+
44+
export default getFilteredClusterList;

0 commit comments

Comments
 (0)