Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix: ui fixes for panel selection modal (#11944)

Abhi kumar14ba332935f8
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx
index 7022033bb6..657ba8dd2c 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardPageToolbar/index.tsx
@@ -63,8 +63,13 @@ function DashboardPageToolbar(props: DashboardPageToolbarProps): JSX.Element {
const { user } = useAppContext();
const { showErrorModal } = useErrorModal();
const { patchAsync } = useOptimisticPatch();
- const { isPickerOpen, openPicker, closePicker, createPanel } =
- useCreatePanel();
+ const {
+ isPickerOpen,
+ openPicker,
+ closePicker,
+ createPanel,
+ targetLayoutIndex,
+ } = useCreatePanel();
const isAuthor =
!!user?.email && !!dashboard.createdBy && dashboard.createdBy === user.email;
@@ -183,6 +188,7 @@ function DashboardPageToolbar(props: DashboardPageToolbarProps): JSX.Element {
open={isPickerOpen}
onClose={closePicker}
onSelect={createPanel}
+ defaultLayoutIndex={targetLayoutIndex}
/>
</section>
);
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.module.scss
index 0d353209dd..9bb1debc6f 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.module.scss
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.module.scss
@@ -1,22 +1,69 @@
+.panelTypeSection {
+ display: flex;
+ flex-direction: column;
+ gap: 12px;
+ align-items: center;
+}
+
.grid {
+ align-self: stretch;
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
}
-.typeButton {
+.panelTypeCard {
display: flex;
+ flex-direction: column;
align-items: center;
- gap: 8px;
+ border: 1px solid var(--l2-border);
+ background: var(--l2-background);
padding: 12px;
- background: var(--bg-ink-400, #0b0c0e);
- border: 1px solid var(--l1-border);
+ gap: 12px;
+ cursor: pointer;
+ font: inherit;
border-radius: 4px;
color: var(--l1-foreground);
- cursor: pointer;
- text-align: left;
+ transition:
+ transform 180ms ease,
+ border-color 180ms ease;
&:hover {
- border-color: var(--bg-robin-500);
+ background-color: var(--l2-background-hover);
+ border-color: var(--bg-robin-400);
+ }
+ &:active {
+ transform: translateY(2px);
}
}
+
+.panelTypeCardSelected {
+ border-color: var(--bg-robin-400);
+ background-color: var(--l2-background-hover);
+ box-shadow: inset 0 0 0 1px var(--bg-robin-400);
+}
+
+.footerActions {
+ display: flex;
+ align-items: flex-end;
+ justify-content: flex-end;
+ gap: 8px;
+ width: 100%;
+}
+
+.footerPicker {
+ // Take all the width left over by the (natural-width) confirm button.
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ gap: 6px;
+ min-width: 0;
+}
+
+.pickerLabel {
+ color: var(--l3-foreground);
+ font-size: 11px;
+ font-weight: 500;
+ letter-spacing: 0.06em;
+ text-transform: uppercase;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.tsx
index c6d6a5d017..1529ea0806 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModal.tsx
@@ -1,45 +1,93 @@
-import { Modal } from 'antd';
-import { Button } from '@signozhq/ui/button';
+import { useEffect, useMemo, useState } from 'react';
+import { Color } from '@signozhq/design-tokens';
+import { DialogWrapper } from '@signozhq/ui/dialog';
+import cx from 'classnames';
+import { useDashboardSections } from '../../../hooks/useDashboardSections';
import type { PanelKind } from '../../../Panels/types/panelKind';
import { PANEL_TYPES } from './constants';
+import PanelTypeSelectionModalFooter from './PanelTypeSelectionModalFooter';
+import { buildSectionOptions, resolveDefaultSectionValue } from './utils';
import styles from './PanelTypeSelectionModal.module.scss';
interface PanelTypeSelectionModalProps {
open: boolean;
onClose: () => void;
- onSelect: (panelKind: PanelKind) => void;
+ onSelect: (panelKind: PanelKind, layoutIndex?: number) => void;
+ /** Section the picker opens on; omit → the first section. */
+ defaultLayoutIndex?: number;
}
function PanelTypeSelectionModal({
open,
onClose,
onSelect,
+ defaultLayoutIndex,
}: PanelTypeSelectionModalProps): JSX.Element {
+ const sections = useDashboardSections();
+ const options = useMemo(() => buildSectionOptions(sections), [sections]);
+
+ const [selectedValue, setSelectedValue] = useState('');
+ const [selectedPanelKind, setSelectedPanelKind] = useState<PanelKind | null>(
+ null,
+ );
+
+ // Seed the target section on open.
+ useEffect(() => {
+ if (open) {
+ setSelectedValue(resolveDefaultSectionValue(options, defaultLayoutIndex));
+ setSelectedPanelKind(null);
+ }
+ }, [open, options, defaultLayoutIndex]);
+
+ const handleConfirm = (): void => {
+ if (selectedPanelKind === null) {
+ return;
+ }
+ const layoutIndex = selectedValue === '' ? undefined : Number(selectedValue);
+ onSelect(selectedPanelKind, layoutIndex);
+ };
+
return (
- <Modal
+ <DialogWrapper
open={open}
- title="Select a panel type"
- onCancel={onClose}
- footer={null}
- destroyOnClose
+ onOpenChange={(isOpen): void => {
+ if (!isOpen) {
+ onClose();
+ }
+ }}
+ title="New Panel"
+ footer={
+ <PanelTypeSelectionModalFooter
+ options={options}
+ selectedValue={selectedValue}
+ onSectionChange={setSelectedValue}
+ isConfirmDisabled={selectedPanelKind === null}
+ onConfirm={handleConfirm}
+ />
+ }
>
- <div className={styles.grid}>
- {PANEL_TYPES.map(({ panelKind, label, Icon }) => (
- <Button
- key={panelKind}
- type="button"
- variant="ghost"
- className={styles.typeButton}
- data-testid={`panel-type-${panelKind}`}
- onClick={(): void => onSelect(panelKind)}
- >
- <Icon size={14} />
- {label}
- </Button>
- ))}
+ <div className={styles.panelTypeSection}>
+ <span className={styles.pickerLabel}>Select panel type</span>
+ <div className={styles.grid}>
+ {PANEL_TYPES.map(({ panelKind, label, Icon }) => (
+ <button
+ key={panelKind}
+ type="button"
+ className={cx(styles.panelTypeCard, {
+ [styles.panelTypeCardSelected]: panelKind === selectedPanelKind,
+ })}
+ data-testid={`panel-type-${panelKind}`}
+ aria-pressed={panelKind === selectedPanelKind}
+ onClick={(): void => setSelectedPanelKind(panelKind)}
+ >
+ <Icon size={24} color={Color.BG_ROBIN_400} />
+ {label}
+ </button>
+ ))}
+ </div>
</div>
- </Modal>
+ </DialogWrapper>
);
}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModalFooter.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModalFooter.tsx
new file mode 100644
index 0000000000..bdea492f82
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/PanelTypeSelectionModalFooter.tsx
@@ -0,0 +1,56 @@
+import { Plus } from '@signozhq/icons';
+import { Button } from '@signozhq/ui/button';
+
+import SectionPicker from './SectionPicker';
+import type { SectionOption } from './types';
+import styles from './PanelTypeSelectionModal.module.scss';
+
+interface PanelTypeSelectionModalFooterProps {
+ options: SectionOption[];
+ selectedValue: string;
+ onSectionChange: (value: string) => void;
+ /** Disabled until a panel type is picked. */
+ isConfirmDisabled: boolean;
+ onConfirm: () => void;
+}
+
+/**
+ * Footer for the New Panel modal: an "Add panel to" section picker (shown only
+ * when the dashboard has more than one section) and the confirm button.
+ */
+function PanelTypeSelectionModalFooter({
+ options,
+ selectedValue,
+ onSectionChange,
+ isConfirmDisabled,
+ onConfirm,
+}: PanelTypeSelectionModalFooterProps): JSX.Element {
+ const hasSectionPicker = options.length > 1;
+
+ return (
+ <div className={styles.footerActions}>
+ {hasSectionPicker && (
+ <div className={styles.footerPicker}>
+ <span className={styles.pickerLabel}>Add panel to</span>
+ <SectionPicker
+ options={options}
+ value={selectedValue}
+ onChange={onSectionChange}
+ />
+ </div>
+ )}
+ <Button
+ color="primary"
+ size="md"
+ disabled={isConfirmDisabled}
+ prefix={<Plus size={16} />}
+ onClick={onConfirm}
+ testId="panel-type-confirm"
+ >
+ Add Panel
+ </Button>
+ </div>
+ );
+}
+
+export default PanelTypeSelectionModalFooter;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/SectionPicker.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/SectionPicker.module.scss
new file mode 100644
index 0000000000..72bd1f6aaa
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/SectionPicker.module.scss
@@ -0,0 +1,55 @@
+.select {
+ width: 100%;
+}
+
+.dropdown {
+ min-width: 260px;
+}
+
+.rootIcon {
+ color: var(--bg-robin-400);
+ flex-shrink: 0;
+}
+
+.sectionIcon {
+ color: var(--l3-foreground);
+ flex-shrink: 0;
+}
+
+.triggerValue {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ overflow: hidden;
+}
+
+.triggerLabel {
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+}
+
+.optionRow {
+ display: flex;
+ align-items: center;
+ gap: 12px;
+ padding: 4px 0;
+}
+
+.optionText {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+ overflow: hidden;
+}
+
+.optionLabel {
+ color: var(--l1-foreground);
+ line-height: 1.2;
+}
+
+.optionDescription {
+ color: var(--l3-foreground);
+ font-size: 12px;
+ line-height: 1.2;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/SectionPicker.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/SectionPicker.tsx
new file mode 100644
index 0000000000..a2c1188b82
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/SectionPicker.tsx
@@ -0,0 +1,65 @@
+import { useMemo } from 'react';
+// eslint-disable-next-line signoz/no-antd-components
+import { Select } from 'antd';
+
+import type { SectionOption } from './types';
+import styles from './SectionPicker.module.scss';
+
+interface SectionPickerProps {
+ options: SectionOption[];
+ value: string;
+ onChange: (value: string) => void;
+}
+
+function SectionPicker({
+ options,
+ value,
+ onChange,
+}: SectionPickerProps): JSX.Element {
+ // `selectedLabel` (one line) shows in the trigger; `label` (two lines) in the list.
+ const selectOptions = useMemo(
+ () =>
+ options.map((option) => {
+ const iconClass = option.isRoot ? styles.rootIcon : styles.sectionIcon;
+ return {
+ value: option.value,
+ selectedLabel: (
+ <span className={styles.triggerValue}>
+ <option.Icon size={16} className={iconClass} />
+ <span className={styles.triggerLabel}>{option.label}</span>
+ </span>
+ ),
+ label: (
+ <span
+ className={styles.optionRow}
+ data-testid={`panel-section-option-${option.layoutIndex}`}
+ >
+ <option.Icon size={16} className={iconClass} />
+ <span className={styles.optionText}>
+ <span className={styles.optionLabel}>{option.label}</span>
+ <span className={styles.optionDescription}>{option.description}</span>
+ </span>
+ </span>
+ ),
+ };
+ }),
+ [options],
+ );
+
+ return (
+ <Select<string>
+ className={styles.select}
+ popupClassName={styles.dropdown}
+ value={value}
+ onChange={onChange}
+ data-testid="panel-section-select"
+ optionLabelProp="selectedLabel"
+ getPopupContainer={(trigger): HTMLElement =>
+ trigger.parentElement ?? document.body
+ }
+ options={selectOptions}
+ />
+ );
+}
+
+export default SectionPicker;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/types.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/types.ts
index b66b817348..a066129d67 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/types.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/types.ts
@@ -14,3 +14,16 @@ export interface PanelType {
/** Icon component — the consumer renders it and controls size/color/etc. */
Icon: ComponentType<IconProps>;
}
+
+export interface SectionOption {
+ /** The section's `layoutIndex`, stringified for the Select value. */
+ value: string;
+ layoutIndex: number;
+ /** Section title, or "Dashboard (root)" for the untitled top-level layout. */
+ label: string;
+ /** Caption under the label. */
+ description: string;
+ /** Untitled top-level layout (has no section header). */
+ isRoot: boolean;
+ Icon: ComponentType<IconProps>;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/utils.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/utils.ts
new file mode 100644
index 0000000000..6288d8dda7
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/PanelTypeSelectionModal/utils.ts
@@ -0,0 +1,41 @@
+import { LayoutDashboard, Rows2 } from '@signozhq/icons';
+
+import type { DashboardSection } from '../../../utils';
+import type { SectionOption } from './types';
+
+const ROOT_LABEL = 'Dashboard (root)';
+const ROOT_DESCRIPTION = 'Top level — no section';
+const SECTION_DESCRIPTION = 'Section';
+
+/** Maps dashboard sections to section-picker options (untitled → "root"). */
+export function buildSectionOptions(
+ sections: DashboardSection[],
+): SectionOption[] {
+ return sections.map((section) => {
+ const isRoot = !section.title && section.layoutIndex === 0;
+ return {
+ value: String(section.layoutIndex),
+ layoutIndex: section.layoutIndex,
+ label: isRoot ? ROOT_LABEL : (section.title as string),
+ description: isRoot ? ROOT_DESCRIPTION : SECTION_DESCRIPTION,
+ isRoot,
+ Icon: isRoot ? LayoutDashboard : Rows2,
+ };
+ });
+}
+
+/**
+ * Picks the option the picker should open on: the section the "Add panel" was
+ * triggered from when present and still valid, otherwise the first option.
+ */
+export function resolveDefaultSectionValue(
+ options: SectionOption[],
+ defaultLayoutIndex: number | undefined,
+): string {
+ const fallback = options[0]?.value ?? '';
+ if (defaultLayoutIndex === undefined) {
+ return fallback;
+ }
+ const target = String(defaultLayoutIndex);
+ return options.some((option) => option.value === target) ? target : fallback;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx
index b785f1e45e..7e5c71e19c 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Section/Section/Section.tsx
@@ -29,8 +29,13 @@ interface SectionProps {
function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {
const isEditable = useDashboardStore((s) => s.isEditable);
- const { isPickerOpen, openPicker, closePicker, createPanel } =
- useCreatePanel();
+ const {
+ isPickerOpen,
+ openPicker,
+ closePicker,
+ createPanel,
+ targetLayoutIndex,
+ } = useCreatePanel();
const [isDeleteOpen, setIsDeleteOpen] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
// Placeholder signal for lazy panel query-loading (consumed in a later PR):
@@ -141,6 +146,7 @@ function Section({ section, sections, dragHandle }: SectionProps): JSX.Element {
open={isPickerOpen}
onClose={closePicker}
onSelect={createPanel}
+ defaultLayoutIndex={targetLayoutIndex}
/>
<ConfirmDeleteDialog
open={isDeleteOpen}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useCreatePanel.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useCreatePanel.ts
index 6b9ae69049..c2341f0d73 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useCreatePanel.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useCreatePanel.ts
@@ -12,7 +12,10 @@ interface UseCreatePanelResult {
/** Pass the target section's layout index; omit → last/new section. */
openPicker: (layoutIndex?: number) => void;
closePicker: () => void;
- createPanel: (panelKind: PanelKind) => void;
+ /** The section the picker was opened against — seeds its section dropdown. */
+ targetLayoutIndex: number | undefined;
+ /** `layoutIndex` overrides the opened-against target (the dropdown's choice). */
+ createPanel: (panelKind: PanelKind, layoutIndex?: number) => void;
}
/**
@@ -38,16 +41,23 @@ export function useCreatePanel(): UseCreatePanelResult {
}, []);
const createPanel = useCallback(
- (panelKind: PanelKind): void => {
+ (panelKind: PanelKind, targetIndex?: number): void => {
setIsPickerOpen(false);
const path = generatePath(ROUTES.DASHBOARD_PANEL_EDITOR, {
dashboardId,
panelId: NEW_PANEL_ID,
});
- safeNavigate(`${path}${newPanelSearch(panelKind, layoutIndex)}`);
+ const target = targetIndex ?? layoutIndex;
+ safeNavigate(`${path}${newPanelSearch(panelKind, target)}`);
},
[safeNavigate, dashboardId, layoutIndex],
);
- return { isPickerOpen, openPicker, closePicker, createPanel };
+ return {
+ isPickerOpen,
+ openPicker,
+ closePicker,
+ targetLayoutIndex: layoutIndex,
+ createPanel,
+ };
}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useDashboardSections.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useDashboardSections.ts
new file mode 100644
index 0000000000..275281556d
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/hooks/useDashboardSections.ts
@@ -0,0 +1,18 @@
+import { useMemo } from 'react';
+import { type DashboardSection, layoutsToSections } from '../utils';
+import { useDashboardFetchRequired } from './useDashboardFetchRequired';
+
+/**
+ * The current dashboard's sections, derived from the guaranteed-loaded dashboard
+ * via useDashboardFetchRequired. That reuses the shared react-query cache (no extra
+ * request) instead of prop-drilling the section list.
+ */
+export function useDashboardSections(): DashboardSection[] {
+ const { dashboard } = useDashboardFetchRequired();
+ const spec = dashboard.spec;
+
+ return useMemo(
+ () => layoutsToSections(spec.layouts, spec.panels),
+ [spec.layouts, spec.panels],
+ );
+}