Skip to content

Commit 6a793ea

Browse files
authored
MON-1440+1927+1928+1932 [Bug Fixes & Reference Comparison] (#24)
1 parent 56644a3 commit 6a793ea

File tree

17 files changed

+157
-68
lines changed

17 files changed

+157
-68
lines changed

cypress/e2e/analysis_screen_advanced.cy.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ describe("Analysis screen drilldown", () => {
1010
})
1111
.then(() => {
1212
cy.visit("/analysis");
13-
14-
// toggle comparison mode
15-
cy.contains("span", "Compare data with previous period").click({
13+
cy.contains("span", "Compare with previous period").click({
1614
force: true,
1715
});
1816
// cy.get('input[value="11/05/2022 - 11/08/2022"]')

frontend/src/components/AlertsDrawer/components/AlertsDrawerHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export const AlertsDrawerHeader = ({
141141
monitor?.additional_kwargs?.res_conf ? monitor?.additional_kwargs?.res_conf[0] : 'N/A',
142142
monitor?.data_filters ? `${monitor?.data_filters.filters[0].column}` : 'N/A',
143143
monitor?.frequency ? processFrequency(dayjs.duration(FrequencyMap[monitor.frequency], 'seconds')) : 'N/A',
144-
monitor?.aggregation_window ? processFrequency(dayjs.duration(monitor.aggregation_window, 'seconds')) : 'N/A'
144+
monitor?.aggregation_window ?? 'N/A'
145145
],
146146
[
147147
condition.operator,

frontend/src/components/AnalysisHeader/components/AnalysisHeaderOptions.tsx

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dayjs from 'dayjs';
44
import { ModelManagmentSchema, useGetModelAutoFrequencyApiV1ModelsModelIdAutoFrequencyGet } from 'api/generated';
55
import { AnalysisContext, frequencyData } from 'helpers/context/AnalysisProvider';
66

7-
import { MenuItem, SelectChangeEvent } from '@mui/material';
7+
import { Box, MenuItem, SelectChangeEvent } from '@mui/material';
88

99
import { DateRange } from 'components/DateRange';
1010
import { CustomStyledSelect } from 'components/CustomStyledSelect';
@@ -17,12 +17,20 @@ interface AnalysisHeaderOptions {
1717
model: ModelManagmentSchema;
1818
}
1919

20-
const MAX_WINDOWS_COUNT = 31
20+
const MAX_WINDOWS_COUNT = 31;
2121

2222
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2323
export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
24-
const { compareWithPreviousPeriod, setCompareWithPreviousPeriod, period, setPeriod, frequency, setFrequency } =
25-
useContext(AnalysisContext);
24+
const {
25+
compareWithPreviousPeriod,
26+
setCompareWithPreviousPeriod,
27+
period,
28+
setPeriod,
29+
frequency,
30+
setFrequency
31+
// compareByReference,
32+
// setCompareByReference
33+
} = useContext(AnalysisContext);
2634

2735
const [minDate, setMinDate] = useState<Date | null>(
2836
model.start_time && frequency ? dayjs.unix(model.start_time).toDate() : null
@@ -33,10 +41,10 @@ export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
3341

3442
useEffect(() => {
3543
if (frequency) {
36-
model.start_time && setMinDate(dayjs.unix(model.start_time).toDate())
37-
model.latest_time && setMaxDate(dayjs.unix(model.latest_time + frequencyValues.DAY).toDate())
44+
model.start_time && setMinDate(dayjs.unix(model.start_time).toDate());
45+
model.latest_time && setMaxDate(dayjs.unix(model.latest_time + frequencyValues.DAY).toDate());
3846
}
39-
}, [model, frequency])
47+
}, [model, frequency]);
4048

4149
const { data: defaultFrequency } = useGetModelAutoFrequencyApiV1ModelsModelIdAutoFrequencyGet(model.id, undefined, {
4250
query: {
@@ -48,8 +56,8 @@ export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
4856
if (startTime && endTime) {
4957
if (dayjs(startTime).isSame(dayjs(endTime))) {
5058
startTime.setDate(startTime.getDate() - 1);
51-
startTime.setHours(0,0,0,0);
52-
endTime.setHours(23,59,59,999);
59+
startTime.setHours(0, 0, 0, 0);
60+
endTime.setHours(23, 59, 59, 999);
5361
}
5462
setPeriod([startTime, endTime]);
5563
}
@@ -65,7 +73,9 @@ export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
6573
windows_count = 31;
6674
}
6775
if (period) {
68-
let start_date = dayjs(period[1]).subtract(value * windows_count, 'second').toDate();
76+
let start_date = dayjs(period[1])
77+
.subtract(value * windows_count, 'second')
78+
.toDate();
6979
if (model.start_time) {
7080
const model_start_date = dayjs.unix(model.start_time).toDate();
7181
if (model_start_date > start_date) {
@@ -79,11 +89,17 @@ export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
7989
const handleDateChange = (startTime: Date | undefined, endTime: Date | undefined) => {
8090
// limit selection to only 30 windows
8191
if (frequency && dayjs(startTime).isSame(dayjs(endTime))) {
82-
const newMin = dayjs(startTime).subtract(frequency * MAX_WINDOWS_COUNT, 'second').toDate();
83-
const newMax = dayjs(startTime).add(frequency * MAX_WINDOWS_COUNT, 'second').toDate();
84-
92+
const newMin = dayjs(startTime)
93+
.subtract(frequency * MAX_WINDOWS_COUNT, 'second')
94+
.toDate();
95+
96+
const newMax = dayjs(startTime)
97+
.add(frequency * MAX_WINDOWS_COUNT, 'second')
98+
.toDate();
99+
85100
if (model.start_time) {
86101
const modelStart = dayjs.unix(model.start_time).toDate();
102+
87103
if (modelStart > newMin) {
88104
setMinDate(modelStart);
89105
} else {
@@ -92,6 +108,7 @@ export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
92108
}
93109
if (model.latest_time) {
94110
const modelEnd = dayjs.unix(model.latest_time + frequencyValues.DAY).toDate();
111+
95112
if (modelEnd < newMax) {
96113
setMaxDate(modelEnd);
97114
} else {
@@ -132,14 +149,20 @@ export const AnalysisHeaderOptions = ({ model }: AnalysisHeaderOptions) => {
132149
</CustomStyledSelect>
133150
</>
134151
)}
135-
136152
<StyledDivider orientation="vertical" flexItem sx={{ marginRight: '29px' }} />
137-
138-
<SwitchButton
139-
checked={compareWithPreviousPeriod}
140-
setChecked={setCompareWithPreviousPeriod}
141-
label="Compare data with previous period"
142-
/>
153+
<Box display="flex" flexDirection="column" gap="8px">
154+
<SwitchButton
155+
checked={compareWithPreviousPeriod}
156+
setChecked={setCompareWithPreviousPeriod}
157+
label="Compare with previous period"
158+
/>
159+
{/* <SwitchButton
160+
checked={compareByReference}
161+
setChecked={setCompareByReference}
162+
label="Compare by reference"
163+
sx={{ marginRight: 'auto' }}
164+
/> */}
165+
</Box>
143166
</>
144167
);
145168
};

frontend/src/components/AnalysisItem/AnalysisItem.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { AnalysisItemProps } from './AnalysisItem.types';
1010
import { CheckFilterTypes, FilteredValues } from 'helpers/utils/checkUtil';
1111
import { events, reportEvent } from 'helpers/services/mixPanel';
1212
import { manipulateAnalysisItem } from './helpers/manipulateAnalysisItem';
13+
import { getReference } from './helpers/getReference';
1314

1415
import { AnalysisChartItemWithFilters } from './components/AnalysisChartItemWithFilters';
1516
import { AnalysisChartItem } from './components/AnalysisChartItem';
@@ -28,7 +29,8 @@ const AnalysisItem = ({
2829
frequency,
2930
activeFilters,
3031
height,
31-
graphHeight
32+
graphHeight,
33+
compareByReference
3234
}: AnalysisItemProps) => {
3335
const { observedContainerRef, isVisible } = useElementOnScreen();
3436
const { mutateAsync: runCheck, chartData } = useRunCheckLookback('line');
@@ -44,6 +46,7 @@ const AnalysisItem = ({
4446
const [filteredValues, setFilteredValues] = useState<FilteredValues>({} as FilteredValues);
4547
const [isMostWorstActive, setIsMostWorstActive] = useState(false);
4648
const [runLookBack, setRunLookBack] = useState(false);
49+
const [alertRules, setAlertRules] = useState([]);
4750

4851
const checkConf = useMemo(() => checkInfo && checkInfo.check_conf, [checkInfo?.check_conf]);
4952
const additionalKwargs = useMemo(() => {
@@ -77,6 +80,10 @@ const AnalysisItem = ({
7780
}
7881
}, [check.id, refetch]);
7982

83+
useEffect(() => {
84+
getReference({ check, compareByReference, additionalKwargs, setAlertRules });
85+
}, [compareByReference]);
86+
8087
useEffect(() => {
8188
manipulateAnalysisItem({
8289
isVisible,
@@ -113,7 +120,8 @@ const AnalysisItem = ({
113120
initialData,
114121
checksWithCustomProps,
115122
isVisible,
116-
runLookBack
123+
runLookBack,
124+
compareByReference
117125
]);
118126

119127
const diagramLineProps = {
@@ -124,7 +132,8 @@ const AnalysisItem = ({
124132
timeFreq: frequency,
125133
previousPeriodLabels: perviousPeriodLabels,
126134
analysis: true,
127-
height: { lg: graphHeight - 104, xl: graphHeight }
135+
height: { lg: graphHeight - 104, xl: graphHeight },
136+
alert_rules: alertRules
128137
};
129138

130139
const chartItemProps = {

frontend/src/components/AnalysisItem/AnalysisItem.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface AnalysisItemProps {
4343
) => void;
4444
height: number;
4545
graphHeight: number;
46+
compareByReference?: boolean;
4647
}
4748

4849
export interface RunCheckBody {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { CheckSchema, getCheckReferenceApiV1ChecksCheckIdRunReferencePost } from 'api/generated';
2+
3+
export interface GetReferenceProps {
4+
check: CheckSchema;
5+
compareByReference?: boolean;
6+
additionalKwargs: any;
7+
setAlertRules: (alertRules: any) => void;
8+
}
9+
10+
export const getReference = (props: GetReferenceProps) => {
11+
const { check, compareByReference, additionalKwargs, setAlertRules } = props;
12+
13+
if (compareByReference) {
14+
const getReferenceData = async () => {
15+
const response = await getCheckReferenceApiV1ChecksCheckIdRunReferencePost(check.id, {
16+
additional_kwargs: additionalKwargs
17+
});
18+
19+
if (response && (response as any[])[0]) {
20+
setAlertRules(response);
21+
}
22+
};
23+
24+
getReferenceData();
25+
} else {
26+
setAlertRules([]);
27+
}
28+
};

frontend/src/components/Dashboard/DataIngestion/DataIngestion.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const DataIngestion = ({ modelId }: DataIngestionProps) => {
7272
}, []);
7373

7474
useEffect(() => setStorageItem(storageKeys.dataIngestionTimeFilter, JSON.stringify(currentTime)), [currentTime]);
75+
7576
return (
7677
<StyledContainer>
7778
<StyledHeader>
@@ -107,12 +108,7 @@ export const DataIngestion = ({ modelId }: DataIngestionProps) => {
107108
</StyledLoaderBox>
108109
) : (
109110
<DiagramTutorialTooltip>
110-
<DiagramLine
111-
data={graphData}
112-
minTimeUnit={minTimeUnit}
113-
timeFreq={timeValue}
114-
height={{ lg: 259, xl: 362 }}
115-
></DiagramLine>
111+
<DiagramLine data={graphData} minTimeUnit={minTimeUnit} timeFreq={timeValue} height={{ lg: 259, xl: 362 }} />
116112
</DiagramTutorialTooltip>
117113
)}
118114
</StyledContainer>

frontend/src/components/Layout/Sidebar/components/SidebarMenuItem/SidebarMenuItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function SidebarMenuItemComponent({ info, onOpenSubMenu }: SidebarMenuItemProps)
2626
const { ActiveIcon, Icon, IconHover, link } = info;
2727
const active = location?.pathname.startsWith(link);
2828
const activeHover = hover && !active;
29+
const LinkWithParams = `${link}${window.location.search ?? ''}`;
2930

3031
const toggleSubMenu = (event: React.MouseEvent<HTMLDivElement>) => {
3132
event.stopPropagation();
@@ -195,7 +196,7 @@ function SidebarMenuItemComponent({ info, onOpenSubMenu }: SidebarMenuItemProps)
195196
) : (
196197
<StyledLinkWrapper
197198
onClick={e => goToLink(e, link)}
198-
to={link}
199+
to={LinkWithParams}
199200
active={active}
200201
onMouseLeave={onMouseLeave}
201202
onMouseOver={onMouseOver}

frontend/src/components/WorkspaceSettings/Billing/Billing.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,23 @@ import FirstBilling from './FirstBilling/FirstBilling';
88

99
import { Subscriptions } from './billing.types';
1010

11+
import { resError } from 'helpers/types/resError';
12+
1113
const Billing = () => {
1214
const [subscriptions, setSubscriptions] = useState<Subscriptions[]>([]);
1315
const [isLoading, setIsLoading] = useState(true);
1416

1517
const getSubscription = async () => {
1618
const response = (await getSubscriptionsApiV1BillingSubscriptionGet()) as Subscriptions[];
17-
response && setSubscriptions([...response]);
18-
setIsLoading(false);
19+
20+
if (response) {
21+
if ((response as unknown as resError).error_message) {
22+
setIsLoading(false);
23+
} else {
24+
setSubscriptions([...response]);
25+
setIsLoading(false);
26+
}
27+
}
1928
};
2029

2130
useEffect(() => {

frontend/src/components/WorkspaceSettings/Billing/BillingHistory/BillingHistory.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from 'react';
22

3-
import logger from 'helpers/services/logger';
43
import { ChargeSchema, listAllChargesApiV1BillingChargesGet } from 'api/generated';
54

65
import BillingTransaction from './BillingTransaction';
@@ -12,20 +11,24 @@ import { Col16Gap } from 'components/base/Container/Container.styles';
1211

1312
import { constants } from '../billing.constants';
1413

14+
import { resError } from 'helpers/types/resError';
15+
1516
const BillingHistory = () => {
1617
const [loading, setLoading] = useState(true);
1718
const [transactions, setTransactions] = useState<ChargeSchema[]>([]);
1819

1920
const tableHeaders = ['models', 'plan', 'status', 'created'];
2021

2122
const getBillingHistory = async () => {
22-
try {
23-
const response = await listAllChargesApiV1BillingChargesGet();
23+
const response = await listAllChargesApiV1BillingChargesGet();
2424

25-
response && setTransactions([...response]);
26-
setLoading(false);
27-
} catch (err) {
28-
logger.error(err);
25+
if (response) {
26+
if (response[0]) {
27+
setTransactions([...response]);
28+
setLoading(false);
29+
} else if ((response as unknown as resError).error_message) {
30+
setLoading(false);
31+
}
2932
}
3033
};
3134

0 commit comments

Comments
 (0)