mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-20 15:21:19 +00:00
Compare commits
1 Commits
main
...
dev/bottom
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8713472f98 |
@@ -8,7 +8,7 @@ import { Tooltip } from '@signozhq/ui/tooltip';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { History, Maximize2, Plus, X } from '@signozhq/icons';
|
||||
import Noz from 'components/Noz/Noz';
|
||||
import { BOTTOM_STRIP_HEIGHT } from 'container/BottomStrip';
|
||||
import { useBottomStripStore } from 'container/BottomStrip/store/useBottomStripStore';
|
||||
import { supportChatObstacle } from 'container/BottomStrip/SupportButton/supportChatObstacle';
|
||||
import { FloatingPanel } from 'periscope/components/FloatingPanel';
|
||||
|
||||
@@ -46,6 +46,7 @@ export default function AIAssistantPanel(): JSX.Element | null {
|
||||
const [showHistory, setShowHistory] = useState(false);
|
||||
|
||||
const isOpen = useAIAssistantStore((s) => s.isDrawerOpen);
|
||||
const stripHeight = useBottomStripStore((s) => s.height);
|
||||
const isFullScreenPage = !!matchRoute(pathname, ROUTES.AI_ASSISTANT, {
|
||||
exact: true,
|
||||
});
|
||||
@@ -98,7 +99,7 @@ export default function AIAssistantPanel(): JSX.Element | null {
|
||||
|
||||
const availableHeight = Math.max(
|
||||
0,
|
||||
window.innerHeight - BOTTOM_STRIP_HEIGHT - 2 * PANEL_MARGIN,
|
||||
window.innerHeight - stripHeight - 2 * PANEL_MARGIN,
|
||||
);
|
||||
const panelHeight = Math.min(PANEL_HEIGHT, availableHeight);
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Mark labels sit below the track, so the value aligns to the track, not the centre.
|
||||
.pill {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: var(--spacing-6);
|
||||
transform: translateY(-50%);
|
||||
z-index: 900;
|
||||
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: var(--spacing-10);
|
||||
|
||||
padding: var(--spacing-10) var(--spacing-16) var(--spacing-4);
|
||||
|
||||
background: var(--l1-background);
|
||||
border: 1px solid var(--l2-border);
|
||||
border-radius: var(--radius-round);
|
||||
box-shadow: var(--shadow-dropdown);
|
||||
}
|
||||
|
||||
.slider {
|
||||
--slider-thumb-width: 22px;
|
||||
--slider-thumb-height: 22px;
|
||||
--slider-track-height: 8px;
|
||||
--slider-marks-font-size: 12px;
|
||||
--slider-marks-top: calc(50% + 18px);
|
||||
--slider-root-with-marks-margin-bottom: 32px;
|
||||
// The library's own `width: var(--slider-root-width, 100%)` wins over a plain width.
|
||||
--slider-root-width: 720px;
|
||||
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.value {
|
||||
min-width: 6ch;
|
||||
font-size: 15px;
|
||||
line-height: 22px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--l1-foreground);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import { useRef } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Slider } from '@signozhq/ui/slider';
|
||||
|
||||
import {
|
||||
BOTTOM_STRIP_HEIGHT_MARKS,
|
||||
BOTTOM_STRIP_MAX_HEIGHT,
|
||||
BOTTOM_STRIP_MIN_HEIGHT,
|
||||
} from '../constants';
|
||||
import { useBottomStripStore } from '../store/useBottomStripStore';
|
||||
import { useWheelNudge } from './useWheelNudge';
|
||||
|
||||
import styles from './StripHeightPill.module.scss';
|
||||
|
||||
/** Dev tool: drags the strip's height between the min and max. */
|
||||
function StripHeightPill(): JSX.Element {
|
||||
const height = useBottomStripStore((s) => s.height);
|
||||
const setHeight = useBottomStripStore((s) => s.setHeight);
|
||||
const nudgeHeight = useBottomStripStore((s) => s.nudgeHeight);
|
||||
const pillRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useWheelNudge(pillRef, nudgeHeight);
|
||||
|
||||
// Portalled so the strip's stacking context can't put page content above it.
|
||||
return createPortal(
|
||||
<div
|
||||
ref={pillRef}
|
||||
className={styles.pill}
|
||||
data-testid="bottom-strip-height-pill"
|
||||
>
|
||||
<Slider
|
||||
className={styles.slider}
|
||||
min={BOTTOM_STRIP_MIN_HEIGHT}
|
||||
max={BOTTOM_STRIP_MAX_HEIGHT}
|
||||
step={1}
|
||||
marks={BOTTOM_STRIP_HEIGHT_MARKS}
|
||||
value={height}
|
||||
onChange={(value): void =>
|
||||
setHeight(Array.isArray(value) ? value[0] : value)
|
||||
}
|
||||
aria-label="Bottom strip height"
|
||||
testId="bottom-strip-height-slider"
|
||||
/>
|
||||
<span className={styles.value}>{height}px</span>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
}
|
||||
|
||||
export default StripHeightPill;
|
||||
@@ -0,0 +1,23 @@
|
||||
import { RefObject, useEffect } from 'react';
|
||||
|
||||
/** Each wheel tick over `ref` nudges by 1: up grows, down shrinks. */
|
||||
export function useWheelNudge(
|
||||
ref: RefObject<HTMLElement>,
|
||||
nudge: (delta: number) => void,
|
||||
): void {
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const onWheel = (event: WheelEvent): void => {
|
||||
// React's onWheel is passive, so the page would scroll too.
|
||||
event.preventDefault();
|
||||
nudge(event.deltaY < 0 ? 1 : -1);
|
||||
};
|
||||
|
||||
element.addEventListener('wheel', onWheel, { passive: false });
|
||||
return (): void => element.removeEventListener('wheel', onWheel);
|
||||
}, [ref, nudge]);
|
||||
}
|
||||
@@ -4,10 +4,10 @@ import { render } from 'tests/test-utils';
|
||||
import { Info } from 'types/api/v1/version/get';
|
||||
|
||||
import BottomStrip, {
|
||||
BOTTOM_STRIP_HEIGHT,
|
||||
BOTTOM_STRIP_HEIGHT_VAR,
|
||||
BOTTOM_STRIP_ON_CLASS,
|
||||
} from '..';
|
||||
import { BOTTOM_STRIP_HEIGHT } from '../constants';
|
||||
import { useBottomStripStore } from '../store/useBottomStripStore';
|
||||
import { useBottomStrip } from '../useBottomStrip';
|
||||
import { StripItemKind } from '../types';
|
||||
|
||||
10
frontend/src/container/BottomStrip/constants.ts
Normal file
10
frontend/src/container/BottomStrip/constants.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const BOTTOM_STRIP_HEIGHT = 24;
|
||||
|
||||
export const BOTTOM_STRIP_MIN_HEIGHT = 0;
|
||||
export const BOTTOM_STRIP_MAX_HEIGHT = 200;
|
||||
|
||||
// 48 is skipped: on a linear track its label would overlap 50's.
|
||||
export const BOTTOM_STRIP_HEIGHT_MARKS: Record<number, string> =
|
||||
Object.fromEntries(
|
||||
[0, 8, 16, 24, 32, 40, 50, 100, 150, 200].map((px) => [px, String(px)]),
|
||||
);
|
||||
@@ -2,39 +2,41 @@ import { useLayoutEffect } from 'react';
|
||||
|
||||
import AskNoz from './AskNoz/AskNoz';
|
||||
import LeftSlot from './LeftSlot/LeftSlot';
|
||||
import { useBottomStripStore } from './store/useBottomStripStore';
|
||||
import StripHeightPill from './StripHeightPill/StripHeightPill';
|
||||
import SupportButton from './SupportButton/SupportButton';
|
||||
|
||||
import styles from './BottomStrip.module.scss';
|
||||
|
||||
export const BOTTOM_STRIP_HEIGHT = 24;
|
||||
|
||||
export const BOTTOM_STRIP_ON_CLASS = 'bottom-strip-on';
|
||||
export const BOTTOM_STRIP_HEIGHT_VAR = '--bottom-strip-height';
|
||||
|
||||
function BottomStrip(): JSX.Element {
|
||||
const height = useBottomStripStore((s) => s.height);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
document.body.classList.add(BOTTOM_STRIP_ON_CLASS);
|
||||
document.body.style.setProperty(
|
||||
BOTTOM_STRIP_HEIGHT_VAR,
|
||||
`${BOTTOM_STRIP_HEIGHT}px`,
|
||||
);
|
||||
document.body.style.setProperty(BOTTOM_STRIP_HEIGHT_VAR, `${height}px`);
|
||||
|
||||
return (): void => {
|
||||
document.body.classList.remove(BOTTOM_STRIP_ON_CLASS);
|
||||
document.body.style.removeProperty(BOTTOM_STRIP_HEIGHT_VAR);
|
||||
};
|
||||
}, []);
|
||||
}, [height]);
|
||||
|
||||
return (
|
||||
<div className={styles.strip} data-testid="bottom-strip">
|
||||
<div className={styles.left}>
|
||||
<LeftSlot />
|
||||
<>
|
||||
<div className={styles.strip} data-testid="bottom-strip">
|
||||
<div className={styles.left}>
|
||||
<LeftSlot />
|
||||
</div>
|
||||
<div className={styles.right}>
|
||||
<AskNoz />
|
||||
<SupportButton />
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.right}>
|
||||
<AskNoz />
|
||||
<SupportButton />
|
||||
</div>
|
||||
</div>
|
||||
<StripHeightPill />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { create } from 'zustand';
|
||||
|
||||
import {
|
||||
BOTTOM_STRIP_HEIGHT,
|
||||
BOTTOM_STRIP_MAX_HEIGHT,
|
||||
BOTTOM_STRIP_MIN_HEIGHT,
|
||||
} from '../constants';
|
||||
import type { StripItem } from '../types';
|
||||
|
||||
interface BottomStripState {
|
||||
@@ -7,14 +12,28 @@ interface BottomStripState {
|
||||
left: StripItem[] | null;
|
||||
/** Which page owns the current value — see `clearLeft`. */
|
||||
ownerId: string | null;
|
||||
/** In px; the dev height pill changes it. */
|
||||
height: number;
|
||||
setLeft: (ownerId: string, left: StripItem[] | null) => void;
|
||||
clearLeft: (ownerId: string) => void;
|
||||
setHeight: (height: number) => void;
|
||||
/** Moves the height by `delta` px, kept within the min and max. */
|
||||
nudgeHeight: (delta: number) => void;
|
||||
}
|
||||
|
||||
export const useBottomStripStore = create<BottomStripState>()((set, get) => ({
|
||||
left: null,
|
||||
ownerId: null,
|
||||
height: BOTTOM_STRIP_HEIGHT,
|
||||
setLeft: (ownerId, left): void => set({ left, ownerId }),
|
||||
setHeight: (height): void => set({ height }),
|
||||
nudgeHeight: (delta): void =>
|
||||
set((state) => ({
|
||||
height: Math.min(
|
||||
BOTTOM_STRIP_MAX_HEIGHT,
|
||||
Math.max(BOTTOM_STRIP_MIN_HEIGHT, state.height + delta),
|
||||
),
|
||||
})),
|
||||
// Only the current owner may clear. On a plain route swap React runs the old
|
||||
// page's cleanup before the new page's effect, so this is moot, but two
|
||||
// consumers can be mounted at once (a page under a drawer): the one that set
|
||||
|
||||
Reference in New Issue
Block a user