Skip to content

Commit 267d3c2

Browse files
authored
Jonatan/mon 1894 monitor form bugs (#14)
1 parent a472f6c commit 267d3c2

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ COPY backend/requirements.txt ./
4444
# TODO: not secure, use docker build-kit instead
4545
ARG DEEPCHECKS_CI_TOKEN
4646

47-
RUN pip install -U pip \
48-
&& pip install -q -r requirements.txt --compile --no-cache-dir
47+
RUN pip install -U pip==22.0.4 setuptools==58.3.0 && \
48+
pip install -q -r requirements.txt --compile --no-cache-dir
4949
# && apk del .build-deps
5050

5151
RUN pip install pyinstrument

backend/makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ requirements: $(ENV)
136136

137137
dev-requirements: $(ENV)
138138
@echo "#### installing development dependencies, it could take some time, please wait! ####"
139-
@$(PIP) install -U pip
139+
@$(PIP) install -U pip==22.0.4 setuptools==58.3.0
140140
@$(PIP) install -q -e ./client
141141
@$(PIP) install -q -r ./dev-requirements.txt
142142

@@ -172,7 +172,7 @@ test: requirements dev-requirements
172172
test-win:
173173
@test -d $(WIN_ENV) || python -m venv $(WIN_ENV)
174174
@$(WIN_ENV)\Scripts\activate.bat
175-
@$(PIP_WIN) install -U pip
175+
@$(PIP_WIN) install -U pip==22.0.4 setuptools==58.3.0
176176
@$(PIP_WIN) install -q -r ./requirements.txt -r ./dev-requirements.txt
177177
python -m pytest $(WIN_TESTDIR)
178178

frontend/src/components/Dashboard/MonitorDrawer/MonitorDrawer.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useCallback } from 'react';
1+
import React, { useState, useCallback, useMemo } from 'react';
22
import { ChartData } from 'chart.js';
33

44
import {
@@ -49,10 +49,11 @@ export const MonitorDrawer = ({
4949
const [graphFrequency, setGraphFrequency] = useState<SelectValues>(monitor?.frequency || '');
5050
const [reset, setReset] = useState(false);
5151

52-
const timeFreq =
53-
(graphFrequency && +graphFrequency) || monitor
54-
? FrequencyMap[monitor?.frequency as Frequency]
55-
: frequencyValues.DAY;
52+
const timeFreq = useMemo(() => {
53+
if (graphFrequency) return +graphFrequency;
54+
if (monitor) return FrequencyMap[monitor?.frequency as Frequency];
55+
return frequencyValues.DAY;
56+
}, [graphFrequency])
5657

5758
const handleGraphLookBack = useCallback(
5859
async (checkId: SelectValues, data: MonitorOptions) => {

frontend/src/components/Dashboard/MonitorDrawer/components/MonitorForm/MonitorForm.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import useModels from 'helpers/hooks/useModels';
1414
import { TextField, Stack, MenuItem, OutlinedInput, Typography } from '@mui/material';
1515

1616
import { MarkedSelect } from 'components/MarkedSelect';
17-
import { ControlledMarkedSelect } from 'components/MarkedSelect/ControlledMarkedSelect';
17+
import { ControlledMarkedSelect, ControlledMarkedSelectDisabledCallback } from 'components/MarkedSelect/ControlledMarkedSelect';
1818
import { SelectCheck as Check } from 'components/SelectCheck';
1919
import { SelectColumn as Column } from 'components/SelectColumn';
2020
import { TooltipInputWrapper } from 'components/TooltipInputWrapper';
@@ -226,6 +226,20 @@ export const MonitorForm = ({
226226
setColumn('');
227227
};
228228

229+
const isDisabledLookback = useCallback((lookbackSelect: { label: string; value: number }) => {
230+
if (frequency === undefined) return false;
231+
if (lookbackSelect.value < frequency ) return true;
232+
if (lookbackSelect.value > +frequency * 31 ) return true;
233+
return false;
234+
}, [frequency]);
235+
236+
useEffect(() => {
237+
const filteredLookbacks = lookbackTimeWindow.filter(val => !isDisabledLookback(val)).map(val => val.value);
238+
if (lookBack && !filteredLookbacks.includes(+lookBack)) {
239+
setLookBack(filteredLookbacks.at(-1));
240+
}
241+
}, [frequency])
242+
229243
useEffect(() => {
230244
if (isDrawerOpen) {
231245
if (currentModel && lookBack && frequency && aggregationWindow) {
@@ -379,6 +393,7 @@ export const MonitorForm = ({
379393
value={lookBack}
380394
setValue={setLookBack}
381395
clearValue={clearLookBack}
396+
DisabledCallback={isDisabledLookback as ControlledMarkedSelectDisabledCallback}
382397
required
383398
error={error && !lookBack}
384399
fullWidth

frontend/src/components/MarkedSelect/ControlledMarkedSelect.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import { SelectChangeEvent, MenuItem, SelectProps } from '@mui/material';
55
import { MarkedSelect } from 'components/MarkedSelect';
66

77
export type ControlledMarkedSelectSelectValues = string | number | undefined;
8+
export type ControlledMarkedSelectSelectValueType = (ControlledMarkedSelectSelectValues | { label: string; value: number })
9+
export type ControlledMarkedSelectDisabledCallback = (value: ControlledMarkedSelectSelectValueType) => boolean;
810

911
interface ControlledMarkedSelectProps extends SelectProps {
10-
values: (ControlledMarkedSelectSelectValues | { label: string; value: number })[];
12+
values: ControlledMarkedSelectSelectValueType[];
1113
value: ControlledMarkedSelectSelectValues;
1214
setValue: Dispatch<SetStateAction<ControlledMarkedSelectSelectValues>>;
1315
clearValue?: () => void;
16+
DisabledCallback?: ControlledMarkedSelectDisabledCallback;
1417
}
1518

1619
export const ControlledMarkedSelectComponent = ({
@@ -19,6 +22,7 @@ export const ControlledMarkedSelectComponent = ({
1922
value,
2023
setValue,
2124
clearValue,
25+
DisabledCallback,
2226
...props
2327
}: ControlledMarkedSelectProps) => {
2428
const handleValueChange = (event: SelectChangeEvent<unknown>) => setValue(event.target.value as string | number);
@@ -29,7 +33,7 @@ export const ControlledMarkedSelectComponent = ({
2933
const isObj = typeof value === 'object';
3034

3135
return (
32-
<MenuItem key={`${value}${index}`} value={isObj ? value.value : value}>
36+
<MenuItem key={`${value}${index}`} value={isObj ? value.value : value} disabled={DisabledCallback !== undefined ? DisabledCallback(value) : false}>
3337
{isObj ? value.label : value}
3438
</MenuItem>
3539
);

makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ $(ENV):
127127
@echo "#### Creating Python Vertual Enviroment [ $(ENV) ] ####"
128128
@test -d $(ENV) || $(ext_py) -m venv $(ENV)
129129
@$(PIP) install -e backend/
130-
@$(PIP) install -U pip
130+
@$(PIP) install -U pip==22.0.4 setuptools==58.3.0
131131

132132

133133
requirements: $(ENV)
@@ -173,7 +173,7 @@ test:
173173
test-win:
174174
@test -d $(WIN_ENV) || python -m venv $(WIN_ENV)
175175
@$(WIN_ENV)\Scripts\activate.bat
176-
@$(PIP_WIN) install -U pip
176+
@$(PIP_WIN) install -U pip==22.0.4 setuptools==58.3.0
177177
@$(PIP_WIN) install -q -r ./requirements.txt -r ./dev-requirements.txt
178178
python -m pytest $(WIN_TESTDIR)
179179

0 commit comments

Comments
 (0)