mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-26 04:04:29 +08:00
fix: date time value retain on location switch (#4546)
* fix: date time value retain on location switch * chore: added inline comments * feat: added shortcut strings based on user os * feat: added shortcut strings based on user os * feat: added shortcut strings based on user os
This commit is contained in:
parent
bd4786f128
commit
b3bc78d23c
@ -21,6 +21,7 @@ import {
|
|||||||
useEffect,
|
useEffect,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
|
import { useLocation } from 'react-router-dom';
|
||||||
import { popupContainer } from 'utils/selectPopupContainer';
|
import { popupContainer } from 'utils/selectPopupContainer';
|
||||||
|
|
||||||
import CustomTimePickerPopoverContent from './CustomTimePickerPopoverContent';
|
import CustomTimePickerPopoverContent from './CustomTimePickerPopoverContent';
|
||||||
@ -68,6 +69,7 @@ function CustomTimePicker({
|
|||||||
const [inputErrorMessage, setInputErrorMessage] = useState<string | null>(
|
const [inputErrorMessage, setInputErrorMessage] = useState<string | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
const location = useLocation();
|
||||||
const [isInputFocused, setIsInputFocused] = useState(false);
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
||||||
|
|
||||||
const getSelectedTimeRangeLabel = (
|
const getSelectedTimeRangeLabel = (
|
||||||
@ -222,6 +224,15 @@ function CustomTimePicker({
|
|||||||
setIsInputFocused(false);
|
setIsInputFocused(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this is required as TopNav component wraps the components and we need to clear the state on path change
|
||||||
|
useEffect(() => {
|
||||||
|
setInputStatus('');
|
||||||
|
onError(false);
|
||||||
|
setInputErrorMessage(null);
|
||||||
|
setInputValue('');
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
}, [location.pathname]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="custom-time-picker">
|
<div className="custom-time-picker">
|
||||||
<Popover
|
<Popover
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import { getUserOperatingSystem, UserOperatingSystem } from 'utils/getUserOS';
|
||||||
|
|
||||||
|
const userOS = getUserOperatingSystem();
|
||||||
export const GlobalShortcuts = {
|
export const GlobalShortcuts = {
|
||||||
SidebarCollapse: '\\+meta',
|
SidebarCollapse: '\\+meta',
|
||||||
NavigateToServices: 's+shift',
|
NavigateToServices: 's+shift',
|
||||||
@ -8,6 +11,16 @@ export const GlobalShortcuts = {
|
|||||||
NavigateToExceptions: 'e+shift',
|
NavigateToExceptions: 'e+shift',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const GlobalShortcutsName = {
|
||||||
|
SidebarCollapse: `${userOS === UserOperatingSystem.MACOS ? 'cmd' : 'ctrl'}+\\`,
|
||||||
|
NavigateToServices: 'shift+s',
|
||||||
|
NavigateToTraces: 'shift+t',
|
||||||
|
NavigateToLogs: 'shift+l',
|
||||||
|
NavigateToDashboards: 'shift+d',
|
||||||
|
NavigateToAlerts: 'shift+a',
|
||||||
|
NavigateToExceptions: 'shift+e',
|
||||||
|
};
|
||||||
|
|
||||||
export const GlobalShortcutsDescription = {
|
export const GlobalShortcutsDescription = {
|
||||||
SidebarCollapse: 'Collpase the sidebar',
|
SidebarCollapse: 'Collpase the sidebar',
|
||||||
NavigateToServices: 'Navigate to Services page',
|
NavigateToServices: 'Navigate to Services page',
|
||||||
|
@ -1,8 +1,18 @@
|
|||||||
|
import { getUserOperatingSystem, UserOperatingSystem } from 'utils/getUserOS';
|
||||||
|
|
||||||
|
const userOS = getUserOperatingSystem();
|
||||||
export const LogsExplorerShortcuts = {
|
export const LogsExplorerShortcuts = {
|
||||||
StageAndRunQuery: 'enter+meta',
|
StageAndRunQuery: 'enter+meta',
|
||||||
FocusTheSearchBar: 's',
|
FocusTheSearchBar: 's',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const LogsExplorerShortcutsName = {
|
||||||
|
StageAndRunQuery: `${
|
||||||
|
userOS === UserOperatingSystem.MACOS ? 'cmd' : 'ctrl'
|
||||||
|
}+enter`,
|
||||||
|
FocusTheSearchBar: 's',
|
||||||
|
};
|
||||||
|
|
||||||
export const LogsExplorerShortcutsDescription = {
|
export const LogsExplorerShortcutsDescription = {
|
||||||
StageAndRunQuery: 'Stage and Run the current query',
|
StageAndRunQuery: 'Stage and Run the current query',
|
||||||
FocusTheSearchBar: 'Shift the focus to the last query filter bar',
|
FocusTheSearchBar: 'Shift the focus to the last query filter bar',
|
||||||
|
@ -2,10 +2,12 @@ import { TableProps } from 'antd';
|
|||||||
import {
|
import {
|
||||||
GlobalShortcuts,
|
GlobalShortcuts,
|
||||||
GlobalShortcutsDescription,
|
GlobalShortcutsDescription,
|
||||||
|
GlobalShortcutsName,
|
||||||
} from 'constants/shortcuts/globalShortcuts';
|
} from 'constants/shortcuts/globalShortcuts';
|
||||||
import {
|
import {
|
||||||
LogsExplorerShortcuts,
|
LogsExplorerShortcuts,
|
||||||
LogsExplorerShortcutsDescription,
|
LogsExplorerShortcutsDescription,
|
||||||
|
LogsExplorerShortcutsName,
|
||||||
} from 'constants/shortcuts/logsExplorerShortcuts';
|
} from 'constants/shortcuts/logsExplorerShortcuts';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
@ -14,6 +16,11 @@ export const ALL_SHORTCUTS: Record<string, Record<string, string>> = {
|
|||||||
'Logs Explorer Shortcuts': LogsExplorerShortcuts,
|
'Logs Explorer Shortcuts': LogsExplorerShortcuts,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ALL_SHORTCUTS_LABEL: Record<string, Record<string, string>> = {
|
||||||
|
'Global Shortcuts': GlobalShortcutsName,
|
||||||
|
'Logs Explorer Shortcuts': LogsExplorerShortcutsName,
|
||||||
|
};
|
||||||
|
|
||||||
export const ALL_SHORTCUTS_DESCRIPTION: Record<
|
export const ALL_SHORTCUTS_DESCRIPTION: Record<
|
||||||
string,
|
string,
|
||||||
Record<string, string>
|
Record<string, string>
|
||||||
@ -46,9 +53,10 @@ export function generateTableData(
|
|||||||
): TableProps<ShortcutRow>['dataSource'] {
|
): TableProps<ShortcutRow>['dataSource'] {
|
||||||
const shortcuts = ALL_SHORTCUTS[shortcutSection];
|
const shortcuts = ALL_SHORTCUTS[shortcutSection];
|
||||||
const shortcutsDescription = ALL_SHORTCUTS_DESCRIPTION[shortcutSection];
|
const shortcutsDescription = ALL_SHORTCUTS_DESCRIPTION[shortcutSection];
|
||||||
|
const shortcutsLabel = ALL_SHORTCUTS_LABEL[shortcutSection];
|
||||||
return Object.keys(shortcuts).map((shortcutName) => ({
|
return Object.keys(shortcuts).map((shortcutName) => ({
|
||||||
key: `${shortcuts[shortcutName]} ${shortcutName}`,
|
key: `${shortcuts[shortcutName]} ${shortcutName}`,
|
||||||
shortcutKey: shortcuts[shortcutName],
|
shortcutKey: shortcutsLabel[shortcutName],
|
||||||
shortcutDescription: shortcutsDescription[shortcutName],
|
shortcutDescription: shortcutsDescription[shortcutName],
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
14
frontend/src/utils/getUserOS.ts
Normal file
14
frontend/src/utils/getUserOS.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export enum UserOperatingSystem {
|
||||||
|
WINDOWS = 'Windows',
|
||||||
|
MACOS = 'Mac OS',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUserOperatingSystem(): UserOperatingSystem {
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/userAgent
|
||||||
|
if (window.navigator.userAgent.indexOf(UserOperatingSystem.WINDOWS) !== -1) {
|
||||||
|
return UserOperatingSystem.WINDOWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// default return is MacOS
|
||||||
|
return UserOperatingSystem.MACOS;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user