Skip to content

Commit dff1d7d

Browse files
committed
#188: Add flush backend-cache button in each view
Signed-off-by: Ziqi He <[email protected]>
1 parent ba6b2f0 commit dff1d7d

File tree

6 files changed

+111
-7
lines changed

6 files changed

+111
-7
lines changed

frontend/src/assets/styles/dashboard.scss

+17-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@
3434
display: flex;
3535
flex-direction: column;
3636
gap: 64px;
37+
position: relative;
38+
39+
.flush-cache-container {
40+
top: 0;
41+
right: 0;
42+
.flush-cache-button {
43+
border-radius: $primary-radius;
44+
background-color: $primary-blue;
45+
}
46+
}
3747
}
3848

3949
.secondary-dashboard {
@@ -105,7 +115,7 @@
105115
overflow: auto;
106116
}
107117

108-
.MuiPaper-root.MuiPaper-elevation.MuiPaper-rounded {
118+
.MuiPaper-root.MuiPaper-elevation.MuiPaper-rounded:not(.MuiAlert-root) {
109119
box-shadow: none;
110120
border-top: 1px solid $primary-grey;
111121
border-bottom: 1px solid $primary-grey;
@@ -127,10 +137,10 @@
127137
.message-box-wrapper.MuiBox-root {
128138
background-color: $primary-white;
129139
width: 80%;
130-
height: 80vh;
140+
height: 80vh;
131141
top: 100px;
132142
overflow-y: hidden;
133-
padding-top: 0px;
143+
padding-top: 0px;
134144
position: relative;
135145
margin: 0 auto;
136146
border-radius: $primary-radius;
@@ -141,10 +151,10 @@
141151
padding: 34px;
142152
background-color: transparent;
143153
overflow-y: scroll;
144-
-ms-overflow-style: none; /* Internet Explorer 10+ */
145-
scrollbar-width: none; /* Firefox */
146-
&::-webkit-scrollbar {
147-
display: none; /* Safari and Chrome */
154+
-ms-overflow-style: none; /* Internet Explorer 10+ */
155+
scrollbar-width: none; /* Firefox */
156+
&::-webkit-scrollbar {
157+
display: none; /* Safari and Chrome */
148158
}
149159
.message-filter-wrapper {
150160
display: flex;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import * as React from 'react'
2+
import { Box, Button, Snackbar } from '@mui/material'
3+
import MuiAlert, { AlertProps } from '@mui/material/Alert'
4+
import config from '../../config'
5+
import axios from 'axios'
6+
7+
const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(
8+
props,
9+
ref
10+
) {
11+
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />
12+
})
13+
14+
export default function FlushCacheButton() {
15+
const [open, setOpen] = React.useState(false)
16+
// const [loading, setLoading] = React.useState(false)
17+
// const [success, setSuccess] = React.useState(false)
18+
const [error, setError] = React.useState(false)
19+
20+
/**
21+
* Call the backend api endpoint to flush the backend-cache
22+
*/
23+
const flushCache = () => {
24+
const url = config.backendUrl + '/api/cache/flush'
25+
axios
26+
.get(url)
27+
.then((response) => {
28+
if (response.status !== 200) {
29+
setError(true)
30+
}
31+
setError(false)
32+
})
33+
.catch((error) => {
34+
console.log(error.message)
35+
setError(true)
36+
})
37+
}
38+
39+
const handleClick = () => {
40+
flushCache()
41+
setOpen(true)
42+
}
43+
44+
const handleClose = (
45+
event?: React.SyntheticEvent | Event,
46+
reason?: string
47+
) => {
48+
if (reason === 'clickaway') {
49+
return
50+
}
51+
52+
setOpen(false)
53+
}
54+
55+
return (
56+
<Box sx={{ m: 1, position: 'absolute' }} className="flush-cache-container">
57+
<Button
58+
variant="contained"
59+
onClick={handleClick}
60+
className="flush-cache-button"
61+
>
62+
Flush Cache
63+
</Button>
64+
<Snackbar
65+
open={open}
66+
autoHideDuration={3000}
67+
onClose={handleClose}
68+
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
69+
>
70+
{error ? (
71+
<Alert severity="error" onClose={handleClose} sx={{ width: '100%' }}>
72+
Error when flush the cache
73+
</Alert>
74+
) : (
75+
<Alert
76+
onClose={handleClose}
77+
severity="success"
78+
sx={{ width: '100%' }}
79+
>
80+
Cache flushed!
81+
</Alert>
82+
)}
83+
</Snackbar>
84+
</Box>
85+
)
86+
}

frontend/src/routes/cluster/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { selectCluster } from '../../store/filterSlice'
1010
import { selectTrigger } from '../requestTriggerSlice'
1111
import config from '../../config'
1212
import { Masonry } from 'react-plock'
13+
import FlushCacheButton from '../../components/buttons/FlushCacheButton'
1314

1415
export interface ResponseCluster {
1516
clusters: ClusterInfo[]
@@ -49,6 +50,7 @@ const ClusterGroup: React.FC = () => {
4950
Tenants: {sumElements(data, 'numberOfTenants')}, Namespaces:{' '}
5051
{sumElements(data, 'numberOfNamespaces')}
5152
</h3>
53+
<FlushCacheButton />
5254
{loading ? (
5355
<div className="main-card"> Loading...</div>
5456
) : error ? (

frontend/src/routes/namespace/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import NamespaceView from './NamespaceView'
1414
import { selectTrigger } from '../requestTriggerSlice'
1515
import config from '../../config'
1616
import { Masonry } from 'react-plock'
17+
import FlushCacheButton from '../../components/buttons/FlushCacheButton'
1718

1819
export interface ResponseNamespace {
1920
namespaces: NamespaceInfo[]
@@ -69,6 +70,7 @@ const NamespaceGroup: React.FC = () => {
6970
<div>
7071
<h2 className="dashboard-title">Available Namespaces ({data.length})</h2>
7172
<h3 className="dashboard-subtitle">Topics: {sumTopics(data)}</h3>
73+
<FlushCacheButton />
7274
{loading ? (
7375
<div className="main-card"> Loading...</div>
7476
) : error ? (

frontend/src/routes/tenant/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import TenantView from './TenantView'
1010
import { selectTrigger } from '../requestTriggerSlice'
1111
import config from '../../config'
1212
import { Masonry } from 'react-plock'
13+
import FlushCacheButton from '../../components/buttons/FlushCacheButton'
1314

1415
export interface ResponseTenant {
1516
tenants: TenantInfo[]
@@ -62,6 +63,7 @@ const TenantGroup: React.FC = () => {
6263
Namespaces: {sumElements(data, 'numberOfNamespaces')}, Topics:{' '}
6364
{sumElements(data, 'numberOfTopics')}
6465
</h3>
66+
<FlushCacheButton />
6567
{loading ? (
6668
<div className="main-card"> Loading...</div>
6769
) : error ? (

frontend/src/routes/topic/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import config from '../../config'
1919
import { Masonry } from 'react-plock'
2020
import { Pagination } from '@mui/material'
2121
import { Box } from '@mui/system'
22+
import FlushCacheButton from '../../components/buttons/FlushCacheButton'
2223

2324
export interface ResponseTopic {
2425
topics: TopicInfo[]
@@ -106,6 +107,7 @@ const TopicGroup: React.FC = () => {
106107
Producers: {sumElements(data, 'producers')}, Subscriptions:{' '}
107108
{sumElements(data, 'subscriptions')}
108109
</h3>
110+
<FlushCacheButton />
109111
{loading ? (
110112
<div className="main-card"> Loading...</div>
111113
) : error ? (

0 commit comments

Comments
 (0)