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.

feat(dashboard-v2): variable settings editor UX polishes (#11775)

Ashwin Bhatkala4ff4093cdf3
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/DynamicVariableFields.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/DynamicVariableFields.tsx
index 010564e8ec..bd6fff323f 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/DynamicVariableFields.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/DynamicVariableFields.tsx
@@ -1,24 +1,34 @@
import { useEffect, useMemo, useState } from 'react';
-import { SelectSimple } from '@signozhq/ui/select';
+import { Info } from '@signozhq/icons';
import { Typography } from '@signozhq/ui/typography';
import cx from 'classnames';
-// eslint-disable-next-line signoz/no-antd-components -- searchable async select: no @signozhq/ui equivalent
+// eslint-disable-next-line signoz/no-antd-components -- fixed-option signal picker
import { Select } from 'antd';
+import { CustomSelect } from 'components/NewSelect';
+import TextToolTip from 'components/TextToolTip';
import { useGetFieldKeys } from 'hooks/dynamicVariables/useGetFieldKeys';
import { useGetFieldValues } from 'hooks/dynamicVariables/useGetFieldValues';
import useDebounce from 'hooks/useDebounce';
+import { isRetryableError } from 'utils/errorUtils';
-import { TELEMETRY_SIGNALS, type TelemetrySignal } from '../variableModel';
+import {
+ DYNAMIC_SIGNAL_LABEL,
+ DYNAMIC_SIGNALS,
+ type DynamicSignalOption,
+ signalForApi,
+} from '../variableFormModel';
import styles from './VariableForm.module.scss';
interface DynamicVariableFieldsProps {
attribute: string;
- signal: TelemetrySignal;
+ signal: DynamicSignalOption;
onChange: (patch: {
dynamicAttribute?: string;
- dynamicSignal?: TelemetrySignal;
+ dynamicSignal?: DynamicSignalOption;
}) => void;
onPreview: (values: (string | number)[]) => void;
+ /** Inline error shown under the attribute field (e.g. duplicate attribute). */
+ attributeError?: string;
}
/** Dynamic-variable body: telemetry signal + field, whose live values preview. */
@@ -27,18 +37,24 @@ function DynamicVariableFields({
signal,
onChange,
onPreview,
+ attributeError,
}: DynamicVariableFieldsProps): JSX.Element {
const [search, setSearch] = useState('');
const debouncedSearch = useDebounce(search, 300);
+ const apiSignal = signalForApi(signal);
- const { data: keyData, isLoading } = useGetFieldKeys({
- signal,
+ const {
+ data: keyData,
+ isLoading,
+ error,
+ refetch,
+ } = useGetFieldKeys({
+ signal: apiSignal,
name: debouncedSearch || undefined,
});
// `keys` is a Record keyed BY field name; the field names are the map keys.
- // When the API reports the list is `complete`, search filters locally.
- const isComplete = keyData?.data?.complete === true;
+ // CustomSelect filters the supplied options locally as the user types.
const options = useMemo(
() =>
Object.keys(keyData?.data?.keys ?? {}).map((name) => ({
@@ -49,7 +65,7 @@ function DynamicVariableFields({
);
const { data: valueData } = useGetFieldValues({
- signal,
+ signal: apiSignal,
name: attribute,
enabled: !!attribute,
});
@@ -62,40 +78,60 @@ function DynamicVariableFields({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [valueData]);
+ const errorMessage = error ? (error as Error).message || null : null;
+
return (
<>
<div className={cx(styles.row, styles.sortSection)}>
- <div className={styles.labelContainer}>
+ <div className={cx(styles.labelContainer, styles.sourceLabel)}>
<Typography.Text className={styles.label}>Source</Typography.Text>
+ <TextToolTip
+ text="By default, this searches across logs, traces, and metrics, which can be slow. Selecting a single source improves performance. Many fields share the same values across different signals (for example, `k8s.pod.name` is identical in logs, traces and metrics) making one source enough. Only use `All telemetry` when you need fields that have different values in different signal types."
+ useFilledIcon={false}
+ outlinedIcon={<Info size={14} />}
+ />
</div>
- <SelectSimple
+ <Select
className={styles.sortSelect}
+ popupMatchSelectWidth={false}
value={signal}
- items={TELEMETRY_SIGNALS.map((s) => ({ label: s, value: s }))}
+ options={DYNAMIC_SIGNALS.map((s) => ({
+ label: DYNAMIC_SIGNAL_LABEL[s],
+ value: s,
+ }))}
onChange={(value): void =>
- onChange({ dynamicSignal: value as TelemetrySignal })
+ onChange({ dynamicSignal: value as DynamicSignalOption })
}
- testId="variable-signal-select"
+ data-testid="variable-signal-select"
/>
</div>
<div className={cx(styles.row, styles.sortSection)}>
<div className={styles.labelContainer}>
<Typography.Text className={styles.label}>Attribute</Typography.Text>
</div>
- <Select
+ <CustomSelect
className={styles.searchSelect}
showSearch
value={attribute || undefined}
placeholder="Select a telemetry field"
loading={isLoading}
- filterOption={isComplete}
+ options={options}
onSearch={setSearch}
onChange={(value): void => onChange({ dynamicAttribute: value as string })}
- options={options}
- notFoundContent={isLoading ? 'Loading…' : 'No fields found'}
+ noDataMessage="No fields found"
+ errorMessage={errorMessage}
+ onRetry={(): void => {
+ void refetch();
+ }}
+ showRetryButton={error ? isRetryableError(error) : true}
data-testid="variable-field-select"
/>
</div>
+ {attributeError ? (
+ <Typography.Text className={styles.errorText}>
+ {attributeError}
+ </Typography.Text>
+ ) : null}
</>
);
}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/ListVariableFields.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/ListVariableFields.tsx
new file mode 100644
index 0000000000..0c623719a2
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/ListVariableFields.tsx
@@ -0,0 +1,139 @@
+import { Badge } from '@signozhq/ui/badge';
+import { Switch } from '@signozhq/ui/switch';
+import { Typography } from '@signozhq/ui/typography';
+import cx from 'classnames';
+// eslint-disable-next-line signoz/no-antd-components -- fixed-option sort picker
+import { Select } from 'antd';
+import { CustomSelect } from 'components/NewSelect';
+
+import {
+ VARIABLE_SORT_LABEL,
+ VARIABLE_SORTS,
+ type VariableFormModel,
+ type VariableSort,
+} from '../variableFormModel';
+import styles from './VariableForm.module.scss';
+
+interface ListVariableFieldsProps {
+ model: VariableFormModel;
+ onChange: (patch: Partial<VariableFormModel>) => void;
+ previewValues: (string | number)[];
+ previewError: string | null;
+ defaultValue: string;
+ onDefaultValueChange: (value: string) => void;
+ /** Whether the "ALL values" toggle applies to this type (QUERY / CUSTOM). */
+ showAllOptionField: boolean;
+}
+
+/**
+ * Rows shared by the list-style variables (Query / Custom / Dynamic): the value
+ * preview, sort, multi-select / ALL toggles and the default-value picker.
+ */
+function ListVariableFields({
+ model,
+ onChange,
+ previewValues,
+ previewError,
+ defaultValue,
+ onDefaultValueChange,
+ showAllOptionField,
+}: ListVariableFieldsProps): JSX.Element {
+ return (
+ <>
+ <div className={cx(styles.row, styles.previewSection)}>
+ <Typography.Text className={styles.previewLabel}>
+ Preview of Values
+ </Typography.Text>
+ <div className={styles.previewValues}>
+ {previewError ? (
+ <Typography.Text className={styles.previewError}>
+ {previewError}
+ </Typography.Text>
+ ) : (
+ previewValues.map((value, idx) => (
+ <Badge
+ // eslint-disable-next-line react/no-array-index-key -- preview values are display-only and may contain duplicates
+ key={`${value}-${idx}`}
+ color="vanilla"
+ >
+ {value.toString()}
+ </Badge>
+ ))
+ )}
+ </div>
+ </div>
+
+ <div className={cx(styles.row, styles.sortSection)}>
+ <div className={styles.labelContainer}>
+ <Typography.Text className={styles.label}>Sort Values</Typography.Text>
+ </div>
+ <Select
+ className={styles.sortSelect}
+ popupMatchSelectWidth={false}
+ value={model.sort}
+ options={VARIABLE_SORTS.map((sort) => ({
+ label: VARIABLE_SORT_LABEL[sort],
+ value: sort,
+ }))}
+ onChange={(value): void => onChange({ sort: value as VariableSort })}
+ data-testid="variable-sort-select"
+ />
+ </div>
+
+ <div className={cx(styles.row, styles.multiSection)}>
+ <Typography.Text className={styles.rowLabel}>
+ Enable multiple values to be checked
+ </Typography.Text>
+ <Switch
+ value={model.multiSelect}
+ onChange={(checked): void =>
+ onChange({
+ multiSelect: checked,
+ showAllOption: checked ? model.showAllOption : false,
+ })
+ }
+ testId="variable-multi-switch"
+ />
+ </div>
+
+ {model.multiSelect && showAllOptionField ? (
+ <div className={cx(styles.row, styles.allOptionSection)}>
+ <Typography.Text className={styles.rowLabel}>
+ Include an option for ALL values
+ </Typography.Text>
+ <Switch
+ value={model.showAllOption}
+ onChange={(checked): void => onChange({ showAllOption: checked })}
+ testId="variable-all-switch"
+ />
+ </div>
+ ) : null}
+
+ <div className={cx(styles.row, styles.defaultValueSection)}>
+ <div className={styles.labelContainer}>
+ <Typography.Text className={styles.label}>Default Value</Typography.Text>
+ <Typography.Text className={styles.defaultValueDesc}>
+ {model.type === 'QUERY'
+ ? 'Click Test Run Query to see the values or add custom value'
+ : 'Select a value from the preview values or add custom value'}
+ </Typography.Text>
+ </div>
+ <CustomSelect
+ className={styles.searchSelect}
+ showSearch
+ allowClear
+ placeholder="Select a default value"
+ value={defaultValue || undefined}
+ onChange={(value): void => onDefaultValueChange((value as string) ?? '')}
+ options={previewValues.map((value) => ({
+ label: value.toString(),
+ value: value.toString(),
+ }))}
+ data-testid="variable-default-select"
+ />
+ </div>
+ </>
+ );
+}
+
+export default ListVariableFields;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/QueryVariableFields.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/QueryVariableFields.tsx
index d04a5366a8..9993a572ce 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/QueryVariableFields.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/QueryVariableFields.tsx
@@ -3,14 +3,14 @@ import { Button } from '@signozhq/ui/button';
import { Typography } from '@signozhq/ui/typography';
import dashboardVariablesQuery from 'api/dashboard/variables/dashboardVariablesQuery';
import Editor from 'components/Editor';
-import sortValues from 'lib/dashboardVariables/sortVariableValues';
+import type { PayloadVariables } from 'types/api/dashboard/variables/query';
-import type { VariableSort } from '../variableModel';
import styles from './VariableForm.module.scss';
interface QueryVariableFieldsProps {
queryValue: string;
- sort: VariableSort;
+ /** Sibling variable selections, so dependent `$vars` in the query resolve. */
+ variables: PayloadVariables;
onChange: (queryValue: string) => void;
onPreview: (values: (string | number)[]) => void;
onError: (message: string | null) => void;
@@ -19,7 +19,7 @@ interface QueryVariableFieldsProps {
/** Query-variable body: SQL editor + "Test Run Query" that previews the values. */
function QueryVariableFields({
queryValue,
- sort,
+ variables,
onChange,
onPreview,
onError,
@@ -30,20 +30,21 @@ function QueryVariableFields({
setIsRunning(true);
onError(null);
try {
- const res = await dashboardVariablesQuery({
- query: queryValue,
- variables: {},
- });
+ const res = await dashboardVariablesQuery({ query: queryValue, variables });
if (res.statusCode === 200 && res.payload) {
- onPreview(
- sortValues(res.payload.variableValues ?? [], sort) as (string | number)[],
- );
+ onPreview(res.payload.variableValues ?? []);
} else {
onError(res.error || 'Failed to run query');
onPreview([]);
}
} catch (err) {
- onError((err as Error).message || 'Failed to run query');
+ // `dashboardVariablesQuery` throws `{ message, details: { error } }`.
+ const detail = (err as { details?: { error?: string } }).details?.error;
+ const message =
+ detail && detail.includes('Syntax error:')
+ ? 'Please make sure query is valid and dependent variables are selected'
+ : detail || (err as Error).message || 'Failed to run query';
+ onError(message);
onPreview([]);
} finally {
setIsRunning(false);
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.module.scss
index dadaf2423d..17d052248c 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.module.scss
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.module.scss
@@ -5,22 +5,8 @@
.container {
display: flex;
flex-direction: column;
- border: 1px solid var(--l1-border);
border-radius: 3px;
-}
-
-.allVariables {
- display: flex;
- align-items: center;
- gap: 8px;
- padding: 10px 16px;
- border-bottom: 1px solid var(--l1-border);
-}
-
-.allVariablesBtn {
- --button-height: 24px;
- --button-padding: 0;
- color: var(--muted-foreground);
+ border: 1px solid var(--l2-border);
}
.content {
@@ -42,6 +28,12 @@
width: 200px;
}
+.sourceLabel {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+}
+
.label {
color: var(--l2-foreground);
font-family: Inter;
@@ -59,7 +51,7 @@
.textarea,
.defaultInput {
padding: 6px 6px 6px 8px;
- border: 1px solid var(--l1-border);
+ border: 1px solid var(--l2-border);
border-radius: 2px;
background: var(--l3-background);
}
@@ -78,48 +70,89 @@
color: var(--bg-amber-500);
}
-/* Variable type segmented group */
+/* Variable type — Tabs root composing the picker row + per-type body panels. */
.typeSection {
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
+ margin-top: 40px;
+ margin-bottom: 0;
+}
+
+/* Picker row (label left, tabs right); the bottom divider separates type from
+ config. Single line — the tab row scrolls (never wraps) when narrow. */
+.typePicker {
+ display: flex;
align-items: center;
justify-content: space-between;
+ gap: 16px;
+ padding-bottom: 12px;
+ border-bottom: 1px solid var(--l2-border);
+
+ @media (max-width: 1440px) {
+ flex-wrap: wrap;
+ }
+}
+
+/* Active tab panel — reset the Tabs default padding; body rows handle spacing. */
+.typePanel {
+ padding: 0 !important;
+}
+
+.typeContent {
+ display: flex;
+ flex-direction: column;
+ gap: 20px;
}
.typeLabelContainer {
display: flex;
align-items: center;
gap: 8px;
- width: auto;
+ white-space: nowrap;
}
-.typeBtnGroup {
- display: grid;
- grid-template-columns: repeat(4, max-content);
- height: 32px;
- flex-shrink: 0;
- border: 1px solid var(--l1-border);
+/* Horizontal scroll so the tab row never wraps to a second line. The scrollbar
+ is hidden — the row stays a single crisp line and scrolls only when narrow. */
+.typeTabsScroll {
+ justify-self: flex-end;
+ --tab-list-wrapper-secondary-padding-left: 0;
+}
+
+/* Connected segmented control, mirroring Overview's SegmentedControl: no outer
+ padding, segments divided by 1px borders, active segment filled + bold. */
+.typeTabs {
+ display: inline-flex;
+ flex-wrap: nowrap;
+ width: max-content;
+ gap: 0;
+ padding: 0;
+ border: 1px solid var(--l2-border);
border-radius: 2px;
- background: var(--l2-background);
- box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.1);
+ background: transparent;
}
-.typeBtn {
- --button-height: 32px;
- display: flex;
+.typeTab {
+ display: inline-flex;
+ flex-shrink: 0;
align-items: center;
- justify-content: center;
- gap: 4px;
- min-width: 114px;
+ gap: 6px;
+ min-height: 24px;
+ padding: 6px 14px;
+ white-space: nowrap;
border-radius: 0;
color: var(--l2-foreground);
- & + & {
- border-left: 1px solid var(--l1-border);
+ &:not(:last-child) {
+ border-right: 1px solid var(--l2-border);
}
-}
-.typeBtnSelected {
- background: var(--l1-border);
- color: var(--l1-foreground);
+ &[data-state='active'] {
+ color: var(--l1-foreground);
+ font-weight: 500;
+ // override the Tabs component's default (transparent) active background.
+ background: var(--l3-background) !important;
+ }
}
.betaTag {
@@ -138,7 +171,7 @@
.editorWrap {
height: 240px;
overflow: hidden;
- border: 1px solid var(--l1-border);
+ border: 1px solid var(--l2-border);
border-radius: 2px;
}
@@ -154,7 +187,7 @@
.customSection :global(.custom-collapse) {
width: 100%;
- border: 1px solid var(--l1-border);
+ border: 1px solid var(--l2-border);
border-radius: 3px 3px 0 0;
:global(.ant-collapse-item) {
@@ -208,7 +241,7 @@
min-height: 88px;
margin-bottom: 0;
padding-bottom: 8px;
- border: 1px solid var(--l1-border);
+ border: 1px solid var(--l2-border);
border-radius: 3px;
}
@@ -271,13 +304,9 @@
letter-spacing: -0.07px;
}
-.sortSelect {
- width: 192px;
-}
-
.defaultValueSection {
- display: grid;
- grid-template-columns: max-content 1fr;
+ display: flex;
+ justify-content: space-between;
gap: 1rem;
align-items: center;
margin-bottom: 0;
@@ -297,14 +326,21 @@
letter-spacing: -0.06px;
}
+/* All variable selects (Source / Attribute / Sort / Default Value) share width
+ and a consistent --l2-border outline. */
+.sortSelect,
.searchSelect {
- width: 100%;
+ width: 240px;
+ flex-shrink: 0;
+
+ :global(.ant-select-selector) {
+ border-color: var(--l2-border) !important;
+ }
}
-/* Footer */
-.footer {
+.actionButtons {
+ width: 100%;
display: flex;
justify-content: flex-end;
gap: 1rem;
- margin-top: 12px;
}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.tsx
index 6c5cc678b4..f9e1500278 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableForm.tsx
@@ -1,350 +1,199 @@
-import { useEffect, useState } from 'react';
-import { ArrowLeft, Check, X } from '@signozhq/icons';
-import { Badge } from '@signozhq/ui/badge';
+import { Check, X } from '@signozhq/icons';
import { Button } from '@signozhq/ui/button';
import { Input } from '@signozhq/ui/input';
-import { SelectSimple } from '@signozhq/ui/select';
-import { Switch } from '@signozhq/ui/switch';
+import { TabsContent, TabsRoot } from '@signozhq/ui/tabs';
import { Typography } from '@signozhq/ui/typography';
import cx from 'classnames';
-// eslint-disable-next-line signoz/no-antd-components -- TextArea/Collapse/searchable Select: no @signozhq/ui equivalent
-import { Collapse, Input as AntdInput, Select } from 'antd';
-import { commaValuesParser } from 'lib/dashboardVariables/customCommaValuesParser';
-import sortValues from 'lib/dashboardVariables/sortVariableValues';
+// eslint-disable-next-line signoz/no-antd-components -- TextArea/Collapse: no @signozhq/ui equivalent
+import { Collapse, Input as AntdInput } from 'antd';
-import {
- VARIABLE_SORTS,
- type VariableFormModel,
- type VariableSort,
- type VariableType,
-} from '../variableModel';
+import type { VariableType } from '../variableFormModel';
import DynamicVariableFields from './DynamicVariableFields';
+import ListVariableFields from './ListVariableFields';
import QueryVariableFields from './QueryVariableFields';
-import VariableTypeSelector from './VariableTypeSelector';
+import { useVariableForm } from './useVariableForm';
+import VariableTypeTabs from './VariableTypeTabs';
import styles from './VariableForm.module.scss';
-
-const SORT_LABEL: Record<VariableSort, string> = {
- DISABLED: 'Disabled',
- ASC: 'Ascending',
- DESC: 'Descending',
-};
-
-function getNameError(name: string, existingNames: string[]): string | null {
- if (name === '') {
- return 'Variable name is required';
- }
- if (/\s/.test(name)) {
- return 'Variable name cannot contain whitespaces';
- }
- if (existingNames.includes(name)) {
- return 'Variable name already exists';
- }
- return null;
-}
-
-interface VariableFormProps {
- initial: VariableFormModel;
- /** Names of the other variables, for uniqueness validation. */
- existingNames: string[];
- isSaving: boolean;
- onClose: () => void;
- onSave: (model: VariableFormModel) => void;
-}
+import BackToAllVariables from '../components/BackToAllVariables/BackToAllVariables';
+import { VariableFormProps } from '../types';
+import VariableInfoForm from '../components/VariableInfoForm/VariableInfoForm';
/**
* In-drawer variable editor reproducing the V1 VariableItem layout, built on
* @signozhq components (antd kept only for the monaco editor, TextArea, Collapse
- * and searchable selects). Master→detail: renders in place of the list.
+ * and searchable selects). Master→detail: renders in place of the list. Form
+ * state/handlers live in {@link useVariableForm}; the shared list-type rows in
+ * {@link ListVariableFields}.
*/
function VariableForm({
initial,
- existingNames,
+ siblings,
+ isNew,
isSaving,
onClose,
onSave,
}: VariableFormProps): JSX.Element {
- const [model, setModel] = useState<VariableFormModel>(initial);
- const [previewValues, setPreviewValues] = useState<(string | number)[]>([]);
- const [previewError, setPreviewError] = useState<string | null>(null);
- const [defaultValue, setDefaultValue] = useState<string>(
- ((initial.defaultValue as { value?: string })?.value ?? '') as string,
- );
-
- useEffect(() => {
- setModel(initial);
- setPreviewValues([]);
- setPreviewError(null);
- setDefaultValue(
- ((initial.defaultValue as { value?: string })?.value ?? '') as string,
- );
- }, [initial]);
-
- const set = (patch: Partial<VariableFormModel>): void =>
- setModel((prev) => ({ ...prev, ...patch }));
-
- const selectType = (type: VariableType): void => {
- set({ type });
- setPreviewValues([]);
- setPreviewError(null);
- };
-
- const onCustomChange = (value: string): void => {
- set({ customValue: value });
- setPreviewValues(
- sortValues(commaValuesParser(value), model.sort) as (string | number)[],
- );
- };
-
- const trimmedName = model.name.trim();
- const nameError = getNameError(trimmedName, existingNames);
-
- const isListType =
- model.type === 'QUERY' || model.type === 'CUSTOM' || model.type === 'DYNAMIC';
- const showAllOptionField = model.type === 'QUERY' || model.type === 'CUSTOM';
-
- const handleSave = (): void => {
- onSave({
- ...model,
- name: trimmedName,
- defaultValue: defaultValue ? { value: defaultValue } : undefined,
- });
- };
+ const {
+ model,
+ set,
+ onNameChange,
+ selectType,
+ onCustomChange,
+ onDynamicChange,
+ setRawPreview,
+ previewValues,
+ previewError,
+ setPreviewError,
+ defaultValue,
+ setDefaultValue,
+ visibleNameError,
+ nameError,
+ attributeError,
+ cycleError,
+ isListType,
+ showAllOptionField,
+ payloadVariables,
+ handleSave,
+ } = useVariableForm({ initial, siblings, isNew, onSave });
+
+ // Shared list rows (preview/sort/multi/default) for the list-type variables;
+ // rendered as a sibling inside each list-type panel. Only the active panel
+ // mounts (Tabs unmounts the rest), so reusing one element is safe.
+ const listFields = isListType ? (
+ <ListVariableFields
+ model={model}
+ onChange={set}
+ previewValues={previewValues}
+ previewError={previewError}
+ defaultValue={defaultValue}
+ onDefaultValueChange={setDefaultValue}
+ showAllOptionField={showAllOptionField}
+ />
+ ) : null;
return (
- <>
- <div className={styles.container}>
- <div className={styles.allVariables}>
- <Button
- variant="ghost"
- color="secondary"
- className={styles.allVariablesBtn}
- prefix={<ArrowLeft size={14} />}
- onClick={onClose}
- testId="variable-form-back"
- >
- All variables
- </Button>
- </div>
-
- <div className={styles.content}>
- {/* Name */}
- <div className={cx(styles.row, styles.column)}>
- <Typography.Text className={styles.label}>Name</Typography.Text>
- <Input
- className={styles.input}
- value={model.name}
- placeholder="Unique name of the variable"
- onChange={(e): void => set({ name: e.target.value })}
- testId="variable-name-input"
- />
- {nameError ? (
- <Typography.Text className={styles.errorText}>
- {nameError}
- </Typography.Text>
- ) : null}
- </div>
-
- {/* Description */}
- <div className={cx(styles.row, styles.column)}>
- <Typography.Text className={styles.label}>Description</Typography.Text>
- <AntdInput.TextArea
- className={styles.textarea}
- value={model.description}
- placeholder="Enter a description for the variable"
- rows={3}
- onChange={(e): void => set({ description: e.target.value })}
- data-testid="variable-description-input"
- />
- </div>
-
- {/* Variable Type */}
- <VariableTypeSelector value={model.type} onChange={selectType} />
-
- {/* Type-specific body */}
- {model.type === 'DYNAMIC' ? (
- <DynamicVariableFields
- attribute={model.dynamicAttribute}
- signal={model.dynamicSignal}
- onChange={(patch): void => set(patch)}
- onPreview={setPreviewValues}
- />
- ) : null}
-
- {model.type === 'QUERY' ? (
- <QueryVariableFields
- queryValue={model.queryValue}
- sort={model.sort}
- onChange={(queryValue): void => set({ queryValue })}
- onPreview={setPreviewValues}
- onError={setPreviewError}
- />
- ) : null}
-
- {model.type === 'CUSTOM' ? (
- <div className={cx(styles.row, styles.customSection)}>
- <Collapse
- collapsible="header"
- rootClassName="custom-collapse"
- defaultActiveKey={['1']}
- items={[
- {
- key: '1',
- label: 'Options',
- children: (
- <AntdInput.TextArea
- value={model.customValue}
- placeholder="Enter options separated by commas."
- rootClassName="comma-input"
- onChange={(e): void => onCustomChange(e.target.value)}
- data-testid="variable-custom-input"
- />
- ),
- },
- ]}
+ <div className={styles.container}>
+ <BackToAllVariables onClose={onClose} />
+
+ <div className={styles.content}>
+ <VariableInfoForm
+ title={model.name}
+ description={model.description}
+ onTitleChange={onNameChange}
+ onDescriptionChange={(value): void => set({ description: value })}
+ visibleNameError={visibleNameError}
+ />
+
+ <TabsRoot
+ className={styles.typeSection}
+ value={model.type}
+ onValueChange={(next): void => selectType(next as VariableType)}
+ >
+ <VariableTypeTabs />
+
+ <TabsContent value="DYNAMIC" className={styles.typePanel}>
+ <div className={styles.typeContent}>
+ <DynamicVariableFields
+ attribute={model.dynamicAttribute}
+ signal={model.dynamicSignal}
+ onChange={onDynamicChange}
+ onPreview={setRawPreview}
+ attributeError={attributeError}
/>
+ {listFields}
</div>
- ) : null}
-
- {model.type === 'TEXT' ? (
- <div className={cx(styles.row, styles.textboxSection)}>
- <div className={styles.labelContainer}>
- <Typography.Text className={styles.label}>
- Default Value
- </Typography.Text>
- </div>
- <Input
- className={styles.defaultInput}
- value={model.textValue}
- placeholder="Enter a default value (if any)..."
- onChange={(e): void => set({ textValue: e.target.value })}
- testId="variable-text-input"
+ </TabsContent>
+
+ <TabsContent value="QUERY" className={styles.typePanel}>
+ <div className={styles.typeContent}>
+ <QueryVariableFields
+ queryValue={model.queryValue}
+ variables={payloadVariables}
+ onChange={(queryValue): void => set({ queryValue })}
+ onPreview={setRawPreview}
+ onError={setPreviewError}
/>
+ {listFields}
</div>
- ) : null}
-
- {/* Shared rows for list-type variables */}
- {isListType ? (
- <>
- <div className={cx(styles.row, styles.previewSection)}>
- <Typography.Text className={styles.previewLabel}>
- Preview of Values
- </Typography.Text>
- <div className={styles.previewValues}>
- {previewError ? (
- <Typography.Text className={styles.previewError}>
- {previewError}
- </Typography.Text>
- ) : (
- previewValues.map((value, idx) => (
- <Badge
- // eslint-disable-next-line react/no-array-index-key -- preview values are display-only and may contain duplicates
- key={`${value}-${idx}`}
- color="vanilla"
- >
- {value.toString()}
- </Badge>
- ))
- )}
- </div>
- </div>
-
- <div className={cx(styles.row, styles.sortSection)}>
- <div className={styles.labelContainer}>
- <Typography.Text className={styles.label}>Sort Values</Typography.Text>
- </div>
- <SelectSimple
- className={styles.sortSelect}
- value={model.sort}
- items={VARIABLE_SORTS.map((sort) => ({
- label: SORT_LABEL[sort],
- value: sort,
- }))}
- onChange={(value): void => set({ sort: value as VariableSort })}
- testId="variable-sort-select"
- />
- </div>
-
- <div className={cx(styles.row, styles.multiSection)}>
- <Typography.Text className={styles.rowLabel}>
- Enable multiple values to be checked
- </Typography.Text>
- <Switch
- value={model.multiSelect}
- onChange={(checked): void => {
- set({
- multiSelect: checked,
- showAllOption: checked ? model.showAllOption : false,
- });
- }}
- testId="variable-multi-switch"
+ </TabsContent>
+
+ <TabsContent value="CUSTOM" className={styles.typePanel}>
+ <div className={styles.typeContent}>
+ <div className={cx(styles.row, styles.customSection)}>
+ <Collapse
+ collapsible="header"
+ rootClassName="custom-collapse"
+ defaultActiveKey={['1']}
+ items={[
+ {
+ key: '1',
+ label: 'Options',
+ children: (
+ <AntdInput.TextArea
+ value={model.customValue}
+ placeholder="Enter options separated by commas."
+ rootClassName="comma-input"
+ onChange={(e): void => onCustomChange(e.target.value)}
+ data-testid="variable-custom-input"
+ />
+ ),
+ },
+ ]}
/>
</div>
+ {listFields}
+ </div>
+ </TabsContent>
- {model.multiSelect && showAllOptionField ? (
- <div className={cx(styles.row, styles.allOptionSection)}>
- <Typography.Text className={styles.rowLabel}>
- Include an option for ALL values
- </Typography.Text>
- <Switch
- value={model.showAllOption}
- onChange={(checked): void => set({ showAllOption: checked })}
- testId="variable-all-switch"
- />
- </div>
- ) : null}
-
- <div className={cx(styles.row, styles.defaultValueSection)}>
+ <TabsContent value="TEXT" className={styles.typePanel}>
+ <div className={styles.typeContent}>
+ <div className={cx(styles.row, styles.textboxSection)}>
<div className={styles.labelContainer}>
<Typography.Text className={styles.label}>
Default Value
</Typography.Text>
- <Typography.Text className={styles.defaultValueDesc}>
- {model.type === 'QUERY'
- ? 'Click Test Run Query to see the values or add custom value'
- : 'Select a value from the preview values or add custom value'}
- </Typography.Text>
</div>
- <Select
- className={styles.searchSelect}
- showSearch
- allowClear
- placeholder="Select a default value"
- value={defaultValue || undefined}
- onChange={(value): void => setDefaultValue(value ?? '')}
- options={previewValues.map((value) => ({
- label: value.toString(),
- value: value.toString(),
- }))}
- data-testid="variable-default-select"
+ <Input
+ className={styles.defaultInput}
+ value={model.textValue}
+ placeholder="Enter a default value (if any)..."
+ onChange={(e): void => set({ textValue: e.target.value })}
+ testId="variable-text-input"
/>
</div>
- </>
- ) : null}
- </div>
- </div>
+ </div>
+ </TabsContent>
+ </TabsRoot>
- <div className={styles.footer}>
- <Button
- variant="solid"
- color="secondary"
- prefix={<X size={14} />}
- onClick={onClose}
- >
- Discard
- </Button>
- <Button
- variant="solid"
- color="primary"
- prefix={<Check size={14} />}
- disabled={!!nameError}
- loading={isSaving}
- onClick={handleSave}
- testId="variable-save"
- >
- Save Variable
- </Button>
+ {cycleError ? (
+ <Typography.Text className={styles.errorText}>
+ {cycleError}
+ </Typography.Text>
+ ) : null}
+
+ <div className={styles.actionButtons}>
+ <Button
+ variant="outlined"
+ color="secondary"
+ prefix={<X size={14} />}
+ onClick={onClose}
+ >
+ Discard
+ </Button>
+ <Button
+ variant="solid"
+ color="primary"
+ prefix={<Check size={14} />}
+ disabled={!!nameError || !!attributeError}
+ loading={isSaving}
+ onClick={handleSave}
+ testId="variable-save"
+ >
+ Save Variable
+ </Button>
+ </div>
</div>
- </>
+ </div>
);
}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableTypeSelector.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableTypeSelector.tsx
deleted file mode 100644
index 31528e0d5c..0000000000
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableTypeSelector.tsx
+++ /dev/null
@@ -1,99 +0,0 @@
-import {
- ClipboardType,
- DatabaseZap,
- Info,
- LayoutList,
- Pyramid,
-} from '@signozhq/icons';
-import { Badge } from '@signozhq/ui/badge';
-import { Button } from '@signozhq/ui/button';
-import { Typography } from '@signozhq/ui/typography';
-import cx from 'classnames';
-import TextToolTip from 'components/TextToolTip';
-
-import type { VariableType } from '../variableModel';
-import styles from './VariableForm.module.scss';
-
-interface VariableTypeSelectorProps {
- value: VariableType;
- onChange: (type: VariableType) => void;
-}
-
-/** The segmented Dynamic / Textbox / Custom / Query type picker. */
-function VariableTypeSelector({
- value,
- onChange,
-}: VariableTypeSelectorProps): JSX.Element {
- return (
- <div className={cx(styles.row, styles.typeSection)}>
- <div className={styles.typeLabelContainer}>
- <Typography.Text className={styles.label}>Variable Type</Typography.Text>
- <TextToolTip
- text="Learn more about supported variable types"
- url="https://signoz.io/docs/userguide/manage-variables/#supported-variable-types"
- urlText="here"
- useFilledIcon={false}
- outlinedIcon={<Info size={14} />}
- />
- </div>
- <div className={styles.typeBtnGroup}>
- <Button
- variant="ghost"
- color="secondary"
- prefix={<Pyramid size={14} />}
- className={cx(styles.typeBtn, {
- [styles.typeBtnSelected]: value === 'DYNAMIC',
- })}
- onClick={(): void => onChange('DYNAMIC')}
- testId="variable-type-dynamic"
- >
- Dynamic
- <Badge color="robin" className={styles.betaTag}>
- Beta
- </Badge>
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- prefix={<ClipboardType size={14} />}
- className={cx(styles.typeBtn, {
- [styles.typeBtnSelected]: value === 'TEXT',
- })}
- onClick={(): void => onChange('TEXT')}
- testId="variable-type-textbox"
- >
- Textbox
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- prefix={<LayoutList size={14} />}
- className={cx(styles.typeBtn, {
- [styles.typeBtnSelected]: value === 'CUSTOM',
- })}
- onClick={(): void => onChange('CUSTOM')}
- testId="variable-type-custom"
- >
- Custom
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- prefix={<DatabaseZap size={14} />}
- className={cx(styles.typeBtn, {
- [styles.typeBtnSelected]: value === 'QUERY',
- })}
- onClick={(): void => onChange('QUERY')}
- testId="variable-type-query"
- >
- Query
- <Badge color="amber" className={styles.betaTag}>
- Not Recommended
- </Badge>
- </Button>
- </div>
- </div>
- );
-}
-
-export default VariableTypeSelector;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableTypeTabs.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableTypeTabs.tsx
new file mode 100644
index 0000000000..3887802d61
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/VariableTypeTabs.tsx
@@ -0,0 +1,93 @@
+import {
+ ClipboardType,
+ DatabaseZap,
+ Info,
+ LayoutList,
+ Pyramid,
+} from '@signozhq/icons';
+import { Badge } from '@signozhq/ui/badge';
+import { TabsList, TabsTrigger } from '@signozhq/ui/tabs';
+import { Typography } from '@signozhq/ui/typography';
+import TextToolTip from 'components/TextToolTip';
+
+import styles from './VariableForm.module.scss';
+
+/**
+ * Presentational trigger row for the variable-type tabs (label + segmented
+ * triggers). Must render inside a `TabsRoot`, which owns the active state and
+ * change handling; the matching `TabsContent` panels are siblings in the root.
+ */
+function VariableTypeTabs(): JSX.Element {
+ return (
+ <div className={styles.typePicker}>
+ <div className={styles.typeLabelContainer}>
+ <Typography.Text className={styles.label}>Variable Type</Typography.Text>
+ <TextToolTip
+ text="Learn more about supported variable types"
+ url="https://signoz.io/docs/userguide/manage-variables/#supported-variable-types"
+ urlText="here"
+ useFilledIcon={false}
+ outlinedIcon={<Info size={14} />}
+ />
+ </div>
+
+ <div className={styles.typeTabsScroll}>
+ <TabsList variant="secondary" className={styles.typeTabs}>
+ <TabsTrigger
+ value="DYNAMIC"
+ className={styles.typeTab}
+ testId="variable-type-dynamic"
+ >
+ <Pyramid size={14} />
+ Dynamic
+ <Badge color="robin" className={styles.betaTag}>
+ Beta
+ </Badge>
+ </TabsTrigger>
+ <TabsTrigger
+ value="TEXT"
+ className={styles.typeTab}
+ testId="variable-type-textbox"
+ >
+ <ClipboardType size={14} />
+ Textbox
+ </TabsTrigger>
+ <TabsTrigger
+ value="CUSTOM"
+ className={styles.typeTab}
+ testId="variable-type-custom"
+ >
+ <LayoutList size={14} />
+ Custom
+ </TabsTrigger>
+ <TabsTrigger
+ value="QUERY"
+ className={styles.typeTab}
+ testId="variable-type-query"
+ >
+ <DatabaseZap size={14} />
+ Query
+ <Badge color="amber" className={styles.betaTag}>
+ Not Recommended
+ </Badge>
+ <span
+ className={styles.betaTag}
+ onClick={(e): void => e.stopPropagation()}
+ role="presentation"
+ >
+ <TextToolTip
+ text="Learn why we don't recommend"
+ url="https://signoz.io/docs/userguide/manage-variables/#why-avoid-clickhouse-query-variables"
+ urlText="here"
+ useFilledIcon={false}
+ outlinedIcon={<Info size={14} />}
+ />
+ </span>
+ </TabsTrigger>
+ </TabsList>
+ </div>
+ </div>
+ );
+}
+
+export default VariableTypeTabs;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/useVariableForm.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/useVariableForm.ts
new file mode 100644
index 0000000000..d96e78d0e9
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/useVariableForm.ts
@@ -0,0 +1,191 @@
+import { useEffect, useMemo, useState } from 'react';
+import { commaValuesParser } from 'lib/dashboardVariables/customCommaValuesParser';
+import type { PayloadVariables } from 'types/api/dashboard/variables/query';
+
+import type { VariableSelectionMap } from '../../../VariablesBar/selectionTypes';
+import { useDashboardStore } from '../../../store/useDashboardStore';
+import { detectVariableCycle } from '../variableDependencies';
+import {
+ sortValuesByOrder,
+ type VariableFormModel,
+ type VariableType,
+} from '../variableFormModel';
+import { getAttributeError, getNameError } from './variableValidation';
+
+// Stable reference so the zustand selector never returns a fresh object (which
+// would make useSyncExternalStore loop) when this dashboard has no selections.
+const EMPTY_SELECTIONS: VariableSelectionMap = {};
+
+interface UseVariableFormArgs {
+ initial: VariableFormModel;
+ siblings: VariableFormModel[];
+ isNew: boolean;
+ onSave: (model: VariableFormModel) => void;
+}
+
+export interface UseVariableForm {
+ model: VariableFormModel;
+ set: (patch: Partial<VariableFormModel>) => void;
+ onNameChange: (value: string) => void;
+ selectType: (type: VariableType) => void;
+ onCustomChange: (value: string) => void;
+ onDynamicChange: (patch: Partial<VariableFormModel>) => void;
+ setRawPreview: (values: (string | number)[]) => void;
+ previewValues: (string | number)[];
+ previewError: string | null;
+ setPreviewError: (message: string | null) => void;
+ defaultValue: string;
+ setDefaultValue: (value: string) => void;
+ visibleNameError: string | null;
+ nameError: string | null;
+ attributeError: string | undefined;
+ cycleError: string | null;
+ isListType: boolean;
+ showAllOptionField: boolean;
+ payloadVariables: PayloadVariables;
+ handleSave: () => void;
+}
+
+const readDefaultValue = (model: VariableFormModel): string =>
+ ((model.defaultValue as { value?: string })?.value ?? '') as string;
+
+/** Form state, derivations and handlers for the variable editor. */
+export function useVariableForm({
+ initial,
+ siblings,
+ isNew,
+ onSave,
+}: UseVariableFormArgs): UseVariableForm {
+ const [model, setModel] = useState<VariableFormModel>(initial);
+ // Raw, unsorted preview; `previewValues` applies the chosen sort so a shown
+ // preview re-sorts when Sort changes.
+ const [rawPreview, setRawPreview] = useState<(string | number)[]>([]);
+ const [previewError, setPreviewError] = useState<string | null>(null);
+ const [cycleError, setCycleError] = useState<string | null>(null);
+ // In add mode, mirror the chosen attribute into the name until the user types.
+ const [nameTouched, setNameTouched] = useState(false);
+ const [defaultValue, setDefaultValue] = useState<string>(
+ readDefaultValue(initial),
+ );
+
+ useEffect(() => {
+ setModel(initial);
+ setRawPreview([]);
+ setPreviewError(null);
+ setCycleError(null);
+ setNameTouched(false);
+ setDefaultValue(readDefaultValue(initial));
+ }, [initial]);
+
+ const set = (patch: Partial<VariableFormModel>): void =>
+ setModel((prev) => ({ ...prev, ...patch }));
+
+ const previewValues = useMemo(
+ () => sortValuesByOrder(rawPreview, model.sort) as (string | number)[],
+ [rawPreview, model.sort],
+ );
+
+ const existingNames = useMemo(() => siblings.map((v) => v.name), [siblings]);
+
+ const existingDynamicAttributes = useMemo(
+ () =>
+ siblings
+ .filter((v) => v.type === 'DYNAMIC' && v.dynamicAttribute)
+ .map((v) => v.dynamicAttribute),
+ [siblings],
+ );
+
+ // Sibling selections feed the Query "Test Run" so dependent `$vars` resolve.
+ const dashboardId = useDashboardStore((s) => s.dashboardId);
+ const selections = useDashboardStore(
+ (s) => s.variableValues[dashboardId ?? ''] ?? EMPTY_SELECTIONS,
+ );
+ const payloadVariables = useMemo<PayloadVariables>(() => {
+ const out: PayloadVariables = {};
+ siblings.forEach((v) => {
+ if (v.name) {
+ out[v.name] = selections[v.name]?.value ?? null;
+ }
+ });
+ return out;
+ }, [siblings, selections]);
+
+ const trimmedName = model.name.trim();
+ const nameError = getNameError(trimmedName, existingNames, initial.name);
+ // Surface the message only once the field is dirty; Save stays disabled regardless.
+ const visibleNameError = nameTouched ? nameError : null;
+ const attributeError = getAttributeError(model, existingDynamicAttributes);
+
+ const isListType =
+ model.type === 'QUERY' || model.type === 'CUSTOM' || model.type === 'DYNAMIC';
+ const showAllOptionField = model.type === 'QUERY' || model.type === 'CUSTOM';
+
+ const onNameChange = (value: string): void => {
+ setNameTouched(true);
+ set({ name: value });
+ };
+
+ const selectType = (type: VariableType): void => {
+ set({ type });
+ setRawPreview([]);
+ setPreviewError(null);
+ };
+
+ const onCustomChange = (value: string): void => {
+ set({ customValue: value });
+ setRawPreview(commaValuesParser(value));
+ };
+
+ // In add mode, mirror the selected attribute into the name until the user
+ // edits the name themselves (matches the V1 dynamic-variable behaviour).
+ const onDynamicChange = (patch: Partial<VariableFormModel>): void => {
+ if (isNew && !nameTouched && patch.dynamicAttribute) {
+ set({ ...patch, name: patch.dynamicAttribute });
+ } else {
+ set(patch);
+ }
+ };
+
+ const handleSave = (): void => {
+ const next: VariableFormModel = {
+ ...model,
+ name: trimmedName,
+ defaultValue: defaultValue ? { value: defaultValue } : undefined,
+ };
+
+ const cycle = detectVariableCycle([...siblings, next]);
+ if (cycle) {
+ setCycleError(
+ `Cannot save: circular dependency detected between variables: ${cycle.join(
+ ' → ',
+ )}`,
+ );
+ return;
+ }
+ setCycleError(null);
+ onSave(next);
+ };
+
+ return {
+ model,
+ set,
+ onNameChange,
+ selectType,
+ onCustomChange,
+ onDynamicChange,
+ setRawPreview,
+ previewValues,
+ previewError,
+ setPreviewError,
+ defaultValue,
+ setDefaultValue,
+ visibleNameError,
+ nameError,
+ attributeError,
+ cycleError,
+ isListType,
+ showAllOptionField,
+ payloadVariables,
+ handleSave,
+ };
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/variableValidation.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/variableValidation.ts
new file mode 100644
index 0000000000..dac9659267
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableForm/variableValidation.ts
@@ -0,0 +1,37 @@
+import type { VariableFormModel } from '../variableFormModel';
+
+/**
+ * Name validation, mirroring V1: empty / whitespace are rejected, and the name
+ * set includes self, but keeping your own (original) name is always allowed.
+ */
+export function getNameError(
+ name: string,
+ existingNames: string[],
+ originalName: string,
+): string | null {
+ if (name === '') {
+ return 'Variable name is required';
+ }
+ if (/\s/.test(name)) {
+ return 'Variable name cannot contain whitespaces';
+ }
+ if (name !== originalName && existingNames.includes(name)) {
+ return 'Variable name already exists';
+ }
+ return null;
+}
+
+/** Rejects a dynamic variable reusing an attribute already bound elsewhere. */
+export function getAttributeError(
+ model: VariableFormModel,
+ existingDynamicAttributes: string[],
+): string | undefined {
+ if (
+ model.type === 'DYNAMIC' &&
+ model.dynamicAttribute &&
+ existingDynamicAttributes.includes(model.dynamicAttribute)
+ ) {
+ return 'A variable with this attribute key already exists';
+ }
+ return undefined;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableRow.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableRow.tsx
new file mode 100644
index 0000000000..a7d888bb68
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariableRow.tsx
@@ -0,0 +1,140 @@
+import type { CSSProperties } from 'react';
+import { Check, GripVertical, PenLine, Trash2, X } from '@signozhq/icons';
+import { useSortable } from '@dnd-kit/sortable';
+import { CSS } from '@dnd-kit/utilities';
+import { Button } from '@signozhq/ui/button';
+import { Typography } from '@signozhq/ui/typography';
+
+import type { VariableFormModel } from './variableFormModel';
+import styles from './Variables.module.scss';
+
+const TYPE_LABEL: Record<VariableFormModel['type'], string> = {
+ QUERY: 'Query',
+ CUSTOM: 'Custom',
+ TEXT: 'Text',
+ DYNAMIC: 'Dynamic',
+};
+
+interface VariableRowProps {
+ variable: VariableFormModel;
+ index: number;
+ canEdit: boolean;
+ /** True when this row's delete is awaiting inline confirmation. */
+ isConfirmingDelete: boolean;
+ onEdit: (index: number) => void;
+ onRequestDelete: (index: number) => void;
+ onConfirmDelete: (index: number) => void;
+ onCancelDelete: () => void;
+}
+
+/** A single draggable variable row (drag handle + meta + inline actions). */
+function VariableRow({
+ variable,
+ index,
+ canEdit,
+ isConfirmingDelete,
+ onEdit,
+ onRequestDelete,
+ onConfirmDelete,
+ onCancelDelete,
+}: VariableRowProps): JSX.Element {
+ const {
+ attributes,
+ listeners,
+ setNodeRef,
+ setActivatorNodeRef,
+ transform,
+ transition,
+ isDragging,
+ } = useSortable({ id: variable.name });
+
+ const style: CSSProperties = {
+ transform: CSS.Transform.toString(transform),
+ transition,
+ ...(isDragging ? { position: 'relative', zIndex: 1, opacity: 0.8 } : {}),
+ };
+
+ return (
+ <div
+ ref={setNodeRef}
+ style={style}
+ className={styles.row}
+ data-testid={`variable-row-${variable.name}`}
+ >
+ <div className={styles.rowMain}>
+ {canEdit ? (
+ <span
+ ref={setActivatorNodeRef}
+ className={styles.dragHandle}
+ aria-label="Reorder variable"
+ {...attributes}
+ {...listeners}
+ >
+ <GripVertical size={14} />
+ </span>
+ ) : null}
+ <Typography.Text className={styles.varName}>
+ ${variable.name}
+ </Typography.Text>
+ <span className={styles.typeTag}>{TYPE_LABEL[variable.type]}</span>
+ {variable.description ? (
+ <Typography.Text className={styles.varDesc}>
+ {variable.description}
+ </Typography.Text>
+ ) : null}
+ </div>
+
+ {canEdit && isConfirmingDelete ? (
+ <div className={styles.rowActions}>
+ <Typography.Text className={styles.confirmText}>Delete?</Typography.Text>
+ <Button
+ variant="ghost"
+ color="destructive"
+ size="icon"
+ onClick={(): void => onConfirmDelete(index)}
+ aria-label="Confirm delete"
+ testId={`variable-delete-confirm-${variable.name}`}
+ >
+ <Check size={14} />
+ </Button>
+ <Button
+ variant="ghost"
+ color="secondary"
+ size="icon"
+ onClick={onCancelDelete}
+ aria-label="Cancel delete"
+ >
+ <X size={14} />
+ </Button>
+ </div>
+ ) : null}
+
+ {canEdit && !isConfirmingDelete ? (
+ <div className={styles.rowActions}>
+ <Button
+ variant="ghost"
+ color="secondary"
+ size="icon"
+ onClick={(): void => onEdit(index)}
+ aria-label="Edit variable"
+ testId={`variable-edit-${variable.name}`}
+ >
+ <PenLine size={14} />
+ </Button>
+ <Button
+ variant="ghost"
+ color="secondary"
+ size="icon"
+ onClick={(): void => onRequestDelete(index)}
+ aria-label="Delete variable"
+ testId={`variable-delete-${variable.name}`}
+ >
+ <Trash2 size={14} />
+ </Button>
+ </div>
+ ) : null}
+ </div>
+ );
+}
+
+export default VariableRow;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/Variables.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/Variables.module.scss
index 7d4be81848..e43c31b840 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/Variables.module.scss
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/Variables.module.scss
@@ -2,13 +2,11 @@
display: flex;
flex-direction: column;
gap: 16px;
- padding: 20px 16px;
}
.header {
display: flex;
- align-items: flex-start;
- justify-content: space-between;
+ justify-content: flex-end;
gap: 16px;
}
@@ -30,14 +28,6 @@
color: var(--l2-foreground);
}
-.empty {
- padding: 32px;
- text-align: center;
- border: 1px dashed var(--l1-border);
- border-radius: 4px;
- color: var(--l2-foreground);
-}
-
.list {
display: flex;
flex-direction: column;
@@ -62,6 +52,15 @@
min-width: 0;
}
+.dragHandle {
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ color: var(--l3-foreground);
+ cursor: grab;
+ touch-action: none;
+}
+
.varName {
font-weight: 500;
color: var(--l1-foreground);
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariablesList.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariablesList.tsx
index a8e832c8d0..07d0abafda 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariablesList.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/VariablesList.tsx
@@ -1,24 +1,20 @@
+import type { DragEndEvent } from '@dnd-kit/core';
import {
- Check,
- ChevronDown,
- ChevronUp,
- PenLine,
- Trash2,
- X,
-} from '@signozhq/icons';
-import { Button } from '@signozhq/ui/button';
-import { Typography } from '@signozhq/ui/typography';
+ DndContext,
+ PointerSensor,
+ useSensor,
+ useSensors,
+} from '@dnd-kit/core';
+import { restrictToVerticalAxis } from '@dnd-kit/modifiers';
+import {
+ SortableContext,
+ verticalListSortingStrategy,
+} from '@dnd-kit/sortable';
-import type { VariableFormModel } from './variableModel';
+import VariableRow from './VariableRow';
+import type { VariableFormModel } from './variableFormModel';
import styles from './Variables.module.scss';
-const TYPE_LABEL: Record<VariableFormModel['type'], string> = {
- QUERY: 'Query',
- CUSTOM: 'Custom',
- TEXT: 'Text',
- DYNAMIC: 'Dynamic',
-};
-
interface VariablesListProps {
variables: VariableFormModel[];
canEdit: boolean;
@@ -41,98 +37,48 @@ function VariablesList({
onCancelDelete,
onMove,
}: VariablesListProps): JSX.Element {
- return (
- <div className={styles.list} data-testid="variables-list">
- {variables.map((variable, index) => (
- <div
- className={styles.row}
- key={variable.name || `variable-${index}`}
- data-testid={`variable-row-${variable.name}`}
- >
- <div className={styles.rowMain}>
- <Typography.Text className={styles.varName}>
- ${variable.name}
- </Typography.Text>
- <span className={styles.typeTag}>{TYPE_LABEL[variable.type]}</span>
- {variable.description ? (
- <Typography.Text className={styles.varDesc}>
- {variable.description}
- </Typography.Text>
- ) : null}
- </div>
+ const sensors = useSensors(
+ useSensor(PointerSensor, { activationConstraint: { distance: 1 } }),
+ );
- {canEdit && confirmingIndex === index ? (
- <div className={styles.rowActions}>
- <Typography.Text className={styles.confirmText}>Delete?</Typography.Text>
- <Button
- variant="ghost"
- color="destructive"
- size="icon"
- onClick={(): void => onConfirmDelete(index)}
- aria-label="Confirm delete"
- testId={`variable-delete-confirm-${variable.name}`}
- >
- <Check size={14} />
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- size="icon"
- onClick={onCancelDelete}
- aria-label="Cancel delete"
- >
- <X size={14} />
- </Button>
- </div>
- ) : null}
+ const handleDragEnd = ({ active, over }: DragEndEvent): void => {
+ if (!over || active.id === over.id) {
+ return;
+ }
+ const from = variables.findIndex((v) => v.name === active.id);
+ const to = variables.findIndex((v) => v.name === over.id);
+ if (from !== -1 && to !== -1) {
+ onMove(from, to);
+ }
+ };
- {canEdit && confirmingIndex !== index ? (
- <div className={styles.rowActions}>
- <Button
- variant="ghost"
- color="secondary"
- size="icon"
- disabled={index === 0}
- onClick={(): void => onMove(index, index - 1)}
- aria-label="Move up"
- >
- <ChevronUp size={14} />
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- size="icon"
- disabled={index === variables.length - 1}
- onClick={(): void => onMove(index, index + 1)}
- aria-label="Move down"
- >
- <ChevronDown size={14} />
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- size="icon"
- onClick={(): void => onEdit(index)}
- aria-label="Edit variable"
- testId={`variable-edit-${variable.name}`}
- >
- <PenLine size={14} />
- </Button>
- <Button
- variant="ghost"
- color="secondary"
- size="icon"
- onClick={(): void => onRequestDelete(index)}
- aria-label="Delete variable"
- testId={`variable-delete-${variable.name}`}
- >
- <Trash2 size={14} />
- </Button>
- </div>
- ) : null}
+ return (
+ <DndContext
+ sensors={sensors}
+ modifiers={[restrictToVerticalAxis]}
+ onDragEnd={handleDragEnd}
+ >
+ <SortableContext
+ items={variables.map((v) => v.name)}
+ strategy={verticalListSortingStrategy}
+ >
+ <div className={styles.list} data-testid="variables-list">
+ {variables.map((variable, index) => (
+ <VariableRow
+ key={variable.name || `variable-${index}`}
+ variable={variable}
+ index={index}
+ canEdit={canEdit}
+ isConfirmingDelete={confirmingIndex === index}
+ onEdit={onEdit}
+ onRequestDelete={onRequestDelete}
+ onConfirmDelete={onConfirmDelete}
+ onCancelDelete={onCancelDelete}
+ />
+ ))}
</div>
- ))}
- </div>
+ </SortableContext>
+ </DndContext>
);
}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/AddVariableButton.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/AddVariableButton.tsx
new file mode 100644
index 0000000000..63fcb6f315
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/AddVariableButton.tsx
@@ -0,0 +1,26 @@
+import { Plus } from '@signozhq/icons';
+import { Button } from '@signozhq/ui/button';
+
+const AddVariableButton = ({
+ isEditable,
+ setIsEditing,
+}: {
+ isEditable: boolean;
+ setIsEditing: (state: { type: 'new' }) => void;
+}): JSX.Element => {
+ return (
+ <Button
+ variant="solid"
+ color="primary"
+ prefix={<Plus size={14} />}
+ size="md"
+ onClick={(): void => setIsEditing({ type: 'new' })}
+ testId="add-variable"
+ disabled={!isEditable}
+ >
+ Add variable
+ </Button>
+ );
+};
+
+export default AddVariableButton;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/BackToAllVariables/BackToAllVariables.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/BackToAllVariables/BackToAllVariables.module.scss
new file mode 100644
index 0000000000..ad9eedc5de
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/BackToAllVariables/BackToAllVariables.module.scss
@@ -0,0 +1,11 @@
+.backToAllVariables {
+ gap: 8px;
+ padding: 8px;
+ border-bottom: 1px solid var(--l3-border);
+}
+
+.backToAllVariablesButton {
+ --button-font-size: 14px;
+ --button-padding: var(--spacing-5) var(--spacing-3);
+ color: var(--l1-foreground);
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/BackToAllVariables/BackToAllVariables.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/BackToAllVariables/BackToAllVariables.tsx
new file mode 100644
index 0000000000..59feec7e52
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/BackToAllVariables/BackToAllVariables.tsx
@@ -0,0 +1,28 @@
+import { ArrowLeft } from '@signozhq/icons';
+import { Button } from '@signozhq/ui/button';
+import styles from './BackToAllVariables.module.scss';
+import { VariableFormProps } from '../../types';
+
+const BackToAllVariables = ({
+ onClose,
+}: {
+ onClose: VariableFormProps['onClose'];
+}): JSX.Element => {
+ return (
+ <div className={styles.backToAllVariables}>
+ <Button
+ variant="ghost"
+ color="secondary"
+ className={styles.backToAllVariablesButton}
+ prefix={<ArrowLeft size={14} />}
+ onClick={onClose}
+ testId="variable-form-back"
+ size="md"
+ >
+ All variables
+ </Button>
+ </div>
+ );
+};
+
+export default BackToAllVariables;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/NoVariablesCard/NoVariables.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/NoVariablesCard/NoVariables.module.scss
new file mode 100644
index 0000000000..bd927aada6
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/NoVariablesCard/NoVariables.module.scss
@@ -0,0 +1,25 @@
+.noVariablesCard {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: 16px;
+}
+
+.noVariablesCopy {
+ display: flex;
+ flex-direction: column;
+ gap: 2px;
+}
+
+.noVariablesTitle {
+ color: var(--l1-foreground);
+ font-size: 14px;
+ font-weight: 500;
+ line-height: 20px;
+}
+
+.noVariablesInfo {
+ color: var(--l3-foreground);
+ font-size: 13px;
+ line-height: 18px;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/NoVariablesCard/NoVariablesCard.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/NoVariablesCard/NoVariablesCard.tsx
new file mode 100644
index 0000000000..537ecf9cfe
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/NoVariablesCard/NoVariablesCard.tsx
@@ -0,0 +1,28 @@
+import { Typography } from '@signozhq/ui/typography';
+import AddVariableButton from '../AddVariableButton';
+import { EditingState } from '../../types';
+import styles from './NoVariables.module.scss';
+
+const NoVariablesCard = ({
+ isEditable,
+ setIsEditing,
+}: {
+ isEditable: boolean;
+ setIsEditing: React.Dispatch<React.SetStateAction<EditingState | null>>;
+}): JSX.Element => {
+ return (
+ <div className={styles.noVariablesCard}>
+ <div className={styles.noVariablesCopy}>
+ <Typography.Text className={styles.noVariablesTitle}>
+ No variables yet
+ </Typography.Text>
+ <Typography.Text className={styles.noVariablesInfo}>
+ Create a variable to parameterize your panel queries.
+ </Typography.Text>
+ </div>
+ <AddVariableButton isEditable={isEditable} setIsEditing={setIsEditing} />
+ </div>
+ );
+};
+
+export default NoVariablesCard;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/VariableInfoForm/VariableInfoForm.module.scss b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/VariableInfoForm/VariableInfoForm.module.scss
new file mode 100644
index 0000000000..11a2bbec11
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/VariableInfoForm/VariableInfoForm.module.scss
@@ -0,0 +1,25 @@
+.infoItemContainer {
+ display: flex;
+ flex-direction: column;
+ gap: 4px;
+}
+
+.infoTitle {
+ color: var(--l2-foreground);
+ font-family: Inter;
+ font-size: 12px;
+}
+
+.variableNameInput {
+ border-radius: 2px;
+ border: 1px solid var(--l2-border);
+
+ &::placeholder {
+ color: var(--l3-foreground);
+ }
+}
+
+.descriptionTextArea {
+ border-radius: 2px;
+ border: 1px solid var(--l2-border);
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/VariableInfoForm/VariableInfoForm.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/VariableInfoForm/VariableInfoForm.tsx
new file mode 100644
index 0000000000..bc206f1e95
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/components/VariableInfoForm/VariableInfoForm.tsx
@@ -0,0 +1,60 @@
+import { Input } from '@signozhq/ui/input';
+import { Typography } from '@signozhq/ui/typography';
+// eslint-disable-next-line signoz/no-antd-components -- multiline TextArea has no @signozhq/ui equivalent yet
+import { Input as AntdInput } from 'antd';
+
+import styles from './VariableInfoForm.module.scss';
+import variableFormStyles from '../../VariableForm/VariableForm.module.scss';
+
+interface VariableInfoFormProps {
+ title: string;
+ description: string;
+ onTitleChange: (value: string) => void;
+ onDescriptionChange: (value: string) => void;
+ visibleNameError: string | null;
+}
+
+function VariableInfoForm({
+ title,
+ description,
+ onTitleChange,
+ onDescriptionChange,
+ visibleNameError,
+}: VariableInfoFormProps): JSX.Element {
+ return (
+ <>
+ <div className={styles.infoItemContainer}>
+ <Typography className={styles.infoTitle}>Name</Typography>
+
+ <Input
+ testId="variable-name"
+ className={styles.variableNameInput}
+ value={title}
+ onChange={(e): void => onTitleChange(e.target.value)}
+ placeholder="Unique name of the variable"
+ />
+
+ {visibleNameError ? (
+ <Typography.Text className={variableFormStyles.errorText}>
+ <sup>*</sup>&nbsp;
+ {visibleNameError}
+ </Typography.Text>
+ ) : null}
+ </div>
+
+ <div className={styles.infoItemContainer}>
+ <Typography className={styles.infoTitle}>Description</Typography>
+ <AntdInput.TextArea
+ className={styles.descriptionTextArea}
+ value={description}
+ placeholder="Enter a description for the variable"
+ data-testid="dashboard-desc"
+ rows={3}
+ onChange={(e): void => onDescriptionChange(e.target.value)}
+ />
+ </div>
+ </>
+ );
+}
+
+export default VariableInfoForm;
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/index.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/index.tsx
index 93a57e286d..98f7dc7a39 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/index.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/index.tsx
@@ -1,75 +1,75 @@
import { useEffect, useMemo, useState } from 'react';
-import { Plus } from '@signozhq/icons';
-import { Button } from '@signozhq/ui/button';
-import { Typography } from '@signozhq/ui/typography';
import type { DashboardtypesGettableDashboardV2DTO } from 'api/generated/services/sigNoz.schemas';
+import cx from 'classnames';
+import settingsStyles from '../DashboardSettings.module.scss';
import { useDashboardStore } from '../../store/useDashboardStore';
import { useSaveVariables } from './useSaveVariables';
import { dtoToFormModel } from './variableAdapters';
import {
emptyVariableFormModel,
type VariableFormModel,
-} from './variableModel';
+} from './variableFormModel';
import VariableForm from './VariableForm/VariableForm';
import VariablesList from './VariablesList';
import styles from './Variables.module.scss';
+import AddVariableButton from './components/AddVariableButton';
+import NoVariablesCard from './components/NoVariablesCard/NoVariablesCard';
+import { EditingState } from './types';
interface VariablesSettingsProps {
dashboard: DashboardtypesGettableDashboardV2DTO;
}
-/** `null` index = adding a new variable; a number = editing that row. */
-type EditingState = { index: number | null } | null;
-
function VariablesSettings({ dashboard }: VariablesSettingsProps): JSX.Element {
const isEditable = useDashboardStore((s) => s.isEditable);
const { save, isSaving } = useSaveVariables();
- const initialModels = useMemo(
- () => (dashboard.spec?.variables ?? []).map(dtoToFormModel),
- [dashboard.spec?.variables],
+ const initialFormModels = useMemo(
+ () => dashboard.spec.variables.map(dtoToFormModel),
+ [dashboard.spec.variables],
);
- const [variables, setVariables] = useState<VariableFormModel[]>(initialModels);
+ const [variables, setVariables] =
+ useState<VariableFormModel[]>(initialFormModels);
// Resync from the dashboard after a save round-trips (refetch bumps updatedAt).
useEffect(() => {
- setVariables(initialModels);
+ setVariables(initialFormModels);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [dashboard.updatedAt]);
- const [editing, setEditing] = useState<EditingState>(null);
+ const [isEditing, setIsEditing] = useState<EditingState>(null);
const [confirmDeleteIndex, setConfirmDeleteIndex] = useState<number | null>(
null,
);
- const editingModel: VariableFormModel | null = useMemo(() => {
- if (!editing) {
+ const editingFormModel: VariableFormModel | null = useMemo(() => {
+ if (!isEditing) {
return null;
}
- return editing.index === null
+ return isEditing.type === 'new'
? emptyVariableFormModel()
- : variables[editing.index];
- }, [editing, variables]);
+ : variables[isEditing.index];
+ }, [isEditing, variables]);
- const existingNames = useMemo(() => {
- const self = editing?.index ?? null;
- return variables.filter((_, i) => i !== self).map((v) => v.name);
- }, [variables, editing]);
+ const siblings = useMemo(() => {
+ const self = isEditing?.type === 'edit' ? isEditing.index : null;
+ return variables.filter((_, i) => i !== self);
+ }, [variables, isEditing]);
const persist = (next: VariableFormModel[]): void => {
setVariables(next);
void save(next);
};
- const handleFormSave = (model: VariableFormModel): void => {
+ const handleFormSave = (Formmodel: VariableFormModel): void => {
const next = [...variables];
- if (editing?.index == null) {
- next.push(model);
- } else {
- next[editing.index] = model;
+ if (isEditing?.type === 'new') {
+ next.push(Formmodel);
+ } else if (isEditing?.type === 'edit') {
+ next[isEditing.index] = Formmodel;
}
- setEditing(null);
+ setIsEditing(null);
persist(next);
};
@@ -88,14 +88,14 @@ function VariablesSettings({ dashboard }: VariablesSettingsProps): JSX.Element {
setConfirmDeleteIndex(null);
};
- // Detail view — edit/new form replaces the list in place (no modal).
- if (editingModel) {
+ if (editingFormModel) {
return (
<VariableForm
- initial={editingModel}
- existingNames={existingNames}
+ initial={editingFormModel}
+ siblings={siblings}
+ isNew={isEditing?.type === 'new'}
isSaving={isSaving}
- onClose={(): void => setEditing(null)}
+ onClose={(): void => setIsEditing(null)}
onSave={handleFormSave}
/>
);
@@ -103,42 +103,25 @@ function VariablesSettings({ dashboard }: VariablesSettingsProps): JSX.Element {
// Master view — the variables list.
return (
- <div className={styles.container}>
- <div className={styles.header}>
- <div className={styles.titleRow}>
- <Typography.Text className={styles.title}>Variables</Typography.Text>
- <Typography.Text className={styles.subtitle}>
- Define variables to parameterize panel queries.
- </Typography.Text>
- </div>
- {isEditable ? (
- <Button
- variant="solid"
- color="primary"
- prefix={<Plus size={14} />}
- onClick={(): void => setEditing({ index: null })}
- testId="add-variable"
- >
- New variable
- </Button>
- ) : null}
- </div>
-
+ <div className={cx(styles.container, settingsStyles.settingsCard)}>
{variables.length === 0 ? (
- <div className={styles.empty}>
- <Typography.Text>No variables defined yet.</Typography.Text>
- </div>
+ <NoVariablesCard isEditable={isEditable} setIsEditing={setIsEditing} />
) : (
- <VariablesList
- variables={variables}
- canEdit={isEditable}
- confirmingIndex={confirmDeleteIndex}
- onEdit={(index): void => setEditing({ index })}
- onRequestDelete={(index): void => setConfirmDeleteIndex(index)}
- onConfirmDelete={handleConfirmDelete}
- onCancelDelete={(): void => setConfirmDeleteIndex(null)}
- onMove={handleMove}
- />
+ <>
+ <div className={styles.header}>
+ <AddVariableButton isEditable={isEditable} setIsEditing={setIsEditing} />
+ </div>
+ <VariablesList
+ variables={variables}
+ canEdit={isEditable}
+ confirmingIndex={confirmDeleteIndex}
+ onEdit={(index): void => setIsEditing({ type: 'edit', index })}
+ onRequestDelete={(index): void => setConfirmDeleteIndex(index)}
+ onConfirmDelete={handleConfirmDelete}
+ onCancelDelete={(): void => setConfirmDeleteIndex(null)}
+ onMove={handleMove}
+ />
+ </>
)}
</div>
);
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/types.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/types.ts
new file mode 100644
index 0000000000..c68ea0f5db
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/types.ts
@@ -0,0 +1,18 @@
+import { VariableFormModel } from './variableFormModel';
+
+/** `null` index = adding a new variable; a number = editing that row. */
+export type EditingState =
+ | { type: 'new' }
+ | { type: 'edit'; index: number }
+ | null;
+
+export interface VariableFormProps {
+ initial: VariableFormModel;
+ /** The other variables (excluding this one), for uniqueness & cycle checks. */
+ siblings: VariableFormModel[];
+ /** True when adding a new variable (enables auto-naming from the attribute). */
+ isNew: boolean;
+ isSaving: boolean;
+ onClose: () => void;
+ onSave: (model: VariableFormModel) => void;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/useSaveVariables.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/useSaveVariables.ts
index 23773acf5e..4ae2ad67ae 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/useSaveVariables.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/useSaveVariables.ts
@@ -6,7 +6,7 @@ import APIError from 'types/api/error';
import { useDashboardStore } from '../../store/useDashboardStore';
import { formModelToDto } from './variableAdapters';
-import type { VariableFormModel } from './variableModel';
+import type { VariableFormModel } from './variableFormModel';
import { buildVariablesPatch } from './variablePatchOps';
interface UseSaveVariables {
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableAdapters.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableAdapters.ts
index b0216f2422..bbf8e62c4f 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableAdapters.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableAdapters.ts
@@ -4,7 +4,6 @@ import {
DashboardtypesVariablePluginVariantGithubComSigNozSignozPkgTypesDashboardtypesCustomVariableSpecDTOKind as CustomPluginKind,
DashboardtypesVariablePluginVariantGithubComSigNozSignozPkgTypesDashboardtypesDynamicVariableSpecDTOKind as DynamicPluginKind,
DashboardtypesVariablePluginVariantGithubComSigNozSignozPkgTypesDashboardtypesQueryVariableSpecDTOKind as QueryPluginKind,
- TelemetrytypesSignalDTO,
} from 'api/generated/services/sigNoz.schemas';
import type {
DashboardtypesListVariableSpecDTO,
@@ -14,21 +13,24 @@ import type {
} from 'api/generated/services/sigNoz.schemas';
import {
+ DYNAMIC_SIGNAL_ALL,
+ type DynamicSignalOption,
emptyVariableFormModel,
- PLUGIN_KIND,
- type TelemetrySignal,
+ signalForApi,
+ VARIABLE_SORT_DISABLED,
type VariableFormModel,
type VariableSort,
-} from './variableModel';
+} from './variableFormModel';
/** DTO envelope → flat form model (for display / editing). */
export function dtoToFormModel(
dto: DashboardtypesVariableDTO,
): VariableFormModel {
const base = emptyVariableFormModel();
- const display = dto.spec?.display;
+ const display = dto.spec.display;
const common: VariableFormModel = {
...base,
+ // TODO
name: dto.spec?.name ?? display?.name ?? '',
description: display?.description ?? '',
};
@@ -50,7 +52,7 @@ export function dtoToFormModel(
...common,
multiSelect: spec.allowMultiple ?? false,
showAllOption: spec.allowAllValue ?? false,
- sort: (spec.sort as VariableSort) ?? 'DISABLED',
+ sort: (spec.sort as VariableSort) ?? VARIABLE_SORT_DISABLED,
defaultValue: spec.defaultValue,
};
const plugin = spec.plugin;
@@ -67,7 +69,9 @@ export function dtoToFormModel(
...listCommon,
type: 'DYNAMIC',
dynamicAttribute: plugin.spec.name ?? '',
- dynamicSignal: (plugin.spec.signal as TelemetrySignal) ?? 'traces',
+ // An omitted wire signal means "all telemetry".
+ dynamicSignal:
+ (plugin.spec.signal as DynamicSignalOption) ?? DYNAMIC_SIGNAL_ALL,
};
}
// Default to Query (also covers a query plugin or a missing/unknown plugin).
@@ -95,7 +99,7 @@ function buildPlugin(
kind: DynamicPluginKind['signoz/DynamicVariable'],
spec: {
name: model.dynamicAttribute,
- signal: model.dynamicSignal as TelemetrytypesSignalDTO,
+ signal: signalForApi(model.dynamicSignal),
},
};
case 'QUERY':
@@ -114,7 +118,6 @@ export function formModelToDto(
const display = {
name: model.name,
description: model.description,
- hidden: model.hidden,
};
if (model.type === 'TEXT') {
@@ -135,7 +138,10 @@ export function formModelToDto(
name: model.name,
display,
allowMultiple: model.multiSelect,
- allowAllValue: model.showAllOption,
+ // Dynamic variables always expose the aggregate "ALL" entry (matches V1,
+ // which forced showALLOption true on save); other types respect the toggle.
+ allowAllValue: model.type === 'DYNAMIC' ? true : model.showAllOption,
+ // model.sort is already a Perses sort token (`none` / `alphabetical-*`).
sort: model.sort,
defaultValue: model.defaultValue,
plugin: buildPlugin(model),
@@ -149,5 +155,3 @@ export function variableTypeOf(
): VariableFormModel['type'] {
return dtoToFormModel(dto).type;
}
-
-export { PLUGIN_KIND };
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableDependencies.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableDependencies.ts
new file mode 100644
index 0000000000..4ba52c5046
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableDependencies.ts
@@ -0,0 +1,35 @@
+import {
+ buildDependencies,
+ buildDependencyGraph,
+} from 'container/DashboardContainer/DashboardVariablesSelection/util';
+import type { IDashboardVariable } from 'types/api/dashboard/getAll';
+
+import type { VariableFormModel } from './variableFormModel';
+
+/**
+ * Detects a circular reference among QUERY variables (a query referencing
+ * another that, transitively, references it back). Reuses the V1 dependency
+ * graph helpers, which key off `name` / `type` / `queryValue` only.
+ *
+ * Returns the names forming the cycle, or `null` when the set is acyclic.
+ */
+export function detectVariableCycle(
+ variables: VariableFormModel[],
+): string[] | null {
+ const asDbVariables = variables
+ .filter((variable) => variable.name)
+ .map(
+ (variable) =>
+ ({
+ name: variable.name,
+ type: variable.type,
+ queryValue: variable.queryValue,
+ }) as IDashboardVariable,
+ );
+
+ const { hasCycle, cycleNodes } = buildDependencyGraph(
+ buildDependencies(asDbVariables),
+ );
+
+ return hasCycle ? (cycleNodes ?? []) : null;
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableFormModel.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableFormModel.ts
new file mode 100644
index 0000000000..3af702ae68
--- /dev/null
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableFormModel.ts
@@ -0,0 +1,154 @@
+import { TelemetrytypesSignalDTO } from 'api/generated/services/sigNoz.schemas';
+import type { VariableDefaultValueDTO } from 'api/generated/services/sigNoz.schemas';
+import { sortBy } from 'lodash-es';
+
+/**
+ * The four variable types the editor exposes. No generated enum exists for this
+ * — it's a UI grouping over the wire's envelope + plugin kinds: the TextVariable
+ * envelope → `TEXT`, and a ListVariable's `DashboardtypesVariablePluginKindDTO`
+ * (`signoz/QueryVariable` | `signoz/CustomVariable` | `signoz/DynamicVariable`)
+ * → `QUERY` | `CUSTOM` | `DYNAMIC`. Replace with a generated enum if the backend
+ * ever exposes a single variable-kind type.
+ */
+export type VariableType = 'QUERY' | 'CUSTOM' | 'TEXT' | 'DYNAMIC';
+
+/** Telemetry signal — the generated enum (traces / logs / metrics). */
+export type TelemetrySignal = TelemetrytypesSignalDTO;
+
+/**
+ * Signal selected in the dynamic-variable editor. `'all'` is UI-only (the
+ * generated `TelemetrytypesSignalDTO` has no "all") — it searches across every
+ * signal and maps to an omitted `signal` on the wire (see {@link signalForApi}).
+ */
+export const DYNAMIC_SIGNAL_ALL = 'all' as const;
+export type DynamicSignalOption = TelemetrySignal | typeof DYNAMIC_SIGNAL_ALL;
+
+/**
+ * Sort order for list-variable values. The wire (Perses) validates `sort`
+ * against a fixed method set. There is no generated TS enum for it
+ * (`DashboardtypesListOrderDTO` is the query-builder order, a different field),
+ * so we mirror the Perses `Sort` tokens here.
+ */
+export const VARIABLE_SORT = {
+ DISABLED: 'none',
+ ASC: 'alphabetical-asc',
+ DESC: 'alphabetical-desc',
+ NUMERICAL_ASC: 'numerical-asc',
+ NUMERICAL_DESC: 'numerical-desc',
+ CI_ASC: 'alphabetical-ci-asc',
+ CI_DESC: 'alphabetical-ci-desc',
+} as const;
+
+export type VariableSort = (typeof VARIABLE_SORT)[keyof typeof VARIABLE_SORT];
+
+/** Persisted "no sort" value (Perses `none`). */
+export const VARIABLE_SORT_DISABLED: VariableSort = VARIABLE_SORT.DISABLED;
+
+export const VARIABLE_SORTS: VariableSort[] = [
+ VARIABLE_SORT.DISABLED,
+ VARIABLE_SORT.ASC,
+ VARIABLE_SORT.DESC,
+ VARIABLE_SORT.NUMERICAL_ASC,
+ VARIABLE_SORT.NUMERICAL_DESC,
+ VARIABLE_SORT.CI_ASC,
+ VARIABLE_SORT.CI_DESC,
+];
+
+export const VARIABLE_SORT_LABEL: Record<VariableSort, string> = {
+ [VARIABLE_SORT.DISABLED]: 'Disabled',
+ [VARIABLE_SORT.ASC]: 'Alphabetical (ascending)',
+ [VARIABLE_SORT.DESC]: 'Alphabetical (descending)',
+ [VARIABLE_SORT.NUMERICAL_ASC]: 'Numerical (ascending)',
+ [VARIABLE_SORT.NUMERICAL_DESC]: 'Numerical (descending)',
+ [VARIABLE_SORT.CI_ASC]: 'Alphabetical, case-insensitive (ascending)',
+ [VARIABLE_SORT.CI_DESC]: 'Alphabetical, case-insensitive (descending)',
+};
+
+export const DYNAMIC_SIGNALS: DynamicSignalOption[] = [
+ DYNAMIC_SIGNAL_ALL,
+ TelemetrytypesSignalDTO.traces,
+ TelemetrytypesSignalDTO.logs,
+ TelemetrytypesSignalDTO.metrics,
+];
+
+export const DYNAMIC_SIGNAL_LABEL: Record<DynamicSignalOption, string> = {
+ [DYNAMIC_SIGNAL_ALL]: 'All telemetry',
+ [TelemetrytypesSignalDTO.traces]: 'Traces',
+ [TelemetrytypesSignalDTO.logs]: 'Logs',
+ [TelemetrytypesSignalDTO.metrics]: 'Metrics',
+};
+
+/** Maps the editor's signal selection to the wire value (`'all'` → omitted). */
+export function signalForApi(
+ signal: DynamicSignalOption,
+): TelemetrySignal | undefined {
+ return signal === DYNAMIC_SIGNAL_ALL ? undefined : signal;
+}
+
+type SortableValues = (string | number | boolean)[];
+
+/** Sorts preview / option values by the variable's chosen order (no-op when disabled). */
+export function sortValuesByOrder(
+ values: SortableValues,
+ sort: VariableSort,
+): SortableValues {
+ switch (sort) {
+ case VARIABLE_SORT.ASC:
+ return sortBy(values);
+ case VARIABLE_SORT.DESC:
+ return sortBy(values).reverse();
+ case VARIABLE_SORT.NUMERICAL_ASC:
+ return sortBy(values, (value) => Number(value));
+ case VARIABLE_SORT.NUMERICAL_DESC:
+ return sortBy(values, (value) => Number(value)).reverse();
+ case VARIABLE_SORT.CI_ASC:
+ return sortBy(values, (value) => String(value).toLowerCase());
+ case VARIABLE_SORT.CI_DESC:
+ return sortBy(values, (value) => String(value).toLowerCase()).reverse();
+ default:
+ return values;
+ }
+}
+
+export interface VariableFormModel {
+ /** Stable identifier, referenced in queries (e.g. `$name`); must be unique. */
+ name: string;
+ description: string;
+ type: VariableType;
+
+ // List-variable common fields (Query / Custom / Dynamic).
+ multiSelect: boolean;
+ showAllOption: boolean;
+ sort: VariableSort;
+
+ // Type-specific.
+ queryValue: string; // QUERY
+ customValue: string; // CUSTOM
+ textValue: string; // TEXT
+ textConstant: boolean; // TEXT
+ dynamicAttribute: string; // DYNAMIC — the telemetry field name
+ dynamicSignal: DynamicSignalOption; // DYNAMIC — the telemetry signal
+
+ /**
+ * Runtime-selected default, not editable in the management tab yet; carried
+ * through edits so saving a definition doesn't clobber it.
+ */
+ defaultValue?: VariableDefaultValueDTO;
+}
+
+export function emptyVariableFormModel(): VariableFormModel {
+ return {
+ name: '',
+ description: '',
+ type: 'DYNAMIC',
+ multiSelect: false,
+ showAllOption: false,
+ sort: VARIABLE_SORT_DISABLED,
+ queryValue: '',
+ customValue: '',
+ textValue: '',
+ textConstant: false,
+ dynamicAttribute: '',
+ dynamicSignal: DYNAMIC_SIGNAL_ALL,
+ };
+}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableModel.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableModel.ts
deleted file mode 100644
index 13eb935562..0000000000
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/DashboardSettings/Variables/variableModel.ts
+++ /dev/null
@@ -1,102 +0,0 @@
-import { sortBy } from 'lodash-es';
-import type { VariableDefaultValueDTO } from 'api/generated/services/sigNoz.schemas';
-
-/**
- * Flat, UI-friendly representation of a V2 dashboard variable. The wire format
- * (`DashboardtypesVariableDTO`) is a nested envelope/plugin union that is awkward
- * to bind a form to; `variableAdapters` converts between this model and the DTO.
- */
-
-export type VariableType = 'QUERY' | 'CUSTOM' | 'TEXT' | 'DYNAMIC';
-
-export type VariableSort = 'DISABLED' | 'ASC' | 'DESC';
-
-export type TelemetrySignal = 'traces' | 'logs' | 'metrics';
-
-/** Wire `kind` discriminators (string values of the generated enums). */
-export const ENVELOPE_KIND = {
- LIST: 'ListVariable',
- TEXT: 'TextVariable',
-} as const;
-
-export const PLUGIN_KIND = {
- QUERY: 'signoz/QueryVariable',
- CUSTOM: 'signoz/CustomVariable',
- DYNAMIC: 'signoz/DynamicVariable',
-} as const;
-
-export const VARIABLE_SORTS: VariableSort[] = ['DISABLED', 'ASC', 'DESC'];
-
-export const TELEMETRY_SIGNALS: TelemetrySignal[] = [
- 'traces',
- 'logs',
- 'metrics',
-];
-
-export interface VariableFormModel {
- /** Stable identifier, referenced in queries (e.g. `$name`); must be unique. */
- name: string;
- description: string;
- hidden: boolean;
- type: VariableType;
-
- // List-variable common fields (Query / Custom / Dynamic).
- multiSelect: boolean;
- showAllOption: boolean;
- sort: VariableSort;
-
- // Type-specific.
- queryValue: string; // QUERY
- customValue: string; // CUSTOM
- textValue: string; // TEXT
- textConstant: boolean; // TEXT
- dynamicAttribute: string; // DYNAMIC — the telemetry field name
- dynamicSignal: TelemetrySignal; // DYNAMIC — the telemetry signal
-
- /**
- * Runtime-selected default, not editable in the management tab yet; carried
- * through edits so saving a definition doesn't clobber it.
- */
- defaultValue?: VariableDefaultValueDTO;
-}
-
-export function emptyVariableFormModel(): VariableFormModel {
- return {
- name: '',
- description: '',
- hidden: false,
- type: 'QUERY',
- multiSelect: false,
- showAllOption: false,
- sort: 'DISABLED',
- queryValue: '',
- customValue: '',
- textValue: '',
- textConstant: false,
- dynamicAttribute: '',
- dynamicSignal: 'traces',
- };
-}
-
-/** Maps the dynamic-variable signal to the field-values API signal. */
-export function signalForApi(
- signal: TelemetrySignal,
-): TelemetrySignal | undefined {
- return signal;
-}
-
-type SortableValues = (string | number | boolean)[];
-
-/** Sorts option/preview values by the variable's chosen order (no-op when disabled). */
-export function sortValuesByOrder(
- values: SortableValues,
- sort: VariableSort,
-): SortableValues {
- if (sort === 'ASC') {
- return sortBy(values);
- }
- if (sort === 'DESC') {
- return sortBy(values).reverse();
- }
- return values;
-}
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/VariableSelector.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/VariableSelector.tsx
index da7190eb58..259fa20610 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/VariableSelector.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/VariableSelector.tsx
@@ -5,8 +5,8 @@ import { Typography } from '@signozhq/ui/typography';
import { Tooltip } from 'antd';
import { commaValuesParser } from 'lib/dashboardVariables/customCommaValuesParser';
-import { sortValuesByOrder } from '../DashboardSettings/Variables/variableModel';
-import type { VariableFormModel } from '../DashboardSettings/Variables/variableModel';
+import { sortValuesByOrder } from '../DashboardSettings/Variables/variableFormModel';
+import type { VariableFormModel } from '../DashboardSettings/Variables/variableFormModel';
import type { VariableSelection, VariableSelectionMap } from './selectionTypes';
import DynamicSelector from './selectors/DynamicSelector';
import QuerySelector from './selectors/QuerySelector';
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/dynamicFilter.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/dynamicFilter.ts
index 09559dcc16..f7c7bc873d 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/dynamicFilter.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/dynamicFilter.ts
@@ -1,4 +1,4 @@
-import type { VariableFormModel } from '../DashboardSettings/Variables/variableModel';
+import type { VariableFormModel } from '../DashboardSettings/Variables/variableFormModel';
import type { VariableSelectionMap } from './selectionTypes';
function formatQueryValue(val: string): string {
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/DynamicSelector.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/DynamicSelector.tsx
index 3c3ed13d32..9f47ac029a 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/DynamicSelector.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/DynamicSelector.tsx
@@ -8,8 +8,8 @@ import type { GlobalReducer } from 'types/reducer/globalTime';
import {
signalForApi,
sortValuesByOrder,
-} from '../../DashboardSettings/Variables/variableModel';
-import type { VariableFormModel } from '../../DashboardSettings/Variables/variableModel';
+} from '../../DashboardSettings/Variables/variableFormModel';
+import type { VariableFormModel } from '../../DashboardSettings/Variables/variableFormModel';
import { buildExistingDynamicVariableQuery } from '../dynamicFilter';
import type {
VariableSelection,
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/QuerySelector.tsx b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/QuerySelector.tsx
index a499de78cc..e44bb66ac1 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/QuerySelector.tsx
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/selectors/QuerySelector.tsx
@@ -6,8 +6,8 @@ import dashboardVariablesQuery from 'api/dashboard/variables/dashboardVariablesQ
import type { AppState } from 'store/reducers';
import type { GlobalReducer } from 'types/reducer/globalTime';
-import { sortValuesByOrder } from '../../DashboardSettings/Variables/variableModel';
-import type { VariableFormModel } from '../../DashboardSettings/Variables/variableModel';
+import { sortValuesByOrder } from '../../DashboardSettings/Variables/variableFormModel';
+import type { VariableFormModel } from '../../DashboardSettings/Variables/variableFormModel';
import type {
VariableSelection,
VariableSelectionMap,
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useAutoSelect.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useAutoSelect.ts
index deea33b9cc..f1e152d52a 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useAutoSelect.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useAutoSelect.ts
@@ -1,6 +1,6 @@
import { useEffect } from 'react';
-import type { VariableFormModel } from '../DashboardSettings/Variables/variableModel';
+import type { VariableFormModel } from '../DashboardSettings/Variables/variableFormModel';
import type { VariableSelection } from './selectionTypes';
/**
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useVariableSelection.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useVariableSelection.ts
index 77cd4b67ea..75cfa95d57 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useVariableSelection.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/useVariableSelection.ts
@@ -3,7 +3,7 @@ import { parseAsJson, useQueryState } from 'nuqs';
import type { DashboardtypesGettableDashboardV2DTO } from 'api/generated/services/sigNoz.schemas';
import { dtoToFormModel } from '../DashboardSettings/Variables/variableAdapters';
-import type { VariableFormModel } from '../DashboardSettings/Variables/variableModel';
+import type { VariableFormModel } from '../DashboardSettings/Variables/variableFormModel';
import { selectVariableValues } from '../store/slices/variableSelectionSlice';
import { useDashboardStore } from '../store/useDashboardStore';
import type {
diff --git a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/variableDependencies.ts b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/variableDependencies.ts
index 88f99cc67a..94faf986fa 100644
--- a/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/variableDependencies.ts
+++ b/frontend/src/pages/DashboardPageV2/DashboardContainer/VariablesBar/variableDependencies.ts
@@ -1,6 +1,6 @@
import { textContainsVariableReference } from 'lib/dashboardVariables/variableReference';
-import type { VariableFormModel } from '../DashboardSettings/Variables/variableModel';
+import type { VariableFormModel } from '../DashboardSettings/Variables/variableFormModel';
/**
* Inter-variable dependency graph for runtime selection. A QUERY variable