Skip to content

Commit dae0d08

Browse files
authored
Fix domain search page crash for crossRegion environments (#532)
* fix domain search page crash for crossRegion envs * update unit test name * fix typo in url params variable * fix linting issue
1 parent 9af88c8 commit dae0d08

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

client/containers/active-status/getters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const getters = {
7272

7373
const domainNamespace = domainHash[domainName];
7474

75-
if (!crossRegion || !isReady) {
75+
if (!domainName || !crossRegion || !isReady) {
7676
return [];
7777
}
7878

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2021-2023 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 { ROUTE_PARAMS_DOMAIN } from '../route/getter-types';
23+
import {
24+
CROSS_REGION,
25+
CROSS_REGION_CLUSTER_ORIGIN_LIST,
26+
} from '../cross-region/getter-types';
27+
import { DOMAIN_HASH, DOMAIN_IS_READY } from '../domain/getter-types';
28+
import activeStatusGetterFns from './getters';
29+
import { ACTIVE_STATUS_CLUSTER_LIST } from './getter-types';
30+
import { initGetters } from '~test';
31+
32+
describe('Active status getters', () => {
33+
describe('when calling getters[ACTIVE_STATUS_CLUSTER_LIST]', () => {
34+
it('should return empty array if its dynamic dependent getters returned Nil', () => {
35+
const dependentGetterNames = [
36+
CROSS_REGION_CLUSTER_ORIGIN_LIST,
37+
CROSS_REGION,
38+
ROUTE_PARAMS_DOMAIN,
39+
];
40+
41+
dependentGetterNames.forEach(getterName => {
42+
const getterFns = {
43+
...activeStatusGetterFns,
44+
[getterName]: () => null,
45+
[DOMAIN_IS_READY]: () => true,
46+
[DOMAIN_HASH]: () => ({}),
47+
};
48+
const getters = initGetters({ getterFns });
49+
const output = getters[ACTIVE_STATUS_CLUSTER_LIST];
50+
51+
expect(output).toEqual([]);
52+
});
53+
});
54+
});
55+
});

client/containers/domain/connector.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,18 @@ const gettersToProps = {
5757
const lifecycle = {
5858
mounted: ({ dispatch }) => dispatch(DOMAIN_ON_MOUNT),
5959
updated({ dispatch, state }) {
60-
const urlParamClusterName = this.clusterName;
60+
const urlParams = state.route.params;
61+
const routeSupportsClusterNameParam = urlParams?.hasOwnProperty(
62+
'clusterName'
63+
);
6164

62-
if (!urlParamClusterName && this.activeCluster?.clusterName) {
65+
const hasClusterNameParam = Boolean(urlParams.clusterName);
66+
67+
if (
68+
routeSupportsClusterNameParam &&
69+
!hasClusterNameParam &&
70+
this.activeCluster?.clusterName
71+
) {
6372
// in some cases users have urls that are generic (with no cluster name specified) those are used when we want to auto redirect the user to one of the clusters by default without carring about which cluster.
6473
dispatch(ROUTE_REPLACE, {
6574
name: state.route.name,

client/test/domain.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ describe('Domain ', () => {
9595
.startingAt('/domains/ci-test')
9696
.go();
9797

98-
const configEl = await testEl.waitUntilExists('section.domain');
99-
10098
return [testEl, scenario];
10199
}
102100

0 commit comments

Comments
 (0)