Skip to content

Commit c2d238e

Browse files
authored
[ACM-11686] Add managedHub column to clusters table in global search results (stolostron#3494)
* Add managedHub column to clusters table in global search results Signed-off-by: zlayne <zlayne@redhat.com> * add translation Signed-off-by: zlayne <zlayne@redhat.com> --------- Signed-off-by: zlayne <zlayne@redhat.com>
1 parent 615ecf7 commit c2d238e

File tree

4 files changed

+113
-3
lines changed

4 files changed

+113
-3
lines changed

frontend/public/locales/en/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,7 @@
17341734
"manageClusterSet.form.section.table.description.second": "<bold>Important:</bold> assigning a resource to the cluster set will give all cluster set users permissions to the resource's namespace.",
17351735
"Managed by": "Managed by",
17361736
"Managed externally": "Managed externally",
1737+
"Managed hub": "Managed hub",
17371738
"managed.addCluster": "Add cluster",
17381739
"managed.ai.editCluster.configurationBreadcrumb": "configuration",
17391740
"managed.ai.editCluster.title": "Configure cluster",

frontend/src/routes/Home/Search/__snapshots__/searchDefinitions.test.tsx.snap

+80
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,85 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Correctly returns Cluster resource definitions in global search: SearchDefinitions-Cluster-globalhub 1`] = `
4+
Array [
5+
Object {
6+
"cell": <CreateGlobalSearchDetailsLink
7+
item={
8+
Object {
9+
"cluster": "test-cluster",
10+
"created": "2021-01-01T00:00:00Z",
11+
"kind": "Cluster",
12+
"label": "testLabel=label; testLabel1=label1",
13+
"managedHub": "global-hub",
14+
"name": "test-cluster",
15+
"namespace": "test-cluster",
16+
}
17+
}
18+
/>,
19+
"header": "Name",
20+
"sort": "name",
21+
},
22+
Object {
23+
"cell": "managedHub",
24+
"header": "Managed hub",
25+
"sort": "managedHub",
26+
},
27+
Object {
28+
"cell": "ManagedClusterConditionAvailable",
29+
"header": "Available",
30+
"sort": "ManagedClusterConditionAvailable",
31+
},
32+
Object {
33+
"cell": "HubAcceptedManagedCluster",
34+
"header": "Hub accepted",
35+
"sort": "HubAcceptedManagedCluster",
36+
},
37+
Object {
38+
"cell": "ManagedClusterJoined",
39+
"header": "Joined",
40+
"sort": "ManagedClusterJoined",
41+
},
42+
Object {
43+
"cell": "nodes",
44+
"header": "Nodes",
45+
"sort": "nodes",
46+
},
47+
Object {
48+
"cell": "kubernetesVersion",
49+
"header": "Kubernetes version",
50+
"sort": "kubernetesVersion",
51+
},
52+
Object {
53+
"cell": "cpu",
54+
"header": "CPU",
55+
"sort": "cpu",
56+
},
57+
Object {
58+
"cell": "memory",
59+
"header": "Memory",
60+
"sort": "memory",
61+
},
62+
Object {
63+
"cell": "-",
64+
"header": "Console URL",
65+
"sort": "consoleURL",
66+
},
67+
Object {
68+
"cell": <AcmLabels
69+
collapse={Array []}
70+
labels={
71+
Array [
72+
"testLabel=label",
73+
"testLabel1=label1",
74+
]
75+
}
76+
/>,
77+
"header": "Labels",
78+
"sort": "label",
79+
},
80+
]
81+
`;
82+
383
exports[`Correctly returns CreateApplicationTopologyLink - global search 1`] = `
484
<body>
585
<div>

frontend/src/routes/Home/Search/searchDefinitions.test.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,26 @@ test('Correctly returns all resource definitions', () => {
555555
})
556556
})
557557

558+
test('Correctly returns Cluster resource definitions in global search', () => {
559+
const testItem = {
560+
name: 'test-cluster',
561+
namespace: 'test-cluster',
562+
kind: 'Cluster',
563+
cluster: 'test-cluster',
564+
managedHub: 'global-hub',
565+
label: 'testLabel=label; testLabel1=label1',
566+
created: '2021-01-01T00:00:00Z',
567+
}
568+
const searchDefinitions = getSearchDefinitions((key) => key, true)
569+
const definition = searchDefinitions['cluster'].columns.map((col: any) => {
570+
if (typeof col.cell === 'function') {
571+
col.cell = col.cell(testItem)
572+
}
573+
return col
574+
})
575+
expect(definition).toMatchSnapshot(`SearchDefinitions-Cluster-globalhub`)
576+
})
577+
558578
test('Correctly returns resource with managedHub column', () => {
559579
const testItem = {
560580
cluster: 'testCluster',

frontend/src/routes/Home/Search/searchDefinitions.tsx

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ import { TFunction } from 'react-i18next'
1212
import { generatePath, Link } from 'react-router-dom'
1313
import { useTranslation } from '../../../lib/acm-i18next'
1414
import { NavigationPath } from '../../../NavigationPath'
15+
import { useRecoilValue, useSharedAtoms } from '../../../shared-recoil'
1516
import { AcmButton, AcmLabels } from '../../../ui-components'
1617
import { useAllClusters } from '../../Infrastructure/Clusters/ManagedClusters/components/useAllClusters'
1718

1819
export interface SearchDefinitions {
19-
(t: TFunction): ResourceDefinitions
20+
(t: TFunction, isGlobalHub?: boolean): ResourceDefinitions
2021
}
2122
export interface ResourceDefinitions {
2223
application: Record<'columns', SearchColumnDefinition[]>
@@ -56,7 +57,10 @@ export interface SearchColumnDefinition {
5657
cell: string | ((item: any) => JSX.Element | '-') | ((item: any) => string)
5758
}
5859

59-
export const getSearchDefinitions: SearchDefinitions = (t: TFunction) => {
60+
export const getSearchDefinitions: (t: TFunction, isGlobalHub?: boolean) => ResourceDefinitions = (
61+
t: TFunction,
62+
isGlobalHub?: boolean
63+
) => {
6064
return {
6165
application: {
6266
columns: [
@@ -75,6 +79,7 @@ export const getSearchDefinitions: SearchDefinitions = (t: TFunction) => {
7579
cluster: {
7680
columns: [
7781
AddColumn('name', t('Name')),
82+
...(isGlobalHub ? [AddColumn('managedHub', t('Managed hub'))] : []),
7883
AddColumn('ManagedClusterConditionAvailable', t('Available')),
7984
AddColumn('HubAcceptedManagedCluster', t('Hub accepted')),
8085
AddColumn('ManagedClusterJoined', t('Joined')),
@@ -370,8 +375,12 @@ export const getSearchDefinitions: SearchDefinitions = (t: TFunction) => {
370375

371376
export const useSearchDefinitions = () => {
372377
const { t } = useTranslation()
378+
const { isGlobalHubState, settingsState } = useSharedAtoms()
379+
const isGlobalHub = useRecoilValue(isGlobalHubState)
380+
const settings = useRecoilValue(settingsState)
381+
const globalHub = isGlobalHub && settings.globalSearchFeatureFlag === 'enabled'
373382

374-
return useMemo(() => getSearchDefinitions(t), [t])
383+
return useMemo(() => getSearchDefinitions(t, globalHub), [t, globalHub])
375384
}
376385

377386
export function GetAge(item: any, key: string) {

0 commit comments

Comments
 (0)