mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-14 03:25:57 +08:00
fix(BUG): error text is show to the user (#427)
* fix(BUG): error text is show to the user * fix(bug): retention condition is updated
This commit is contained in:
parent
5b691d26e4
commit
271ffbd1a1
@ -9,7 +9,12 @@ import React, { useCallback, useEffect, useState } from 'react';
|
|||||||
import { PayloadProps } from 'types/api/settings/getRetention';
|
import { PayloadProps } from 'types/api/settings/getRetention';
|
||||||
|
|
||||||
import Retention from './Retention';
|
import Retention from './Retention';
|
||||||
import { ButtonContainer, Container } from './styles';
|
import {
|
||||||
|
ButtonContainer,
|
||||||
|
Container,
|
||||||
|
ErrorText,
|
||||||
|
ErrorTextContainer,
|
||||||
|
} from './styles';
|
||||||
|
|
||||||
const GeneralSettings = (): JSX.Element => {
|
const GeneralSettings = (): JSX.Element => {
|
||||||
const [
|
const [
|
||||||
@ -29,6 +34,8 @@ const GeneralSettings = (): JSX.Element => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const [retentionPeroidTrace, setRetentionPeroidTrace] = useState<number>(0);
|
const [retentionPeroidTrace, setRetentionPeroidTrace] = useState<number>(0);
|
||||||
|
const [isDefaultMetrics, setIsDefaultMetrics] = useState<boolean>(false);
|
||||||
|
const [isDefaultTrace, setIsDefaultTrace] = useState<boolean>(false);
|
||||||
|
|
||||||
const onClickSaveHandler = useCallback(() => {
|
const onClickSaveHandler = useCallback(() => {
|
||||||
onModalToggleHandler();
|
onModalToggleHandler();
|
||||||
@ -43,10 +50,26 @@ const GeneralSettings = (): JSX.Element => {
|
|||||||
setModal((modal) => !modal);
|
setModal((modal) => !modal);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkMetricTraceDefault = (trace: number, metric: number): void => {
|
||||||
|
if (metric === -1) {
|
||||||
|
setIsDefaultMetrics(true);
|
||||||
|
} else {
|
||||||
|
setIsDefaultMetrics(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trace === -1) {
|
||||||
|
setIsDefaultTrace(true);
|
||||||
|
} else {
|
||||||
|
setIsDefaultTrace(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!loading && payload !== undefined) {
|
if (!loading && payload !== undefined) {
|
||||||
const { metrics_ttl_duration_hrs, traces_ttl_duration_hrs } = payload;
|
const { metrics_ttl_duration_hrs, traces_ttl_duration_hrs } = payload;
|
||||||
|
|
||||||
|
checkMetricTraceDefault(traces_ttl_duration_hrs, metrics_ttl_duration_hrs);
|
||||||
|
|
||||||
const traceValue = getSettingsPeroid(traces_ttl_duration_hrs);
|
const traceValue = getSettingsPeroid(traces_ttl_duration_hrs);
|
||||||
const metricsValue = getSettingsPeroid(metrics_ttl_duration_hrs);
|
const metricsValue = getSettingsPeroid(metrics_ttl_duration_hrs);
|
||||||
|
|
||||||
@ -61,14 +84,24 @@ const GeneralSettings = (): JSX.Element => {
|
|||||||
const onOkHandler = async (): Promise<void> => {
|
const onOkHandler = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
setPostApiLoading(true);
|
setPostApiLoading(true);
|
||||||
|
const retentionTraceValue =
|
||||||
|
retentionPeroidTrace === 0 && (payload?.traces_ttl_duration_hrs || 0) < 0
|
||||||
|
? payload?.traces_ttl_duration_hrs || 0
|
||||||
|
: retentionPeroidTrace;
|
||||||
|
|
||||||
|
const retentionMetricsValue =
|
||||||
|
retentionPeroidMetrics === 0 && (payload?.metrics_ttl_duration_hrs || 0) < 0
|
||||||
|
? payload?.metrics_ttl_duration_hrs || 0
|
||||||
|
: retentionPeroidMetrics;
|
||||||
|
|
||||||
const [tracesResponse, metricsResponse] = await Promise.all([
|
const [tracesResponse, metricsResponse] = await Promise.all([
|
||||||
setRetentionApi({
|
setRetentionApi({
|
||||||
duration: `${convertIntoHr(retentionPeroidTrace, selectedTracePeroid)}h`,
|
duration: `${convertIntoHr(retentionTraceValue, selectedTracePeroid)}h`,
|
||||||
type: 'traces',
|
type: 'traces',
|
||||||
}),
|
}),
|
||||||
setRetentionApi({
|
setRetentionApi({
|
||||||
duration: `${convertIntoHr(
|
duration: `${convertIntoHr(
|
||||||
retentionPeroidMetrics,
|
retentionMetricsValue,
|
||||||
selectedMetricsPeroid,
|
selectedMetricsPeroid,
|
||||||
)}h`,
|
)}h`,
|
||||||
type: 'metrics',
|
type: 'metrics',
|
||||||
@ -84,6 +117,9 @@ const GeneralSettings = (): JSX.Element => {
|
|||||||
placement: 'topRight',
|
placement: 'topRight',
|
||||||
description: 'Congrats. The retention periods were updated correctly.',
|
description: 'Congrats. The retention periods were updated correctly.',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
checkMetricTraceDefault(retentionTraceValue, retentionMetricsValue);
|
||||||
|
|
||||||
onModalToggleHandler();
|
onModalToggleHandler();
|
||||||
} else {
|
} else {
|
||||||
notifications.error({
|
notifications.error({
|
||||||
@ -112,10 +148,37 @@ const GeneralSettings = (): JSX.Element => {
|
|||||||
return <Spinner tip="Loading.." height="70vh" />;
|
return <Spinner tip="Loading.." height="70vh" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getErrorText = (): string => {
|
||||||
|
const getValue = (value: string): string =>
|
||||||
|
`Retention Peroid for ${value} is not set yet. Please set by choosing below`;
|
||||||
|
|
||||||
|
if (!isDefaultMetrics && !isDefaultTrace) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isDefaultMetrics && !isDefaultTrace) {
|
||||||
|
return `${getValue('Metrics')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isDefaultMetrics && isDefaultTrace) {
|
||||||
|
return `${getValue('Trace')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${getValue('Trace , Metrics')}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const errorText = getErrorText();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
{Element}
|
{Element}
|
||||||
|
|
||||||
|
{errorText && (
|
||||||
|
<ErrorTextContainer>
|
||||||
|
<ErrorText>{errorText}</ErrorText>
|
||||||
|
</ErrorTextContainer>
|
||||||
|
)}
|
||||||
|
|
||||||
<Retention
|
<Retention
|
||||||
text={'Retention Period for Metrics'}
|
text={'Retention Period for Metrics'}
|
||||||
selectedRetentionPeroid={selectedMetricsPeroid}
|
selectedRetentionPeroid={selectedMetricsPeroid}
|
||||||
|
@ -59,3 +59,17 @@ export const TextContainer = styled.div`
|
|||||||
min-width: 100px;
|
min-width: 100px;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export const ErrorTextContainer = styled.div`
|
||||||
|
&&& {
|
||||||
|
margin-top: 2rem;
|
||||||
|
margin-bottom: 2rem;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const ErrorText = styled(TypographyComponent)`
|
||||||
|
&&& {
|
||||||
|
color: #e89a3c;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user