Skip to content

Commit 2f7713a

Browse files
feat: Add modal to view full failover event (#1080)
* Add modal for viewing an individual failover event, which is shown when "See more" in the table is clicked Signed-off-by: Adhitya Mamallan <[email protected]>
1 parent 39e6497 commit 2f7713a

File tree

6 files changed

+569
-31
lines changed

6 files changed

+569
-31
lines changed

src/views/domain-page/domain-page-failover-active-active/__tests__/domain-page-failover-active-active.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ jest.mock(
2222
))
2323
);
2424

25+
jest.mock('../../domain-page-failover-modal/domain-page-failover-modal', () =>
26+
jest.fn(() => <div data-testid="mock-failover-modal">Modal</div>)
27+
);
28+
2529
describe(DomainPageFailoverActiveActive.name, () => {
2630
beforeEach(() => {
2731
jest.clearAllMocks();
@@ -61,6 +65,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
6165
).toBeInTheDocument();
6266
expect(screen.getByText('cluster-1 -> cluster-2')).toBeInTheDocument();
6367
expect(screen.getByText('See more')).toBeInTheDocument();
68+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
6469
});
6570

6671
it('renders cluster failover when matching non-primary cluster failover is found', () => {
@@ -101,6 +106,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
101106
).toBeInTheDocument();
102107
expect(screen.getByText('cluster-1 -> cluster-2')).toBeInTheDocument();
103108
expect(screen.getByText('See more')).toBeInTheDocument();
109+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
104110
});
105111

106112
it('does not render cluster failover section when clusterAttributeScope is set but clusterAttributeValue is undefined for non-primary scope', () => {
@@ -138,6 +144,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
138144
screen.queryByTestId('mock-single-cluster-failover')
139145
).not.toBeInTheDocument();
140146
expect(screen.getByText('See more')).toBeInTheDocument();
147+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
141148
});
142149

143150
it('does not render cluster failover section when no matching cluster failover is found', () => {
@@ -177,6 +184,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
177184
screen.queryByTestId('mock-single-cluster-failover')
178185
).not.toBeInTheDocument();
179186
expect(screen.getByText('See more')).toBeInTheDocument();
187+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
180188
});
181189

182190
it('does not render cluster failover section when clusterAttributeScope is undefined', () => {
@@ -211,6 +219,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
211219
screen.queryByTestId('mock-single-cluster-failover')
212220
).not.toBeInTheDocument();
213221
expect(screen.getByText('See more')).toBeInTheDocument();
222+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
214223
});
215224

216225
it('renders "See more" button even when no matching cluster failover is found', () => {
@@ -233,6 +242,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
233242
screen.queryByTestId('mock-single-cluster-failover')
234243
).not.toBeInTheDocument();
235244
expect(screen.getByText('See more')).toBeInTheDocument();
245+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
236246
});
237247

238248
it('selects the correct cluster failover when multiple cluster failovers exist', () => {
@@ -286,6 +296,7 @@ describe(DomainPageFailoverActiveActive.name, () => {
286296
screen.getByTestId('mock-single-cluster-failover')
287297
).toBeInTheDocument();
288298
expect(screen.getByText('cluster-3 -> cluster-4')).toBeInTheDocument();
299+
expect(screen.getByTestId('mock-failover-modal')).toBeInTheDocument();
289300
});
290301
});
291302

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { useMemo } from 'react';
1+
import { useMemo, useState } from 'react';
22

33
import { Button } from 'baseui/button';
44
import { MdVisibility } from 'react-icons/md';
55

66
import usePageQueryParams from '@/hooks/use-page-query-params/use-page-query-params';
77

88
import domainPageQueryParamsConfig from '../config/domain-page-query-params.config';
9+
import DomainPageFailoverModal from '../domain-page-failover-modal/domain-page-failover-modal';
910
import DomainPageFailoverSingleCluster from '../domain-page-failover-single-cluster/domain-page-failover-single-cluster';
1011
import { PRIMARY_CLUSTER_SCOPE } from '../domain-page-failovers/domain-page-failovers.constants';
1112
import clusterFailoverMatchesAttribute from '../helpers/cluster-failover-matches-attribute';
@@ -16,6 +17,7 @@ import { type Props } from './domain-page-failover-active-active.types';
1617
export default function DomainPageFailoverActiveActive({
1718
failoverEvent,
1819
}: Props) {
20+
const [isModalOpen, setIsModalOpen] = useState(false);
1921
const [{ clusterAttributeScope, clusterAttributeValue }] = usePageQueryParams(
2022
domainPageQueryParamsConfig
2123
);
@@ -42,35 +44,42 @@ export default function DomainPageFailoverActiveActive({
4244
]);
4345

4446
return (
45-
<styled.FailoverEventContainer>
46-
{clusterFailoverForMaybeSelectedAttribute && (
47-
<styled.ClusterFailoverContainer>
48-
<styled.ClusterAttributeLabel>
49-
{clusterAttributeScope === PRIMARY_CLUSTER_SCOPE
50-
? 'Primary:'
51-
: `${clusterAttributeScope} (${clusterAttributeValue}):`}
52-
</styled.ClusterAttributeLabel>
53-
<DomainPageFailoverSingleCluster
54-
fromCluster={
55-
clusterFailoverForMaybeSelectedAttribute.fromCluster
56-
?.activeClusterName
57-
}
58-
toCluster={
59-
clusterFailoverForMaybeSelectedAttribute.toCluster
60-
?.activeClusterName
61-
}
62-
/>
63-
</styled.ClusterFailoverContainer>
64-
)}
65-
<Button
66-
size="mini"
67-
kind="secondary"
68-
shape="pill"
69-
endEnhancer={<MdVisibility />}
70-
// TODO: open the failover modal here on click
71-
>
72-
See more
73-
</Button>
74-
</styled.FailoverEventContainer>
47+
<>
48+
<styled.FailoverEventContainer>
49+
{clusterFailoverForMaybeSelectedAttribute && (
50+
<styled.ClusterFailoverContainer>
51+
<styled.ClusterAttributeLabel>
52+
{clusterAttributeScope === PRIMARY_CLUSTER_SCOPE
53+
? 'Primary:'
54+
: `${clusterAttributeScope} (${clusterAttributeValue}):`}
55+
</styled.ClusterAttributeLabel>
56+
<DomainPageFailoverSingleCluster
57+
fromCluster={
58+
clusterFailoverForMaybeSelectedAttribute.fromCluster
59+
?.activeClusterName
60+
}
61+
toCluster={
62+
clusterFailoverForMaybeSelectedAttribute.toCluster
63+
?.activeClusterName
64+
}
65+
/>
66+
</styled.ClusterFailoverContainer>
67+
)}
68+
<Button
69+
size="mini"
70+
kind="secondary"
71+
shape="pill"
72+
endEnhancer={<MdVisibility />}
73+
onClick={() => setIsModalOpen(true)}
74+
>
75+
See more
76+
</Button>
77+
</styled.FailoverEventContainer>
78+
<DomainPageFailoverModal
79+
failoverEvent={failoverEvent}
80+
isOpen={isModalOpen}
81+
onClose={() => setIsModalOpen(false)}
82+
/>
83+
</>
7584
);
7685
}

0 commit comments

Comments
 (0)