Skip to content

Commit

Permalink
Merge pull request #885 from signal18/react
Browse files Browse the repository at this point in the history
fixed issue-877, fixed graph and top feedbacks, completed alert settings
  • Loading branch information
svaroqui authored Sep 24, 2024
2 parents 7d58b23 + b3cede9 commit 96e593a
Show file tree
Hide file tree
Showing 25 changed files with 1,251 additions and 453 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ function DBConfigs({ selectedCluster, user }) {
setConfirmTitle(title)
setIsConfirmModalOpen(true)
setConfirmHandler(
() => () => dispatch(dropDBTag({ clusterName: selectedCluster?.name, tag: tag.name }))
() => () => dispatch(dropDBTag({ clusterName: selectedCluster?.name, tag: tag?.name }))
)
}}
used={true}
Expand Down
1 change: 0 additions & 1 deletion share/dashboard_react/src/Pages/Dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function Dashboard({ selectedCluster, user }) {

<AccordionComponent heading={'Cluster Logs'} body={<Logs logs={selectedCluster?.log?.buffer} />} />
<AccordionComponent heading={'Job Logs'} body={<Logs logs={selectedCluster?.logTask?.buffer} />} />
<AccordionComponent heading={'Tests'} body={<RunTests selectedCluster={selectedCluster} />} />
</Flex>
)
}
Expand Down
20 changes: 12 additions & 8 deletions share/dashboard_react/src/Pages/Graphs/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
.graphs {
position: relative;
display: flex;
flex-direction: column;
// flex-direction: column;
flex-wrap: wrap;
justify-content: flex-start;
margin: 0 auto;
gap: rem(24);

.qpsGraph {
min-height: rem(200);
}
Expand All @@ -23,28 +27,28 @@
border-radius: $border-radius-xs;
}
.width360 {
width: rem(360);
min-width: rem(360);
text {
font-size: rem(11);
}
}
.width720 {
width: rem(720);
min-width: rem(720);
}
.width1080 {
width: rem(1080);
min-width: rem(1080);
}
.width1440 {
width: rem(1440);
min-width: rem(1440);
}
.width2160 {
width: rem(2160);
min-width: rem(2160);
}
.width2880 {
width: rem(2880);
min-width: rem(2880);
}
.width4320 {
width: rem(4320);
min-width: rem(4320);
}
}
}
12 changes: 8 additions & 4 deletions share/dashboard_react/src/Pages/Home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getClusterProxies,
getClusters,
getClusterServers,
getJobs,
getMonitoredData,
getQueryRules,
getShardSchema,
Expand All @@ -31,7 +32,7 @@ import Settings from '../Settings'
import Configs from '../Configs'
import Graphs from '../Graphs'
import Agents from '../Agents'
import Backups from '../Backups'
import Maintenance from '../Maintenance'
import Top from '../Top'
import Shards from '../Shards'
import QueryRules from '../QueryRules'
Expand Down Expand Up @@ -73,7 +74,7 @@ function Home() {
authorizedTabs.push('Agents')
}
if (apiUser.grants['cluster-show-backups']) {
authorizedTabs.push('Backups')
authorizedTabs.push('Maintenance')
}
if (apiUser.grants['db-show-process']) {
authorizedTabs.push('Tops')
Expand Down Expand Up @@ -135,8 +136,9 @@ function Home() {
if (dashboardTabsRef.current[selectedTabRef.current - 1] === 'Configs') {
dispatch(getClusterCertificates({ clusterName: selectedClusterNameRef.current }))
}
if (dashboardTabsRef.current[selectedTabRef.current - 1] === 'Backups') {
if (dashboardTabsRef.current[selectedTabRef.current - 1] === 'Maintenance') {
dispatch(getBackupSnapshot({ clusterName: selectedClusterNameRef.current }))
dispatch(getJobs({ clusterName: selectedClusterNameRef.current }))
}
if (dashboardTabsRef.current[selectedTabRef.current - 1] === 'Tops') {
dispatch(getTopProcess({ clusterName: selectedClusterNameRef.current }))
Expand Down Expand Up @@ -178,7 +180,9 @@ function Home() {
<Configs user={user} selectedCluster={selectedCluster} />,
...(selectedCluster?.config?.graphiteMetrics && user?.grants['cluster-show-graphs'] ? [<Graphs />] : []),
...(user?.grants['cluster-show-agents'] ? [<Agents user={user} selectedCluster={selectedCluster} />] : []),
...(user?.grants['cluster-show-backups'] ? [<Backups selectedCluster={selectedCluster} />] : []),
...(user?.grants['cluster-show-backups']
? [<Maintenance user={user} selectedCluster={selectedCluster} />]
: []),
...(user?.grants['db-show-process'] ? [<Top selectedCluster={selectedCluster} />] : []),
...(selectedCluster?.config?.proxysql && user?.grants['cluster-show-agents']
? [<QueryRules selectedCluster={selectedCluster} />]
Expand Down
140 changes: 140 additions & 0 deletions share/dashboard_react/src/Pages/Maintenance/DatabaseJobs/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { HStack, VStack, Text, Tag } from '@chakra-ui/react'
import React, { useEffect, useMemo, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import AccordionComponent from '../../../components/AccordionComponent'
import { DataTable } from '../../../components/DataTable'
import styles from './styles.module.scss'
import { createColumnHelper } from '@tanstack/react-table'
import TagPill from '../../../components/TagPill'
import { canCancelJob, formatDate } from '../../../utility/common'
import ServerStatus from '../../../components/ServerStatus'
import RMIconButton from '../../../components/RMIconButton'
import { FaTrash } from 'react-icons/fa'
import ConfirmModal from '../../../components/Modals/ConfirmModal'
import { cancelServerJob } from '../../../redux/clusterSlice'

function DatabaseJobs({ clusterName }) {
const {
cluster: { jobs, clusterServers }
} = useSelector((state) => state)
const dispatch = useDispatch()
const [isConfirmModalOpen, setIsConfirmModalOpen] = useState(false)
const [taskToCancel, setTaskToCancel] = useState(null)

const columnHelper = createColumnHelper()

const columns = useMemo(
() => [
columnHelper.accessor((row) => row.task, {
header: 'Task'
}),
columnHelper.accessor((row) => row.state, {
header: 'State',
cell: (info) => getJobState(info.getValue())
}),
columnHelper.accessor((row) => row.result, {
header: 'Desc'
}),
columnHelper.accessor((row) => formatDate(new Date(row.start * 1000)), {
header: 'Start'
}),
columnHelper.accessor((row) => formatDate(new Date(row.end * 1000)), {
header: 'End'
}),
columnHelper.accessor((row) => row, {
header: 'Cancel Task',
cell: (info) =>
canCancelJob(info.getValue()) ? (
<RMIconButton
className={styles.btnCancelTask}
tooltip={'Cancel task'}
icon={FaTrash}
iconFontsize='1rem'
onClick={() => {
openConfirmModal(info.getValue())
}}
/>
) : null
})
],
[]
)

const openConfirmModal = (taskData) => {
setIsConfirmModalOpen(true)
setTaskToCancel(taskData)
}

const closeConfirmModal = () => {
setIsConfirmModalOpen(false)
setTaskToCancel(null)
}

const handleCancelTask = (serverId, taskId) => {
dispatch(cancelServerJob({ clusterName, serverId, taskId }))
}

const getJobState = (state) => {
switch (state.toString()) {
case '0':
return <TagPill text={'Init'} />
case '1':
return <TagPill colorScheme='blue' text={'Running'} />
case '2':
return <TagPill colorScheme='orange' text={'Halted'} />
case '3':
return <TagPill colorScheme='blue' text={'Done'} />
case '4':
return <TagPill colorScheme='green' text={'Success'} />
case '5':
return <TagPill colorScheme='red' text={'Error'} />
case '6':
return <TagPill colorScheme='red' text={'PTError'} />
}
}

return (
<VStack className={styles.jobsContainer}>
{jobs?.servers &&
Object.entries(jobs.servers).map((entry) => {
const [dbId, jobServer] = entry
const dbServer = clusterServers.find((server) => server.url === jobServer.serverUrl)
const serverStatus = dbServer?.state || ''
const updatedTasks = [...jobServer.tasks].map((task) => {
const updatedTask = { ...task }
updatedTask.dbId = dbId
updatedTask.dbhost = dbServer?.host
updatedTask.dbport = dbServer?.port
return updatedTask
})

return (
<AccordionComponent
className={styles.accordion}
headerClassName={styles.accordionHeader}
heading={
<HStack>
<Text> {jobServer.serverUrl}</Text>
<ServerStatus state={serverStatus} isVirtualMaster={dbServer?.isVirtualMaster} isBlinking={true} />
</HStack>
}
body={<DataTable data={updatedTasks} columns={columns} className={styles.table} />}
/>
)
})}
{isConfirmModalOpen && (
<ConfirmModal
isOpen={isConfirmModalOpen}
closeModal={closeConfirmModal}
title={`Warning! \n\n This action will forcefully cancel the job. Ensure the job is not currently running.\n\n Confirm to proceed with the cancellation of task id ${taskToCancel.id} on server ${taskToCancel.dbhost}:${taskToCancel.dbport} (${taskToCancel.dbId})`}
onConfirmClick={() => {
handleCancelTask(taskToCancel.dbId, taskToCancel.id)
closeConfirmModal()
}}
/>
)}
</VStack>
)
}

export default DatabaseJobs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.jobsContainer {
padding: rem(16);
.accordion {
width: 100%;
}
.accordionHeader {
background-color: var(--quaternary-color) !important;
}

tr[class*='headerRow'] {
background-color: var(--quaternary-color) !important;
}
.btnCancelTask {
background-color: transparent;
svg {
fill: var(--primary-color);
}
&:hover {
background-color: transparent;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@ import { convertObjectToArray, formatBytes, formatDate, getBackupMethod, getBack
import AccordionComponent from '../../components/AccordionComponent'
import { DataTable } from '../../components/DataTable'
import styles from './styles.module.scss'
import { Box, HStack, VStack } from '@chakra-ui/react'
import { Box, HStack, useDisclosure, VStack } from '@chakra-ui/react'
import TableType3 from '../../components/TableType3'
import { useDispatch, useSelector } from 'react-redux'
import { getBackupSnapshot } from '../../redux/clusterSlice'
import BackupSettings from '../Settings/BackupSettings'
import SchedulerSettings from '../Settings/SchedulerSettings'
import Logs from '../Dashboard/components/Logs'
import DatabaseJobs from './DatabaseJobs'

function Backups({ selectedCluster }) {
function Maintenance({ selectedCluster, user }) {
const dispatch = useDispatch()
const [data, setData] = useState([])
const [snapshotData, setSnapshotData] = useState([])
const columnHelper = createColumnHelper()
const { isOpen: isBackupSettingsOpen, onToggle: onBackupSettingsToggle } = useDisclosure()

const {
cluster: { backupSnapshots }
Expand All @@ -33,7 +38,6 @@ function Backups({ selectedCluster }) {
setSnapshotData(backupSnapshots)
}
}, [backupSnapshots])
console.log('snapshotData::', snapshotData)

const columns = useMemo(
() => [
Expand Down Expand Up @@ -179,15 +183,28 @@ function Backups({ selectedCluster }) {
])
return (
<VStack className={styles.backupContainer}>
<AccordionComponent
heading={'Scheduler Settings'}
className={styles.accordion}
panelClassName={styles.accordionPanel}
body={<SchedulerSettings selectedCluster={selectedCluster} user={user} />}
/>
<AccordionComponent
heading={'Backups Settings'}
isOpen={isBackupSettingsOpen}
onToggle={onBackupSettingsToggle}
className={styles.accordion}
panelClassName={styles.accordionPanel}
body={<BackupSettings selectedCluster={selectedCluster} user={user} />}
/>
<AccordionComponent
heading={'Current Backups'}
allowToggle={false}
className={styles.accordion}
panelClassName={styles.accordionPanel}
body={<DataTable data={data} columns={columns} className={styles.table} />}
/>
<AccordionComponent
heading={'Backup Snapshots'}
allowToggle={false}
className={styles.accordion}
panelClassName={styles.accordionPanel}
body={
Expand All @@ -197,8 +214,20 @@ function Backups({ selectedCluster }) {
</VStack>
}
/>
<AccordionComponent
heading={'Database Jobs'}
className={styles.accordion}
panelClassName={styles.accordionPanel}
body={<DatabaseJobs clusterName={selectedCluster?.name} />}
/>
<AccordionComponent
className={styles.accordion}
panelClassName={styles.accordionPanel}
heading={'Job Logs'}
body={<Logs logs={selectedCluster?.logTask?.buffer} />}
/>
</VStack>
)
}

export default Backups
export default Maintenance
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
}
}
}
.table {
tr[class*='headerRow'] {
background-color: var(--quaternary-color) !important;
}
}
}
}
Loading

0 comments on commit 96e593a

Please sign in to comment.