mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-23 18:36:16 +00:00
* feat: logs explorer - new design * feat: update styles * feat: added new toolbar for logs explorer (#4336) * feat: logs list view changes (#4348) * feat: logs list view changes * fix: list view and toolbar styles * feat: side btns * feat: added auto refresh handler * feat: handle popover close for btn click date time * feat: extract the common log actions btn component * feat: update the button for log line actions * fix: event propagation from context button * feat: use styles from ui-library * Query builder design update (#4359) * feat: QB design update * fix: add functionality and light mode styles * fix: ts issues * fix: update all css color variables to correct names * fix: lint errors * feat: new table view for logs explorer list section (#4353) * feat: table view changes for logs list * feat: code refactor to support log line actions * feat: code refactor to support log line actions * fix: the positioning of the btns * feat: fix the table onclick * fix: header issue * fix: on hover * fix: type issue * fix: eslint error * fix: type errors (#4360) * feat: handle light theme for logs explorer design changes (#4363) * feat: handle light theme for list tables and dateTime selection * feat: handle light theme for popover * fix: address review comments * feat: date time custom time modal to render inside the new popover (#4366) * feat: single calender for range picker * fix: edgecases * feat: integrate date time selector across app * fix: remove dangling border after element removal * feat: handle qb design changes across the application * feat: handle light theme * feat: handle light theme * fix: virtuoso scroll refresh issue * feat: handle new typing changes for date time picker v2 (#4386) Co-authored-by: Yunus M <myounis.ar@live.com> * chore: styles improvement across new design (#4389) * fix: improve date time styles * feat: table view changes according to new design * fix: button visibility in clickhouse and promQL headers (#4390) * feat: change the tabs to new design buttons for query builder * Settings theme change (#4368) * feat: settings theme change * [Refactor]: New design for Log details page (#4362) New design for Log details page Co-authored-by: Vikrant Gupta <vikrant.thomso@gmail.com> Co-authored-by: Yunus M <myounis.ar@live.com> * feat: save view for new design (#4392) * feat: save view for new design * refactor: done with save view * feat: update styles for logs detail view (#4407) * feat: update styles for logs detail view * feat: update styles for logs detail view * feat: add raw view attributes in the logs list view (#4422) * feat: add raw view attributes in the logs list view * feat: add raw view attributes in the logs list view * fix: raw attributes * fix: logs UI improvements (#4426) * fix: remove fixed times from the date time picker v2 * fix: added old logs explorer CTA in new designs * feat: handle active logs indicator update * fix: address review comments * fix: old logs explorer page * fix: remove info text and add relative time buttons * fix: update logs explorer tab designs * fix: update logs explorer tab designs * fix: update logs explorer tab designs * refactor: New design for Save views. (#4435) * feat: [GH-4436]: date range enhancements (#4448) * feat: [GH-4436]: when selecting custom time range it should be from start of day to end of date * fix: custom time width and refresh text visibility issues (#4428) --------- Co-authored-by: Yunus M <myounis.ar@live.com> * feat: update ui (#4449) * feat: added loading and error states for logs design (#4452) * feat: added loading and error states for logs design * feat: added error states for table view and time series view * feat: handle error and loading states * feat: loading states * [Refactor]: Tab Switch deplay issue and UI improvement for Clickhouse (#4409) * fix: switching between logs display tabs (#4457) * [Feat]: View in Traces (#4450) * refactor: datetime selector beside run query removed add to dashboard * refactor: added tab for traces view details page * refactor: done with the save view in traces * fix: the gittery effect when navigatigating from views * refactor: view tab view title light mode support * refactor: removed console * fix: gittery effect when switch view from views tabs * refactor: separate traces routes * refactor: remove query params * chore: fix tsc issues * fix: jest config issues * fix: update TODO and remove extra braces * feat: handle loading states and incorporate ui feedback (#4479) * UI feedback updates (#4482) * feat: handle loading and fix ui issues * feat: ui updates * fix: logs explorer issues (#4483) * fix: logs explorer issues * fix: jest test cases * feat: support custom times unique to pages new design changes (#4485) * fix: loading states for list log view (#4486) * fix: logs search view query fix, logs details view - attribute tags alignment fix (#4489) * fix: delete empty file * fix: chart loading when scrolling logs (#4495) * fix: chart should not load when scrolling the logs as it is already fetched * fix: make the search bar as default rather than advanced options * fix: rename show context to show in context * fix: query range api not triggering on default select first load (#4498) * Refactor: Log Explorer UI changes. (#4502) * refactor: used selected view enum * refactor: updated hight of switch old button and tab border * refactor: import fixes * refactor: query builder border and button groups * refactor: removed hypen from refreshed * refactor: show delete button only when there is more than one query * refactor: sqaure up the query build button groups * refactor: updated css * fix: additional filter color button shadow * refactor: removed commented code and used selected panel enum * refactor: updated typecheck script * refactor: used enum selected view (#4504) * fix: retain the current query on date time change (#4510) * feat: added new icon for promQL and added tooltips for dashboards and alerts (#4512) * feat: added new icon for promQL and added tooltips for dashboards and alerts * fix: styles at 1440 px zoom * fix: rename clickhouse to clickHouse --------- Co-authored-by: Vikrant Gupta <54737045+Vikrant2520@users.noreply.github.com> Co-authored-by: Vikrant Gupta <vikrant.thomso@gmail.com> Co-authored-by: Rajat Dabade <rajat@signoz.io>
470 lines
14 KiB
TypeScript
470 lines
14 KiB
TypeScript
import './DateTimeSelectionV2.styles.scss';
|
|
|
|
import { SyncOutlined } from '@ant-design/icons';
|
|
import { Button } from 'antd';
|
|
import getLocalStorageKey from 'api/browser/localstorage/get';
|
|
import setLocalStorageKey from 'api/browser/localstorage/set';
|
|
import CustomTimePicker from 'components/CustomTimePicker/CustomTimePicker';
|
|
import { LOCALSTORAGE } from 'constants/localStorage';
|
|
import { QueryParams } from 'constants/query';
|
|
import {
|
|
initialQueryBuilderFormValuesMap,
|
|
PANEL_TYPES,
|
|
} from 'constants/queryBuilder';
|
|
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
|
import ROUTES from 'constants/routes';
|
|
import {
|
|
constructCompositeQuery,
|
|
defaultLiveQueryDataConfig,
|
|
} from 'container/LiveLogs/constants';
|
|
import { QueryHistoryState } from 'container/LiveLogs/types';
|
|
import dayjs, { Dayjs } from 'dayjs';
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
|
import { updateStepInterval } from 'hooks/queryBuilder/useStepInterval';
|
|
import useUrlQuery from 'hooks/useUrlQuery';
|
|
import GetMinMax from 'lib/getMinMax';
|
|
import getTimeString from 'lib/getTimeString';
|
|
import history from 'lib/history';
|
|
import { isObject } from 'lodash-es';
|
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
import { useQueryClient } from 'react-query';
|
|
import { connect, useSelector } from 'react-redux';
|
|
import { RouteComponentProps, withRouter } from 'react-router-dom';
|
|
import { bindActionCreators, Dispatch } from 'redux';
|
|
import { ThunkDispatch } from 'redux-thunk';
|
|
import { GlobalTimeLoading, UpdateTimeInterval } from 'store/actions';
|
|
import { AppState } from 'store/reducers';
|
|
import AppActions from 'types/actions';
|
|
import { ErrorResponse, SuccessResponse } from 'types/api';
|
|
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
|
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
|
|
|
import AutoRefresh from '../AutoRefreshV2';
|
|
import { DateTimeRangeType } from '../CustomDateTimeModal';
|
|
import {
|
|
getDefaultOption,
|
|
getOptions,
|
|
LocalStorageTimeRange,
|
|
Time,
|
|
TimeRange,
|
|
} from './config';
|
|
import RefreshText from './Refresh';
|
|
import { Form, FormContainer, FormItem } from './styles';
|
|
|
|
function DateTimeSelection({
|
|
showAutoRefresh,
|
|
location,
|
|
updateTimeInterval,
|
|
globalTimeLoading,
|
|
}: Props): JSX.Element {
|
|
const [formSelector] = Form.useForm();
|
|
|
|
const [hasSelectedTimeError, setHasSelectedTimeError] = useState(false);
|
|
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
|
|
const urlQuery = useUrlQuery();
|
|
const searchStartTime = urlQuery.get('startTime');
|
|
const searchEndTime = urlQuery.get('endTime');
|
|
const queryClient = useQueryClient();
|
|
|
|
const {
|
|
localstorageStartTime,
|
|
localstorageEndTime,
|
|
} = ((): LocalStorageTimeRange => {
|
|
const routes = getLocalStorageKey(LOCALSTORAGE.METRICS_TIME_IN_DURATION);
|
|
|
|
if (routes !== null) {
|
|
const routesObject = JSON.parse(routes || '{}');
|
|
const selectedTime = routesObject[location.pathname];
|
|
|
|
if (selectedTime) {
|
|
let parsedSelectedTime: TimeRange;
|
|
try {
|
|
parsedSelectedTime = JSON.parse(selectedTime);
|
|
} catch {
|
|
parsedSelectedTime = selectedTime;
|
|
}
|
|
|
|
if (isObject(parsedSelectedTime)) {
|
|
return {
|
|
localstorageStartTime: parsedSelectedTime.startTime,
|
|
localstorageEndTime: parsedSelectedTime.endTime,
|
|
};
|
|
}
|
|
return { localstorageStartTime: null, localstorageEndTime: null };
|
|
}
|
|
}
|
|
return { localstorageStartTime: null, localstorageEndTime: null };
|
|
})();
|
|
|
|
const getTime = useCallback((): [number, number] | undefined => {
|
|
if (searchEndTime && searchStartTime) {
|
|
const startDate = dayjs(
|
|
new Date(parseInt(getTimeString(searchStartTime), 10)),
|
|
);
|
|
const endDate = dayjs(new Date(parseInt(getTimeString(searchEndTime), 10)));
|
|
|
|
return [startDate.toDate().getTime() || 0, endDate.toDate().getTime() || 0];
|
|
}
|
|
if (localstorageStartTime && localstorageEndTime) {
|
|
const startDate = dayjs(localstorageStartTime);
|
|
const endDate = dayjs(localstorageEndTime);
|
|
|
|
return [startDate.toDate().getTime() || 0, endDate.toDate().getTime() || 0];
|
|
}
|
|
return undefined;
|
|
}, [
|
|
localstorageEndTime,
|
|
localstorageStartTime,
|
|
searchEndTime,
|
|
searchStartTime,
|
|
]);
|
|
|
|
const [options, setOptions] = useState(getOptions(location.pathname));
|
|
const [refreshButtonHidden, setRefreshButtonHidden] = useState<boolean>(false);
|
|
const [customDateTimeVisible, setCustomDTPickerVisible] = useState<boolean>(
|
|
false,
|
|
);
|
|
|
|
const { stagedQuery, initQueryBuilderData, panelType } = useQueryBuilder();
|
|
|
|
const handleGoLive = useCallback(() => {
|
|
if (!stagedQuery) return;
|
|
|
|
setIsOpen(false);
|
|
let queryHistoryState: QueryHistoryState | null = null;
|
|
|
|
const compositeQuery = constructCompositeQuery({
|
|
query: stagedQuery,
|
|
initialQueryData: initialQueryBuilderFormValuesMap.logs,
|
|
customQueryData: defaultLiveQueryDataConfig,
|
|
});
|
|
|
|
const isListView =
|
|
panelType === PANEL_TYPES.LIST && stagedQuery.builder.queryData[0];
|
|
|
|
if (isListView) {
|
|
const [graphQuery, listQuery] = queryClient.getQueriesData<
|
|
SuccessResponse<MetricRangePayloadProps> | ErrorResponse
|
|
>({
|
|
queryKey: REACT_QUERY_KEY.GET_QUERY_RANGE,
|
|
active: true,
|
|
});
|
|
|
|
queryHistoryState = {
|
|
graphQueryPayload:
|
|
graphQuery && graphQuery[1]
|
|
? graphQuery[1].payload?.data.result || []
|
|
: [],
|
|
listQueryPayload:
|
|
listQuery && listQuery[1]
|
|
? listQuery[1].payload?.data.newResult.data.result || []
|
|
: [],
|
|
};
|
|
}
|
|
|
|
const JSONCompositeQuery = encodeURIComponent(JSON.stringify(compositeQuery));
|
|
|
|
const path = `${ROUTES.LIVE_LOGS}?${QueryParams.compositeQuery}=${JSONCompositeQuery}`;
|
|
|
|
history.push(path, queryHistoryState);
|
|
}, [panelType, queryClient, stagedQuery]);
|
|
|
|
const { maxTime, minTime, selectedTime } = useSelector<
|
|
AppState,
|
|
GlobalReducer
|
|
>((state) => state.globalTime);
|
|
|
|
const getInputLabel = (
|
|
startTime?: Dayjs,
|
|
endTime?: Dayjs,
|
|
timeInterval: Time = '15min',
|
|
): string | Time => {
|
|
if (startTime && endTime && timeInterval === 'custom') {
|
|
const format = 'DD/MM/YYYY HH:mm';
|
|
|
|
const startString = startTime.format(format);
|
|
const endString = endTime.format(format);
|
|
|
|
return `${startString} - ${endString}`;
|
|
}
|
|
|
|
return timeInterval;
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (selectedTime === 'custom') {
|
|
setRefreshButtonHidden(true);
|
|
setCustomDTPickerVisible(true);
|
|
} else {
|
|
setRefreshButtonHidden(false);
|
|
setCustomDTPickerVisible(false);
|
|
}
|
|
}, [selectedTime]);
|
|
|
|
const getDefaultTime = (pathName: string): Time => {
|
|
const defaultSelectedOption = getDefaultOption(pathName);
|
|
|
|
const routes = getLocalStorageKey(LOCALSTORAGE.METRICS_TIME_IN_DURATION);
|
|
|
|
if (routes !== null) {
|
|
const routesObject = JSON.parse(routes || '{}');
|
|
const selectedTime = routesObject[pathName];
|
|
|
|
let parsedSelectedTime: TimeRange;
|
|
try {
|
|
parsedSelectedTime = JSON.parse(selectedTime);
|
|
} catch {
|
|
parsedSelectedTime = selectedTime;
|
|
}
|
|
if (isObject(parsedSelectedTime)) {
|
|
return 'custom';
|
|
}
|
|
}
|
|
|
|
return defaultSelectedOption;
|
|
};
|
|
|
|
const updateLocalStorageForRoutes = (value: Time | string): void => {
|
|
const preRoutes = getLocalStorageKey(LOCALSTORAGE.METRICS_TIME_IN_DURATION);
|
|
if (preRoutes !== null) {
|
|
const preRoutesObject = JSON.parse(preRoutes);
|
|
|
|
const preRoute = {
|
|
...preRoutesObject,
|
|
};
|
|
preRoute[location.pathname] = value;
|
|
|
|
setLocalStorageKey(
|
|
LOCALSTORAGE.METRICS_TIME_IN_DURATION,
|
|
JSON.stringify(preRoute),
|
|
);
|
|
}
|
|
};
|
|
|
|
const onLastRefreshHandler = useCallback(() => {
|
|
const currentTime = dayjs();
|
|
|
|
const lastRefresh = dayjs(
|
|
selectedTime === 'custom' ? minTime / 1000000 : maxTime / 1000000,
|
|
);
|
|
|
|
const secondsDiff = currentTime.diff(lastRefresh, 'seconds');
|
|
|
|
const minutedDiff = currentTime.diff(lastRefresh, 'minutes');
|
|
const hoursDiff = currentTime.diff(lastRefresh, 'hours');
|
|
const daysDiff = currentTime.diff(lastRefresh, 'days');
|
|
const monthsDiff = currentTime.diff(lastRefresh, 'months');
|
|
|
|
if (monthsDiff > 0) {
|
|
return `Refreshed ${monthsDiff} months ago`;
|
|
}
|
|
|
|
if (daysDiff > 0) {
|
|
return `Refreshed ${daysDiff} days ago`;
|
|
}
|
|
|
|
if (hoursDiff > 0) {
|
|
return `Refreshed ${hoursDiff} hrs ago`;
|
|
}
|
|
|
|
if (minutedDiff > 0) {
|
|
return `Refreshed ${minutedDiff} mins ago`;
|
|
}
|
|
|
|
return `Refreshed ${secondsDiff} sec ago`;
|
|
}, [maxTime, minTime, selectedTime]);
|
|
|
|
const isLogsExplorerPage = useMemo(
|
|
() => location.pathname === ROUTES.LOGS_EXPLORER,
|
|
[location.pathname],
|
|
);
|
|
|
|
const onSelectHandler = (value: Time): void => {
|
|
if (value !== 'custom') {
|
|
setIsOpen(false);
|
|
updateTimeInterval(value);
|
|
updateLocalStorageForRoutes(value);
|
|
if (refreshButtonHidden) {
|
|
setRefreshButtonHidden(false);
|
|
}
|
|
} else {
|
|
setRefreshButtonHidden(true);
|
|
setCustomDTPickerVisible(true);
|
|
}
|
|
|
|
const { maxTime, minTime } = GetMinMax(value, getTime());
|
|
|
|
if (!isLogsExplorerPage) {
|
|
urlQuery.set(QueryParams.startTime, minTime.toString());
|
|
urlQuery.set(QueryParams.endTime, maxTime.toString());
|
|
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
|
|
history.replace(generatedUrl);
|
|
}
|
|
|
|
if (!stagedQuery) {
|
|
return;
|
|
}
|
|
// the second boolean param directs the qb about the time change so to merge the query and retain the current state
|
|
initQueryBuilderData(updateStepInterval(stagedQuery, maxTime, minTime), true);
|
|
};
|
|
|
|
const onRefreshHandler = (): void => {
|
|
onSelectHandler(selectedTime);
|
|
onLastRefreshHandler();
|
|
};
|
|
|
|
const onCustomDateHandler = (dateTimeRange: DateTimeRangeType): void => {
|
|
if (dateTimeRange !== null) {
|
|
const [startTimeMoment, endTimeMoment] = dateTimeRange;
|
|
if (startTimeMoment && endTimeMoment) {
|
|
setCustomDTPickerVisible(false);
|
|
startTimeMoment.startOf('day').toString();
|
|
updateTimeInterval('custom', [
|
|
startTimeMoment.startOf('day').toDate().getTime(),
|
|
endTimeMoment.endOf('day').toDate().getTime(),
|
|
]);
|
|
setLocalStorageKey('startTime', startTimeMoment.toString());
|
|
setLocalStorageKey('endTime', endTimeMoment.toString());
|
|
updateLocalStorageForRoutes(
|
|
JSON.stringify({ startTime: startTimeMoment, endTime: endTimeMoment }),
|
|
);
|
|
|
|
if (!isLogsExplorerPage) {
|
|
urlQuery.set(QueryParams.startTime, startTimeMoment.toString());
|
|
urlQuery.set(QueryParams.endTime, endTimeMoment.toString());
|
|
const generatedUrl = `${location.pathname}?${urlQuery.toString()}`;
|
|
history.replace(generatedUrl);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
// this is triggred when we change the routes and based on that we are changing the default options
|
|
useEffect(() => {
|
|
const metricsTimeDuration = getLocalStorageKey(
|
|
LOCALSTORAGE.METRICS_TIME_IN_DURATION,
|
|
);
|
|
|
|
if (metricsTimeDuration === null) {
|
|
setLocalStorageKey(
|
|
LOCALSTORAGE.METRICS_TIME_IN_DURATION,
|
|
JSON.stringify({}),
|
|
);
|
|
}
|
|
|
|
const currentRoute = location.pathname;
|
|
const time = getDefaultTime(currentRoute);
|
|
|
|
const currentOptions = getOptions(currentRoute);
|
|
setOptions(currentOptions);
|
|
|
|
const getCustomOrIntervalTime = (time: Time): Time => {
|
|
if (searchEndTime !== null && searchStartTime !== null) {
|
|
return 'custom';
|
|
}
|
|
if (
|
|
(localstorageEndTime === null || localstorageStartTime === null) &&
|
|
time === 'custom'
|
|
) {
|
|
return getDefaultOption(currentRoute);
|
|
}
|
|
|
|
return time;
|
|
};
|
|
|
|
const updatedTime = getCustomOrIntervalTime(time);
|
|
|
|
const [preStartTime = 0, preEndTime = 0] = getTime() || [];
|
|
|
|
setRefreshButtonHidden(updatedTime === 'custom');
|
|
|
|
updateTimeInterval(updatedTime, [preStartTime, preEndTime]);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [location.pathname, updateTimeInterval, globalTimeLoading]);
|
|
|
|
return (
|
|
<div className="date-time-selector">
|
|
{!hasSelectedTimeError && !refreshButtonHidden && (
|
|
<RefreshText
|
|
{...{
|
|
onLastRefreshHandler,
|
|
}}
|
|
refreshButtonHidden={refreshButtonHidden}
|
|
/>
|
|
)}
|
|
<Form
|
|
form={formSelector}
|
|
layout="inline"
|
|
initialValues={{ interval: selectedTime }}
|
|
>
|
|
<FormContainer>
|
|
<CustomTimePicker
|
|
open={isOpen}
|
|
setOpen={setIsOpen}
|
|
onSelect={(value: unknown): void => {
|
|
onSelectHandler(value as Time);
|
|
}}
|
|
onError={(hasError: boolean): void => {
|
|
setHasSelectedTimeError(hasError);
|
|
}}
|
|
selectedTime={selectedTime}
|
|
onValidCustomDateChange={(dateTime): void =>
|
|
onCustomDateHandler(dateTime as DateTimeRangeType)
|
|
}
|
|
selectedValue={getInputLabel(
|
|
dayjs(minTime / 1000000),
|
|
dayjs(maxTime / 1000000),
|
|
selectedTime,
|
|
)}
|
|
data-testid="dropDown"
|
|
items={options}
|
|
newPopover
|
|
handleGoLive={handleGoLive}
|
|
onCustomDateHandler={onCustomDateHandler}
|
|
customDateTimeVisible={customDateTimeVisible}
|
|
setCustomDTPickerVisible={setCustomDTPickerVisible}
|
|
/>
|
|
|
|
{showAutoRefresh && selectedTime !== 'custom' && (
|
|
<div className="refresh-actions">
|
|
<FormItem hidden={refreshButtonHidden} className="refresh-btn">
|
|
<Button icon={<SyncOutlined />} onClick={onRefreshHandler} />
|
|
</FormItem>
|
|
|
|
<FormItem>
|
|
<AutoRefresh
|
|
disabled={refreshButtonHidden}
|
|
showAutoRefreshBtnPrimary={false}
|
|
/>
|
|
</FormItem>
|
|
</div>
|
|
)}
|
|
</FormContainer>
|
|
</Form>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
interface DateTimeSelectionV2Props {
|
|
showAutoRefresh: boolean;
|
|
}
|
|
interface DispatchProps {
|
|
updateTimeInterval: (
|
|
interval: Time,
|
|
dateTimeRange?: [number, number],
|
|
) => (dispatch: Dispatch<AppActions>) => void;
|
|
globalTimeLoading: () => void;
|
|
}
|
|
|
|
const mapDispatchToProps = (
|
|
dispatch: ThunkDispatch<unknown, unknown, AppActions>,
|
|
): DispatchProps => ({
|
|
updateTimeInterval: bindActionCreators(UpdateTimeInterval, dispatch),
|
|
globalTimeLoading: bindActionCreators(GlobalTimeLoading, dispatch),
|
|
});
|
|
|
|
type Props = DateTimeSelectionV2Props & DispatchProps & RouteComponentProps;
|
|
|
|
export default connect(null, mapDispatchToProps)(withRouter(DateTimeSelection));
|