|
| 1 | +import { makeStyles } from '@material-ui/core' |
| 2 | +import { formatDistanceToNowStrict } from 'date-fns' |
| 3 | + |
| 4 | +import { colors } from '@postgres.ai/shared/styles/colors' |
| 5 | +import { formatBytesIEC } from '@postgres.ai/shared/utils/units' |
| 6 | +import { formatUTC, isValidDate } from '@postgres.ai/shared/utils/date' |
| 7 | + |
| 8 | +import { Property } from '../../../components/Property' |
| 9 | +import { ActionsMenu } from '../../Disk/ActionsMenu' |
| 10 | +import { Status } from '../../Disk/Status' |
| 11 | + |
| 12 | +export type DatasetInfo = { |
| 13 | + id: string | null |
| 14 | + name: string |
| 15 | + showName: boolean |
| 16 | + status: 'refreshing' | 'active' | 'empty' |
| 17 | + mode: string |
| 18 | + usedDataSize: number |
| 19 | + clonesCount: number |
| 20 | + snapshotsCount: number |
| 21 | + refreshingStartDate: Date | null |
| 22 | +} |
| 23 | + |
| 24 | +const useStyles = makeStyles( |
| 25 | + { |
| 26 | + root: { |
| 27 | + border: `1px solid ${colors.consoleStroke}`, |
| 28 | + padding: '6px 8px 8px', |
| 29 | + borderRadius: '4px', |
| 30 | + backgroundColor: colors.white, |
| 31 | + }, |
| 32 | + header: { |
| 33 | + display: 'flex', |
| 34 | + justifyContent: 'space-between', |
| 35 | + alignItems: 'center', |
| 36 | + }, |
| 37 | + titleWrapper: { |
| 38 | + display: 'flex', |
| 39 | + flex: '1 1 auto', |
| 40 | + alignItems: 'center', |
| 41 | + marginRight: '16px', |
| 42 | + minWidth: 0, |
| 43 | + }, |
| 44 | + title: { |
| 45 | + fontWeight: 700, |
| 46 | + fontSize: '14px', |
| 47 | + margin: '0 4px 0 0', |
| 48 | + whiteSpace: 'nowrap', |
| 49 | + textOverflow: 'ellipsis', |
| 50 | + overflow: 'hidden', |
| 51 | + }, |
| 52 | + content: { |
| 53 | + marginTop: '8px', |
| 54 | + }, |
| 55 | + uppercaseContent: { |
| 56 | + textTransform: 'uppercase', |
| 57 | + }, |
| 58 | + }, |
| 59 | + { index: 1 }, |
| 60 | +) |
| 61 | + |
| 62 | +export const DatasetRow = (props: DatasetInfo) => { |
| 63 | + const classes = useStyles() |
| 64 | + |
| 65 | + return ( |
| 66 | + <div className={classes.root}> |
| 67 | + <div className={classes.header}> |
| 68 | + {props.showName ? ( |
| 69 | + <div className={classes.titleWrapper}> |
| 70 | + <h6 title={props.name} className={classes.title}> |
| 71 | + {props.name} |
| 72 | + </h6> |
| 73 | + <ActionsMenu |
| 74 | + poolId={props.id} |
| 75 | + poolName={props.id ?? props.name} |
| 76 | + isActive={props.status === 'active'} |
| 77 | + /> |
| 78 | + </div> |
| 79 | + ) : ( |
| 80 | + <ActionsMenu |
| 81 | + poolId={props.id} |
| 82 | + poolName={props.id ?? props.name} |
| 83 | + isActive={props.status === 'active'} |
| 84 | + /> |
| 85 | + )} |
| 86 | + <Status value={props.status} hasWarning={false} /> |
| 87 | + </div> |
| 88 | + |
| 89 | + <Property name="Mode" classes={{ content: classes.uppercaseContent }}> |
| 90 | + {props.mode} |
| 91 | + </Property> |
| 92 | + |
| 93 | + {props.status === 'refreshing' && props.refreshingStartDate && ( |
| 94 | + <div className={classes.content}> |
| 95 | + <Property name="Refreshing started at"> |
| 96 | + {formatUTC(props.refreshingStartDate, 'yyyy-MM-dd HH:mm:ss')} UTC ( |
| 97 | + {isValidDate(props.refreshingStartDate) |
| 98 | + ? formatDistanceToNowStrict(props.refreshingStartDate, { |
| 99 | + addSuffix: true, |
| 100 | + }) |
| 101 | + : '-'} |
| 102 | + ) |
| 103 | + </Property> |
| 104 | + </div> |
| 105 | + )} |
| 106 | + |
| 107 | + <div className={classes.content}> |
| 108 | + <Property name="Clones">{props.clonesCount}</Property> |
| 109 | + <Property name="Snapshots">{props.snapshotsCount}</Property> |
| 110 | + </div> |
| 111 | + |
| 112 | + <div className={classes.content}> |
| 113 | + <Property name="Size">{formatBytesIEC(props.usedDataSize)}</Property> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + ) |
| 117 | +} |
0 commit comments