Skip to content

Commit

Permalink
Add currently running calibration text
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Aug 28, 2024
1 parent 942217f commit 3ab5ccb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/components/APITable/APIStatusText/APIStatusText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type APIStatusTextProps = {
children: React.ReactNode;
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
color?: string;
style?: React.CSSProperties;
};

export default function APIStatusText(props: APIStatusTextProps) {
Expand All @@ -28,6 +29,7 @@ export default function APIStatusText(props: APIStatusTextProps) {
children,
size = 'sm',
color,
style,
} = props;

const tooltipText = React.useMemo(() => {
Expand All @@ -47,6 +49,7 @@ export default function APIStatusText(props: APIStatusTextProps) {
<Text
size={size}
className={classes.root}
style={style}
span
data-nodata={nodata}
data-error={error}
Expand Down
57 changes: 54 additions & 3 deletions src/components/APITables/OverwatcherTable/OverwatcherTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,35 @@ type OverwatcherResponse = {
observing: boolean;
calibrating: boolean;
allow_dome_calibrations: boolean;
safe: boolean;
night: boolean;
running_calibration: string | null;
};

type OverwatcherPillProps = {
value: boolean | undefined;
nodata: boolean;
useErrorColour?: boolean;
noColor?: string;
yesColor?: string;
};

function OverwatcherPill(props: OverwatcherPillProps) {
const { value, nodata, useErrorColour = false } = props;
const {
value,
nodata,
useErrorColour = false,
yesColor = 'lime.9',
noColor = 'dark.5',
} = props;

const text = value ? 'Yes' : 'No';

let colour: string;
if (useErrorColour && !value) {
colour = 'red.9';
} else {
colour = value ? 'lime.9' : 'dark.5';
colour = value ? yesColor : noColor;
}

return (
Expand Down Expand Up @@ -85,6 +96,36 @@ function EnabledGroup(props: EnabledGroupProps & OverwatcherPillProps) {
);
}

function CalibrationGroup(props: {
data: OverwatcherResponse | null;
nodata: boolean;
}) {
const { data, nodata } = props;

const tooltipText = `Running calibration: ${data?.running_calibration || ''}`;
return (
<Group gap="xs">
<OverwatcherPill value={true} nodata={nodata} />
<Box style={{ flexGrow: 1 }} />
<APIStatusText
nodata={nodata}
defaultTooltipText={tooltipText}
size="xs"
style={{
paddingRight: 16,
maxWidth: 190,
whiteSpace: 'nowrap',
textOverflow: 'ellipsis',
overflow: 'hidden',
textAlign: 'right',
}}
>
{data?.running_calibration}
</APIStatusText>
</Group>
);
}

export default function OverwatcherTable() {
const [data, , noData, refresh] = useAPICall<OverwatcherResponse>(
'/overwatcher/status',
Expand Down Expand Up @@ -116,7 +157,17 @@ export default function OverwatcherTable() {
{
key: 'calibrating',
label: 'Calibrating',
value: <OverwatcherPill value={data?.calibrating} nodata={noData} />,
value: <CalibrationGroup data={data} nodata={noData} />,
},
{
key: 'safe',
label: 'Safe',
value: <OverwatcherPill value={data?.safe} nodata={noData} noColor="red.9" />,
},
{
key: 'night',
label: 'Night',
value: <OverwatcherPill value={data?.night} nodata={noData} />,
},
{
key: 'allow_dome_calibrations',
Expand Down

0 comments on commit 3ab5ccb

Please sign in to comment.