-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds sort buttons, graph for qrep (#763)
<img width="886" alt="Screenshot 2023-12-06 at 4 38 37 PM" src="https://github.com/PeerDB-io/peerdb/assets/65964360/9770d68c-e261-4dbd-b092-0fa277f6d3dc"> Changes default to Batch ID by descending in CDC page: <img width="1521" alt="Screenshot 2023-12-06 at 4 41 38 PM" src="https://github.com/PeerDB-io/peerdb/assets/65964360/14029590-e09a-465a-be19-157063a9e105">
- Loading branch information
1 parent
1c92ac3
commit d137300
Showing
9 changed files
with
166 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use client'; | ||
import { formatGraphLabel, timeOptions } from '@/app/utils/graph'; | ||
import { Label } from '@/lib/Label'; | ||
import { BarChart } from '@tremor/react'; | ||
import { useEffect, useState } from 'react'; | ||
import ReactSelect from 'react-select'; | ||
import aggregateCountsByInterval from '../../../edit/[mirrorId]/aggregatedCountsByInterval'; | ||
|
||
type QrepStatusRow = { | ||
partitionID: string; | ||
startTime: Date | null; | ||
endTime: Date | null; | ||
numRows: number | null; | ||
}; | ||
|
||
function QrepGraph({ syncs }: { syncs: QrepStatusRow[] }) { | ||
let [aggregateType, setAggregateType] = useState('hour'); | ||
const initialCount: [string, number][] = []; | ||
let [counts, setCounts] = useState(initialCount); | ||
|
||
useEffect(() => { | ||
let rows = syncs.map((sync) => ({ | ||
timestamp: sync.startTime!, | ||
count: sync.numRows ?? 0, | ||
})); | ||
|
||
let counts = aggregateCountsByInterval(rows, aggregateType); | ||
counts = counts.slice(0, 29); | ||
counts = counts.reverse(); | ||
setCounts(counts); | ||
}, [aggregateType, syncs]); | ||
|
||
return ( | ||
<div> | ||
<div className='float-right'> | ||
<ReactSelect | ||
id={aggregateType} | ||
placeholder='Select a timeframe' | ||
options={timeOptions} | ||
defaultValue={{ label: 'hour', value: 'hour' }} | ||
onChange={(val, _) => val && setAggregateType(val.value)} | ||
/> | ||
</div> | ||
<div style={{ height: '3rem' }}> | ||
<Label variant='headline'>Partition sync history</Label> | ||
</div> | ||
<BarChart | ||
className='mt-3' | ||
data={counts.map((count) => ({ | ||
name: formatGraphLabel(new Date(count[0]), aggregateType), | ||
'Rows synced at a point in time': count[1], | ||
}))} | ||
index='name' | ||
categories={['Rows synced at a point in time']} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default QrepGraph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import moment from 'moment'; | ||
|
||
export const timeOptions = [ | ||
{ label: '1min', value: '1min' }, | ||
{ label: '5min', value: '5min' }, | ||
{ label: '15min', value: '15min' }, | ||
{ label: 'hour', value: 'hour' }, | ||
{ label: 'day', value: 'day' }, | ||
{ label: 'month', value: 'month' }, | ||
]; | ||
|
||
export function formatGraphLabel(date: Date, aggregateType: String): string { | ||
switch (aggregateType) { | ||
case '1min': | ||
case '5min': | ||
case '15min': | ||
case 'hour': | ||
return moment(date).format('MMM Do HH:mm'); | ||
case 'day': | ||
return moment(date).format('MMM Do'); | ||
case 'month': | ||
return moment(date).format('MMM yy'); | ||
default: | ||
return 'Unknown aggregate type: ' + aggregateType; | ||
} | ||
} |