mirror of
https://github.com/SigNoz/signoz.git
synced 2026-07-27 16:30:34 +01:00
Compare commits
11 Commits
email-aler
...
nv/migrati
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa591dff26 | ||
|
|
5d41c5c016 | ||
|
|
6dcc9f191d | ||
|
|
52df42511b | ||
|
|
08715a704a | ||
|
|
41c66f2634 | ||
|
|
503afb13d4 | ||
|
|
774dfc48ae | ||
|
|
d013eab29d | ||
|
|
27f47f3ebc | ||
|
|
18f5baafa0 |
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
"github.com/SigNoz/signoz/pkg/factory"
|
||||
"github.com/SigNoz/signoz/pkg/instrumentation"
|
||||
"github.com/SigNoz/signoz/pkg/modules/dashboard/impldashboard"
|
||||
"github.com/SigNoz/signoz/pkg/modules/tag/impltag"
|
||||
"github.com/SigNoz/signoz/pkg/signoz"
|
||||
"github.com/SigNoz/signoz/pkg/sqlmigration"
|
||||
"github.com/SigNoz/signoz/pkg/sqlmigrator"
|
||||
@@ -145,7 +147,7 @@ func newSyncMigrator(ctx context.Context, config signoz.Config, sqlstoreProvider
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sqlmigrations, err := sqlmigration.New(ctx, providerSettings, config.SQLMigration, signoz.NewSQLMigrationProviderFactories(sqlstore, sqlschema, telemetrystore, providerSettings))
|
||||
sqlmigrations, err := sqlmigration.New(ctx, providerSettings, config.SQLMigration, signoz.NewSQLMigrationProviderFactories(sqlstore, sqlschema, telemetrystore, providerSettings, impldashboard.NewStore(sqlstore), impltag.NewModule(impltag.NewStore(sqlstore))))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -7238,6 +7238,10 @@ components:
|
||||
$ref: '#/components/schemas/RuletypesAlertState'
|
||||
overallStateChanged:
|
||||
type: boolean
|
||||
relatedLogsLink:
|
||||
type: string
|
||||
relatedTracesLink:
|
||||
type: string
|
||||
ruleId:
|
||||
type: string
|
||||
ruleName:
|
||||
|
||||
@@ -551,12 +551,12 @@ func (module *module) provisionDashboards(ctx context.Context, orgID valuer.UUID
|
||||
continue
|
||||
}
|
||||
|
||||
createdDashboard, err := module.dashboardModule.Create(ctx, orgID, createdBy, creator, dashboardtypes.SourceIntegration, dashboardtypes.PostableDashboard(dashboard.Definition))
|
||||
createdDashboard, err := module.dashboardModule.CreateV2(ctx, orgID, createdBy, creator, dashboardtypes.SourceIntegration, dashboard.Definition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
integrationDashboard := cloudintegrationtypes.NewStorableIntegrationDashboard(createdDashboard.ID, cloudintegrationtypes.IntegrationDashboardProviderCloudIntegration, slug)
|
||||
integrationDashboard := cloudintegrationtypes.NewStorableIntegrationDashboard(createdDashboard.ID.StringValue(), cloudintegrationtypes.IntegrationDashboardProviderCloudIntegration, slug)
|
||||
if err := module.store.CreateIntegrationDashboard(ctx, integrationDashboard); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -89,15 +89,6 @@ func (ah *APIHandler) getFeatureFlags(w http.ResponseWriter, r *http.Request) {
|
||||
Route: "",
|
||||
})
|
||||
|
||||
useDashboardV2 := ah.Signoz.Flagger.BooleanOrEmpty(ctx, flagger.FeatureUseDashboardV2, evalCtx)
|
||||
featureSet = append(featureSet, &licensetypes.Feature{
|
||||
Name: valuer.NewString(flagger.FeatureUseDashboardV2.String()),
|
||||
Active: useDashboardV2,
|
||||
Usage: 0,
|
||||
UsageLimit: -1,
|
||||
Route: "",
|
||||
})
|
||||
|
||||
aiObservability := ah.Signoz.Flagger.BooleanOrEmpty(ctx, flagger.FeatureEnableAIObservability, evalCtx)
|
||||
featureSet = append(featureSet, &licensetypes.Feature{
|
||||
Name: valuer.NewString(flagger.FeatureEnableAIObservability.String()),
|
||||
|
||||
@@ -8320,6 +8320,14 @@ export interface RulestatehistorytypesGettableRuleStateHistoryDTO {
|
||||
* @type boolean
|
||||
*/
|
||||
overallStateChanged: boolean;
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
relatedLogsLink?: string;
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
relatedTracesLink?: string;
|
||||
/**
|
||||
* @type string
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,10 @@ import {
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
import { DataSource, ReduceOperators } from 'types/common/queryBuilder';
|
||||
|
||||
import { prepareQueryRangePayloadV5 } from './prepareQueryRangePayloadV5';
|
||||
import {
|
||||
convertBuilderQueriesToV5,
|
||||
prepareQueryRangePayloadV5,
|
||||
} from './prepareQueryRangePayloadV5';
|
||||
|
||||
jest.mock('lib/getStartEndRangeTime', () => ({
|
||||
__esModule: true,
|
||||
@@ -899,3 +902,36 @@ describe('prepareQueryRangePayloadV5', () => {
|
||||
expect(logSpec.filter).toStrictEqual({ expression: '' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('convertBuilderQueriesToV5 having normalization', () => {
|
||||
const buildSpec = (having: unknown): MetricBuilderQuery => {
|
||||
const [envelope] = convertBuilderQueriesToV5(
|
||||
{
|
||||
A: {
|
||||
dataSource: DataSource.METRICS,
|
||||
queryName: 'A',
|
||||
aggregations: [{ metricName: 'm', spaceAggregation: 'p99' }],
|
||||
having,
|
||||
} as unknown as IBuilderQuery,
|
||||
},
|
||||
'time_series',
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
);
|
||||
return envelope.spec as MetricBuilderQuery;
|
||||
};
|
||||
|
||||
it.each([
|
||||
['a legacy V4 array', []],
|
||||
['a blank empty-object having', { expression: '' }],
|
||||
['a whitespace-only having', { expression: ' ' }],
|
||||
['a nullish having', undefined],
|
||||
])('drops %s (serializes to undefined)', (_label, having) => {
|
||||
expect(buildSpec(having).having).toBeUndefined();
|
||||
});
|
||||
|
||||
it('preserves a real having expression', () => {
|
||||
expect(buildSpec({ expression: 'count() > 5' }).having).toStrictEqual({
|
||||
expression: 'count() > 5',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -134,6 +134,21 @@ function getFilter(queryData: IBuilderQuery): Filter {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a builder query's `having` to the V5 shape, treating "no having filter" as absent.
|
||||
* V4 stored it as an array; V5 expects `{ expression }`. An array (legacy), a nullish value, or a
|
||||
* blank expression — the query builder seeds `{ expression: '' }` for an empty having — all mean
|
||||
* "no having" and must serialize to `undefined`. Emitting an empty `{ expression: '' }` sends a
|
||||
* no-op filter and, because a saved panel never carries one, reads an untouched panel as dirty.
|
||||
*/
|
||||
function normalizeHaving(having: unknown): Having | undefined {
|
||||
if (having == null || Array.isArray(having)) {
|
||||
return undefined;
|
||||
}
|
||||
const { expression } = having as Having;
|
||||
return expression?.trim() ? (having as Having) : undefined;
|
||||
}
|
||||
|
||||
function createBaseSpec(
|
||||
queryData: IBuilderQuery,
|
||||
requestType: RequestType,
|
||||
@@ -181,12 +196,7 @@ function createBaseSpec(
|
||||
)
|
||||
: undefined,
|
||||
legend: isEmpty(queryData.legend) ? undefined : queryData.legend,
|
||||
// V4 uses having as array, V5 uses having as object with expression field
|
||||
// If having is an array (V4 format), treat it as undefined for V5
|
||||
having:
|
||||
isEmpty(queryData.having) || Array.isArray(queryData.having)
|
||||
? undefined
|
||||
: (queryData?.having as Having),
|
||||
having: normalizeHaving(queryData.having),
|
||||
functions: isEmpty(queryData.functions)
|
||||
? undefined
|
||||
: queryData.functions.map((func: QueryFunction): QueryFunction => {
|
||||
@@ -414,10 +424,7 @@ function createTraceOperatorBaseSpec(
|
||||
)
|
||||
: undefined,
|
||||
legend: isEmpty(legend) ? undefined : legend,
|
||||
// V4 uses having as array, V5 uses having as object with expression field
|
||||
// If having is an array (V4 format), treat it as undefined for V5
|
||||
having:
|
||||
isEmpty(having) || Array.isArray(having) ? undefined : (having as Having),
|
||||
having: normalizeHaving(having),
|
||||
selectFields: isEmpty(nonEmptySelectColumns)
|
||||
? undefined
|
||||
: nonEmptySelectColumns?.map(
|
||||
|
||||
@@ -213,7 +213,9 @@ describe.each([
|
||||
const callArgs = mockDownloadExportData.mock.calls[0][0];
|
||||
const query = callArgs.body.compositeQuery.queries[0];
|
||||
expect(query.spec.groupBy).toBeUndefined();
|
||||
expect(query.spec.having).toStrictEqual({ expression: '' });
|
||||
// An empty having ({ expression: '' }) is a no-op filter and serializes to
|
||||
// undefined — same as the cleared groupBy above.
|
||||
expect(query.spec.having).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
import { Color } from '@signozhq/design-tokens';
|
||||
import { Button, Select } from 'antd';
|
||||
import { Checkbox } from '@signozhq/ui/checkbox';
|
||||
import { TooltipProvider, TooltipSimple } from '@signozhq/ui/tooltip';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import cx from 'classnames';
|
||||
import TextToolTip from 'components/TextToolTip/TextToolTip';
|
||||
@@ -33,6 +34,7 @@ import { CustomMultiSelectProps, CustomTagProps, OptionData } from './types';
|
||||
import {
|
||||
ALL_SELECTED_VALUE,
|
||||
filterOptionsBySearch,
|
||||
findOptionLabelText,
|
||||
handleScrollToBottom,
|
||||
prioritizeOrAddOptionForMultiSelect,
|
||||
SPACEKEY,
|
||||
@@ -1937,7 +1939,7 @@ const CustomMultiSelect: React.FC<CustomMultiSelectProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
const tag = (
|
||||
<div
|
||||
className={cx('ant-select-selection-item', {
|
||||
'ant-select-selection-item-active': isActive,
|
||||
@@ -1967,13 +1969,32 @@ const CustomMultiSelect: React.FC<CustomMultiSelectProps> = ({
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
// `label` arrives already cut to maxTagTextLength, so the reveal reads the
|
||||
// option's own text (falling back to the raw value for freeform tags).
|
||||
return (
|
||||
<TooltipSimple
|
||||
side="top"
|
||||
delayDuration={300}
|
||||
title={findOptionLabelText(options, value)}
|
||||
>
|
||||
{tag}
|
||||
</TooltipSimple>
|
||||
);
|
||||
}
|
||||
|
||||
// Fallback for safety, should not be reached
|
||||
return <div />;
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[isAllSelected, activeChipIndex, selectedChips, selectedValues, maxTagCount],
|
||||
[
|
||||
isAllSelected,
|
||||
activeChipIndex,
|
||||
selectedChips,
|
||||
selectedValues,
|
||||
maxTagCount,
|
||||
options,
|
||||
],
|
||||
);
|
||||
|
||||
// Simple onClear handler to prevent clearing ALL
|
||||
@@ -1992,51 +2013,58 @@ const CustomMultiSelect: React.FC<CustomMultiSelectProps> = ({
|
||||
|
||||
// ===== Component Rendering =====
|
||||
return (
|
||||
<div
|
||||
className={cx('custom-multiselect-wrapper', {
|
||||
'all-selected': allOptionShown || isAllSelected,
|
||||
})}
|
||||
>
|
||||
{(allOptionShown || isAllSelected) && !searchText && (
|
||||
<div className="all-text">ALL</div>
|
||||
)}
|
||||
<Select
|
||||
ref={selectRef}
|
||||
className={cx('custom-multiselect', className, {
|
||||
'has-selection': selectedChips.length > 0 && !isAllSelected,
|
||||
'is-all-selected': isAllSelected,
|
||||
// Self-provided so the per-tag tooltips work wherever this select is rendered,
|
||||
// without every consumer having to sit under an app-level provider.
|
||||
<TooltipProvider>
|
||||
<div
|
||||
className={cx('custom-multiselect-wrapper', {
|
||||
'all-selected': allOptionShown || isAllSelected,
|
||||
})}
|
||||
placeholder={placeholder}
|
||||
mode="multiple"
|
||||
showSearch
|
||||
filterOption={false}
|
||||
onSearch={handleSearch}
|
||||
value={displayValue}
|
||||
onChange={(newValue): void => {
|
||||
handleInternalChange(newValue, false);
|
||||
}}
|
||||
onClear={onClearHandler}
|
||||
onDropdownVisibleChange={handleDropdownVisibleChange}
|
||||
open={isOpen}
|
||||
defaultActiveFirstOption={defaultActiveFirstOption}
|
||||
popupMatchSelectWidth={dropdownMatchSelectWidth}
|
||||
allowClear={allowClear}
|
||||
getPopupContainer={getPopupContainer ?? popupContainer}
|
||||
suffixIcon={<ChevronDown style={{ cursor: 'default' }} size="md" />}
|
||||
dropdownRender={customDropdownRender}
|
||||
menuItemSelectedIcon={null}
|
||||
popupClassName={cx('custom-multiselect-dropdown-container', popupClassName)}
|
||||
notFoundContent={<div className="empty-message">{noDataMessage}</div>}
|
||||
onKeyDown={handleKeyDown}
|
||||
tagRender={tagRender as any}
|
||||
placement={placement}
|
||||
listHeight={300}
|
||||
searchValue={searchText}
|
||||
maxTagTextLength={maxTagTextLength}
|
||||
maxTagCount={isAllSelected ? undefined : maxTagCount}
|
||||
{...rest}
|
||||
/>
|
||||
</div>
|
||||
>
|
||||
{(allOptionShown || isAllSelected) && !searchText && (
|
||||
<div className="all-text">ALL</div>
|
||||
)}
|
||||
<Select
|
||||
ref={selectRef}
|
||||
className={cx('custom-multiselect', className, {
|
||||
'has-selection': selectedChips.length > 0 && !isAllSelected,
|
||||
'is-all-selected': isAllSelected,
|
||||
})}
|
||||
placeholder={placeholder}
|
||||
mode="multiple"
|
||||
showSearch
|
||||
filterOption={false}
|
||||
onSearch={handleSearch}
|
||||
value={displayValue}
|
||||
onChange={(newValue): void => {
|
||||
handleInternalChange(newValue, false);
|
||||
}}
|
||||
onClear={onClearHandler}
|
||||
onDropdownVisibleChange={handleDropdownVisibleChange}
|
||||
open={isOpen}
|
||||
defaultActiveFirstOption={defaultActiveFirstOption}
|
||||
popupMatchSelectWidth={dropdownMatchSelectWidth}
|
||||
allowClear={allowClear}
|
||||
getPopupContainer={getPopupContainer ?? popupContainer}
|
||||
suffixIcon={<ChevronDown style={{ cursor: 'default' }} size="md" />}
|
||||
dropdownRender={customDropdownRender}
|
||||
menuItemSelectedIcon={null}
|
||||
popupClassName={cx(
|
||||
'custom-multiselect-dropdown-container',
|
||||
popupClassName,
|
||||
)}
|
||||
notFoundContent={<div className="empty-message">{noDataMessage}</div>}
|
||||
onKeyDown={handleKeyDown}
|
||||
tagRender={tagRender as any}
|
||||
placement={placement}
|
||||
listHeight={300}
|
||||
searchValue={searchText}
|
||||
maxTagTextLength={maxTagTextLength}
|
||||
maxTagCount={isAllSelected ? undefined : maxTagCount}
|
||||
{...rest}
|
||||
/>
|
||||
</div>
|
||||
</TooltipProvider>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { TooltipProvider } from '@signozhq/ui/tooltip';
|
||||
|
||||
import CustomMultiSelect from '../CustomMultiSelect';
|
||||
|
||||
const OPTIONS = [
|
||||
{ label: 'checkout-service-prod', value: 'checkout-service-prod' },
|
||||
{ label: 'payments-service-prod', value: 'payments-service-prod' },
|
||||
{ label: 'cart-service-prod', value: 'cart-service-prod' },
|
||||
];
|
||||
|
||||
const SELECTED = ['checkout-service-prod', 'payments-service-prod'];
|
||||
|
||||
function renderSelect(): void {
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<CustomMultiSelect
|
||||
options={OPTIONS}
|
||||
value={SELECTED}
|
||||
maxTagCount={1}
|
||||
maxTagTextLength={10}
|
||||
maxTagPlaceholder={(omitted): string => `+${omitted.length}`}
|
||||
/>
|
||||
</TooltipProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
/** Hovers an element and lets the tooltip's open delay elapse. */
|
||||
async function hover(element: HTMLElement): Promise<void> {
|
||||
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
|
||||
await user.hover(element);
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
}
|
||||
|
||||
describe('CustomMultiSelect tag tooltip', () => {
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it("reveals a tag's untruncated value on hover", async () => {
|
||||
renderSelect();
|
||||
|
||||
await hover(screen.getByText('checkout-s...'));
|
||||
|
||||
expect(screen.getByRole('tooltip')).toHaveTextContent(
|
||||
'checkout-service-prod',
|
||||
);
|
||||
});
|
||||
|
||||
// The `+N` placeholder stays the caller's to render — several callers already wrap
|
||||
// it in a tooltip of their own, and a second one would stack on top.
|
||||
it('leaves the +N overflow placeholder untouched', async () => {
|
||||
renderSelect();
|
||||
|
||||
await hover(screen.getByText('+1'));
|
||||
|
||||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -109,6 +109,21 @@ export const prioritizeOrAddOptionForMultiSelect = (
|
||||
return [...flatOutSelectedOptions, ...filteredOptions];
|
||||
};
|
||||
|
||||
export const findOptionLabelText = (
|
||||
options: OptionData[],
|
||||
value: string,
|
||||
): string => {
|
||||
const match = options
|
||||
.flatMap((option) =>
|
||||
'options' in option && Array.isArray(option.options)
|
||||
? option.options
|
||||
: [option],
|
||||
)
|
||||
.find((option) => option.value === value);
|
||||
|
||||
return typeof match?.label === 'string' ? match.label : value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Filters options based on search text
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
@use '../../styles/scrollbar' as *;
|
||||
|
||||
// Padding for the tooltip body that hosts a scroll area: the right side is given
|
||||
// up so the scrollbar can sit flush against the tooltip's edge instead of floating
|
||||
// inset from it. `.scrollArea` puts that spacing back between the text and the bar.
|
||||
.tooltipContent {
|
||||
--tooltip-padding: var(--spacing-2) 0 var(--spacing-2) var(--spacing-4);
|
||||
}
|
||||
|
||||
// How tall a hover reveal grows before its content starts scrolling.
|
||||
.scrollArea {
|
||||
max-height: 480px;
|
||||
overflow-y: auto;
|
||||
// Keep the page behind the tooltip still once the list hits its end.
|
||||
overscroll-behavior: contain;
|
||||
// Gap between the content and the scrollbar (or the tooltip edge when short).
|
||||
padding-right: var(--spacing-4);
|
||||
|
||||
@include custom-scrollbar;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import styles from './TooltipScrollArea.module.scss';
|
||||
|
||||
interface TooltipScrollAreaProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass as the hosting tooltip's content class (`tooltipContentProps`) so its
|
||||
* padding makes room for the scroll area's own edge handling.
|
||||
*/
|
||||
export const TOOLTIP_SCROLL_CONTENT_CLASS = styles.tooltipContent;
|
||||
|
||||
/**
|
||||
* Scroll container for hover reveals that list an unbounded number of items (tag
|
||||
* chips, variable values): caps the tooltip's height and scrolls past it. Plain CSS
|
||||
* overflow with a pinned-visible thin scrollbar — a tooltip is transient, so an
|
||||
* auto-hiding scrollbar would leave no hint that there is more below.
|
||||
*/
|
||||
function TooltipScrollArea({ children }: TooltipScrollAreaProps): JSX.Element {
|
||||
return <div className={styles.scrollArea}>{children}</div>;
|
||||
}
|
||||
|
||||
export default TooltipScrollArea;
|
||||
@@ -10,7 +10,6 @@ export enum FeatureKeys {
|
||||
DOT_METRICS_ENABLED = 'dot_metrics_enabled',
|
||||
USE_JSON_BODY = 'use_json_body',
|
||||
USE_FINE_GRAINED_AUTHZ = 'use_fine_grained_authz',
|
||||
USE_DASHBOARD_V2 = 'use_dashboard_v2',
|
||||
USE_INFRA_MONITORING_V2 = 'use_infra_monitoring_v2',
|
||||
ENABLE_AI_OBSERVABILITY = 'enable_ai_observability',
|
||||
ENABLE_METRICS_REDUCTION = 'enable_metrics_reduction',
|
||||
|
||||
@@ -56,14 +56,19 @@
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
// Wraps the shared chart Legend. Its width/height are set inline from the
|
||||
// computed chart dimensions, so the VirtuosoGrid inside gets the same bounded
|
||||
// box (right column / bottom rows) the uPlot charts use.
|
||||
// width/height are set inline from the computed chart dimensions; border-box
|
||||
// keeps the padding inside that height and overflow:hidden clips the
|
||||
// virtualized grid to the rectangle.
|
||||
.pieChartLegend {
|
||||
flex: 0 0 auto;
|
||||
box-sizing: border-box;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
padding-left: 12px;
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
|
||||
.pieChartLegendRight {
|
||||
padding-top: 8px;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Color } from '@signozhq/design-tokens';
|
||||
import { Group } from '@visx/group';
|
||||
import { Pie as VisxPie } from '@visx/shape';
|
||||
import { defaultStyles, useTooltip, useTooltipInPortal } from '@visx/tooltip';
|
||||
import cx from 'classnames';
|
||||
import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig';
|
||||
import { useResizeObserver } from 'hooks/useDimensions';
|
||||
import Legend from 'lib/uPlotV2/components/Legend/Legend';
|
||||
@@ -210,7 +211,9 @@ export default function Pie({
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={styles.pieChartLegend}
|
||||
className={cx(styles.pieChartLegend, {
|
||||
[styles.pieChartLegendRight]: isRightLegend,
|
||||
})}
|
||||
style={{
|
||||
width: legendWidth,
|
||||
height: legendHeight,
|
||||
|
||||
@@ -4,8 +4,13 @@ import { MOCK_QUERY } from 'container/QueryTable/Drilldown/__tests__/mockTableDa
|
||||
import { ExportDashboard } from 'hooks/dashboard/useExportDashboards';
|
||||
import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
import { Dashboard } from 'types/api/dashboard/getAll';
|
||||
import {
|
||||
defaultFeatureFlags,
|
||||
render,
|
||||
screen,
|
||||
userEvent,
|
||||
waitFor,
|
||||
} from 'tests/test-utils';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { generateExportToDashboardLink } from 'utils/dashboard/generateExportToDashboardLink';
|
||||
@@ -41,12 +46,16 @@ const mockUseHistory = jest.mocked(useHistory);
|
||||
// Mock data
|
||||
const TEST_QUERY_ID = 'test-query-id';
|
||||
const TEST_DASHBOARD_ID = 'test-dashboard-id';
|
||||
const TEST_DASHBOARD_TITLE = 'Test Dashboard';
|
||||
const TEST_DASHBOARD_DESCRIPTION = 'Test Description';
|
||||
const TEST_TIMESTAMP = '2023-01-01T00:00:00Z';
|
||||
const TEST_DASHBOARD_TITLE_2 = 'Test Dashboard for Export';
|
||||
const NEW_DASHBOARD_ID = 'new-dashboard-id';
|
||||
const DASHBOARDS_API_ENDPOINT = '*/api/v1/dashboards';
|
||||
|
||||
// The export dialog talks to the generated Perses-spec dashboard endpoints.
|
||||
const V2_LIST_ENDPOINT = '*/api/v2/users/me/dashboards';
|
||||
const V2_CREATE_ENDPOINT = '*/api/v2/dashboards';
|
||||
|
||||
// "Create new dashboard" names the dashboard from the `new_dashboard_title` i18n
|
||||
// key; the test-utils react-i18next mock returns the key verbatim.
|
||||
const NEW_DASHBOARD_TITLE = 'new_dashboard_title';
|
||||
|
||||
// Use the existing mock query from the codebase
|
||||
const mockQuery: Query = {
|
||||
@@ -54,23 +63,44 @@ const mockQuery: Query = {
|
||||
id: TEST_QUERY_ID, // Override with our test ID
|
||||
} as Query;
|
||||
|
||||
const createMockDashboard = (id: string = TEST_DASHBOARD_ID): Dashboard => ({
|
||||
id,
|
||||
data: {
|
||||
title: TEST_DASHBOARD_TITLE,
|
||||
description: TEST_DASHBOARD_DESCRIPTION,
|
||||
tags: [],
|
||||
layout: [],
|
||||
variables: {},
|
||||
},
|
||||
createdAt: TEST_TIMESTAMP,
|
||||
updatedAt: TEST_TIMESTAMP,
|
||||
createdBy: 'test-user',
|
||||
updatedBy: 'test-user',
|
||||
});
|
||||
|
||||
const ADD_TO_DASHBOARD_BUTTON_NAME = /add to dashboard/i;
|
||||
|
||||
interface PickerDashboard {
|
||||
id: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
/** Register the "list dashboards" endpoint the picker reads. */
|
||||
function mockDashboardList(dashboards: PickerDashboard[]): void {
|
||||
server.use(
|
||||
rest.get(V2_LIST_ENDPOINT, (_req, res, ctx) =>
|
||||
res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
status: 'success',
|
||||
data: {
|
||||
dashboards: dashboards.map(({ id, title }) => ({
|
||||
id,
|
||||
name: title,
|
||||
spec: { display: { name: title } },
|
||||
})),
|
||||
reservedKeywords: [],
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** Register the "create dashboard" endpoint the "New dashboard" button hits. */
|
||||
function mockCreateDashboard(id: string): void {
|
||||
server.use(
|
||||
rest.post(V2_CREATE_ENDPOINT, (_req, res, ctx) =>
|
||||
res(ctx.status(201), ctx.json({ status: 'success', data: { id } })),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Helper function to render component with props
|
||||
const renderExplorerOptionWrapper = (
|
||||
overrides = {},
|
||||
@@ -104,6 +134,8 @@ const renderExplorerOptionWrapper = (
|
||||
splitedQueries={props.splitedQueries}
|
||||
signalSource={props.signalSource}
|
||||
/>,
|
||||
undefined,
|
||||
{ appContextOverrides: { featureFlags: defaultFeatureFlags } },
|
||||
);
|
||||
};
|
||||
|
||||
@@ -157,17 +189,9 @@ describe('ExplorerOptionWrapper', () => {
|
||||
) => void
|
||||
>;
|
||||
|
||||
// Mock the dashboard creation API
|
||||
const mockNewDashboard = createMockDashboard(NEW_DASHBOARD_ID);
|
||||
server.use(
|
||||
rest.post(DASHBOARDS_API_ENDPOINT, (_req, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json({ data: mockNewDashboard })),
|
||||
),
|
||||
);
|
||||
mockCreateDashboard(NEW_DASHBOARD_ID);
|
||||
|
||||
renderExplorerOptionWrapper({
|
||||
onExport: testOnExport,
|
||||
});
|
||||
renderExplorerOptionWrapper({ onExport: testOnExport });
|
||||
|
||||
// Find and click the "Add to Dashboard" button
|
||||
const addToDashboardButton = screen.getByRole('button', {
|
||||
@@ -187,7 +211,7 @@ describe('ExplorerOptionWrapper', () => {
|
||||
// Wait for the API call to complete and onExport to be called
|
||||
await waitFor(() => {
|
||||
expect(testOnExport).toHaveBeenCalledWith(
|
||||
{ id: NEW_DASHBOARD_ID, title: TEST_DASHBOARD_TITLE },
|
||||
{ id: NEW_DASHBOARD_ID, title: NEW_DASHBOARD_TITLE },
|
||||
true,
|
||||
);
|
||||
});
|
||||
@@ -204,21 +228,13 @@ describe('ExplorerOptionWrapper', () => {
|
||||
>;
|
||||
|
||||
// Mock existing dashboards with unique titles
|
||||
const mockDashboard1 = createMockDashboard('dashboard-1');
|
||||
mockDashboard1.data.title = 'Dashboard 1';
|
||||
const mockDashboard2 = createMockDashboard('dashboard-2');
|
||||
mockDashboard2.data.title = 'Dashboard 2';
|
||||
const mockDashboards = [mockDashboard1, mockDashboard2];
|
||||
const dashboards: PickerDashboard[] = [
|
||||
{ id: 'dashboard-1', title: 'Dashboard 1' },
|
||||
{ id: 'dashboard-2', title: 'Dashboard 2' },
|
||||
];
|
||||
mockDashboardList(dashboards);
|
||||
|
||||
server.use(
|
||||
rest.get(DASHBOARDS_API_ENDPOINT, (_req, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json({ data: mockDashboards })),
|
||||
),
|
||||
);
|
||||
|
||||
renderExplorerOptionWrapper({
|
||||
onExport: testOnExport,
|
||||
});
|
||||
renderExplorerOptionWrapper({ onExport: testOnExport });
|
||||
|
||||
// Find and click the "Add to Dashboard" button
|
||||
const addToDashboardButton = screen.getByRole('button', {
|
||||
@@ -231,10 +247,15 @@ describe('ExplorerOptionWrapper', () => {
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Wait for the dashboard select dropdown to render inside the dialog
|
||||
// Wait for the dashboard select to render AND finish loading. antd
|
||||
// disables the Select while the list request is in flight, and a click
|
||||
// on a disabled combobox is a no-op — so sync on the ready (enabled)
|
||||
// state before clicking.
|
||||
const modal = screen.getByRole('dialog');
|
||||
await waitFor(() => {
|
||||
expect(modal.querySelector('[role="combobox"]')).toBeTruthy();
|
||||
const combobox = modal.querySelector('[role="combobox"]');
|
||||
expect(combobox).toBeTruthy();
|
||||
expect(combobox).not.toBeDisabled();
|
||||
});
|
||||
|
||||
const dashboardSelect = modal.querySelector(
|
||||
@@ -245,11 +266,11 @@ describe('ExplorerOptionWrapper', () => {
|
||||
|
||||
// Wait for the dropdown options to appear and select the first dashboard
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(mockDashboard1.data.title)).toBeInTheDocument();
|
||||
expect(screen.getByText(dashboards[0].title)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Click on the first dashboard option
|
||||
const dashboardOption = screen.getByText(mockDashboard1.data.title);
|
||||
const dashboardOption = screen.getByText(dashboards[0].title);
|
||||
await user.click(dashboardOption);
|
||||
|
||||
// Wait for the selection to be made and the export button to be enabled
|
||||
@@ -264,7 +285,7 @@ describe('ExplorerOptionWrapper', () => {
|
||||
// Wait for onExport to be called with the selected dashboard
|
||||
await waitFor(() => {
|
||||
expect(testOnExport).toHaveBeenCalledWith(
|
||||
{ id: 'dashboard-1', title: 'Dashboard 1' },
|
||||
{ id: dashboards[0].id, title: dashboards[0].title },
|
||||
false,
|
||||
);
|
||||
});
|
||||
@@ -305,18 +326,12 @@ describe('ExplorerOptionWrapper', () => {
|
||||
};
|
||||
|
||||
// Mock existing dashboards
|
||||
const mockDashboard = createMockDashboard('test-dashboard-id');
|
||||
mockDashboard.data.title = TEST_DASHBOARD_TITLE_2;
|
||||
const dashboards: PickerDashboard[] = [
|
||||
{ id: TEST_DASHBOARD_ID, title: TEST_DASHBOARD_TITLE_2 },
|
||||
];
|
||||
mockDashboardList(dashboards);
|
||||
|
||||
server.use(
|
||||
rest.get(DASHBOARDS_API_ENDPOINT, (_req, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json({ data: [mockDashboard] })),
|
||||
),
|
||||
);
|
||||
|
||||
renderExplorerOptionWrapper({
|
||||
onExport: handleExport,
|
||||
});
|
||||
renderExplorerOptionWrapper({ onExport: handleExport });
|
||||
|
||||
// Find and click the "Add to Dashboard" button
|
||||
const addToDashboardButton = screen.getByRole('button', {
|
||||
@@ -329,10 +344,12 @@ describe('ExplorerOptionWrapper', () => {
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Wait for the dashboard select dropdown to render inside the dialog
|
||||
// Wait for the dashboard select to render AND finish loading (see note above).
|
||||
const modal = screen.getByRole('dialog');
|
||||
await waitFor(() => {
|
||||
expect(modal.querySelector('[role="combobox"]')).toBeTruthy();
|
||||
const combobox = modal.querySelector('[role="combobox"]');
|
||||
expect(combobox).toBeTruthy();
|
||||
expect(combobox).not.toBeDisabled();
|
||||
});
|
||||
|
||||
const dashboardSelect = modal.querySelector(
|
||||
@@ -343,11 +360,11 @@ describe('ExplorerOptionWrapper', () => {
|
||||
|
||||
// Wait for the dropdown options to appear and select the dashboard
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText(mockDashboard.data.title)).toBeInTheDocument();
|
||||
expect(screen.getByText(dashboards[0].title)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// Click on the dashboard option
|
||||
const dashboardOption = screen.getByText(mockDashboard.data.title);
|
||||
const dashboardOption = screen.getByText(dashboards[0].title);
|
||||
await user.click(dashboardOption);
|
||||
|
||||
// Wait for the selection to be made and the export button to be enabled
|
||||
@@ -363,7 +380,7 @@ describe('ExplorerOptionWrapper', () => {
|
||||
await waitFor(() => {
|
||||
expect(mockSafeNavigate).toHaveBeenCalledTimes(1);
|
||||
expect(mockSafeNavigate).toHaveBeenCalledWith(
|
||||
`/dashboard/test-dashboard-id/new?graphType=${panelTypeParam}&widgetId=${widgetId}&compositeQuery=${encodeURIComponent(
|
||||
`/dashboard/${TEST_DASHBOARD_ID}/new?graphType=${panelTypeParam}&widgetId=${widgetId}&compositeQuery=${encodeURIComponent(
|
||||
JSON.stringify(query),
|
||||
)}`,
|
||||
);
|
||||
@@ -372,23 +389,23 @@ describe('ExplorerOptionWrapper', () => {
|
||||
// Assert that useUpdateDashboard was NOT called (as per PR #8029)
|
||||
expect(mockMutate).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not show export buttons when component is disabled', () => {
|
||||
const testOnExport = jest.fn() as jest.MockedFunction<
|
||||
(
|
||||
dashboard: ExportDashboard | null,
|
||||
isNewDashboard?: boolean,
|
||||
queryToExport?: Query,
|
||||
) => void
|
||||
>;
|
||||
it('should not show export buttons when component is disabled', () => {
|
||||
const testOnExport = jest.fn() as jest.MockedFunction<
|
||||
(
|
||||
dashboard: ExportDashboard | null,
|
||||
isNewDashboard?: boolean,
|
||||
queryToExport?: Query,
|
||||
) => void
|
||||
>;
|
||||
|
||||
renderExplorerOptionWrapper({ disabled: true, onExport: testOnExport });
|
||||
renderExplorerOptionWrapper({ disabled: true, onExport: testOnExport });
|
||||
|
||||
// The "Add to Dashboard" button should be disabled
|
||||
const addToDashboardButton = screen.getByRole('button', {
|
||||
name: ADD_TO_DASHBOARD_BUTTON_NAME,
|
||||
});
|
||||
expect(addToDashboardButton).toBeDisabled();
|
||||
// The "Add to Dashboard" button should be disabled
|
||||
const addToDashboardButton = screen.getByRole('button', {
|
||||
name: ADD_TO_DASHBOARD_BUTTON_NAME,
|
||||
});
|
||||
expect(addToDashboardButton).toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,8 +9,6 @@ import {
|
||||
DashboardtypesListSortDTO,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { useGetAllDashboard } from 'hooks/dashboard/useGetAllDashboard';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import { useSafeNavigate } from 'hooks/useSafeNavigate';
|
||||
import { ArrowRight, ArrowUpRight, Plus } from '@signozhq/icons';
|
||||
import Card from 'periscope/components/Card/Card';
|
||||
@@ -22,7 +20,7 @@ import dialsUrl from '@/assets/Icons/dials.svg';
|
||||
|
||||
import { getItemIcon } from '../constants';
|
||||
|
||||
// The five most-recent dashboards, normalised across the v1 and v2 list APIs.
|
||||
// The five most-recent dashboards from the V2 list API.
|
||||
interface RecentDashboard {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -38,52 +36,27 @@ export default function Dashboards({
|
||||
}): JSX.Element {
|
||||
const { safeNavigate } = useSafeNavigate();
|
||||
const { user } = useAppContext();
|
||||
const isDashboardV2 = useIsDashboardV2();
|
||||
|
||||
// Fetch the recent dashboards from whichever API the `use_dashboard_v2` flag
|
||||
// selects; the inactive one stays disabled so it never fires.
|
||||
const {
|
||||
data: v1List,
|
||||
isLoading: v1Loading,
|
||||
isError: v1Error,
|
||||
} = useGetAllDashboard({ enabled: !isDashboardV2 });
|
||||
|
||||
const {
|
||||
data: v2List,
|
||||
isLoading: v2Loading,
|
||||
isError: v2Error,
|
||||
} = useListDashboardsForUserV2(
|
||||
{
|
||||
sort: DashboardtypesListSortDTO.updated_at,
|
||||
order: DashboardtypesListOrderDTO.desc,
|
||||
limit: 5,
|
||||
offset: 0,
|
||||
},
|
||||
{ query: { enabled: isDashboardV2 } },
|
||||
);
|
||||
data: dashboardsList,
|
||||
isLoading: isDashboardListLoading,
|
||||
isError: isDashboardListError,
|
||||
} = useListDashboardsForUserV2({
|
||||
sort: DashboardtypesListSortDTO.updated_at,
|
||||
order: DashboardtypesListOrderDTO.desc,
|
||||
limit: 5,
|
||||
offset: 0,
|
||||
});
|
||||
|
||||
const isDashboardListLoading = isDashboardV2 ? v2Loading : v1Loading;
|
||||
const isDashboardListError = isDashboardV2 ? v2Error : v1Error;
|
||||
|
||||
const sortedDashboards = useMemo<RecentDashboard[]>(() => {
|
||||
if (isDashboardV2) {
|
||||
return (v2List?.data?.dashboards ?? []).map((d) => ({
|
||||
const sortedDashboards = useMemo<RecentDashboard[]>(
|
||||
() =>
|
||||
(dashboardsList?.data?.dashboards ?? []).map((d) => ({
|
||||
id: d.id,
|
||||
title: d.spec?.display?.name ?? d.name,
|
||||
tags: (d.tags ?? []).map((t) => (t.value ? `${t.key}:${t.value}` : t.key)),
|
||||
}));
|
||||
}
|
||||
return [...(v1List?.data ?? [])]
|
||||
.sort(
|
||||
(a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime(),
|
||||
)
|
||||
.slice(0, 5)
|
||||
.map((d) => ({
|
||||
id: d.id,
|
||||
title: d.data.title,
|
||||
tags: d.data.tags ?? [],
|
||||
}));
|
||||
}, [isDashboardV2, v1List, v2List]);
|
||||
})),
|
||||
[dashboardsList],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (sortedDashboards.length > 0 && !loadingUserPreferences) {
|
||||
|
||||
@@ -2,15 +2,9 @@ import { ReactNode } from 'react';
|
||||
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
import { createDashboardV2 } from 'api/generated/services/dashboard';
|
||||
import createDashboardV1 from 'api/v1/dashboards/create';
|
||||
import { ENTITY_VERSION_V5 } from 'constants/app';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import { Dashboard } from 'types/api/dashboard/getAll';
|
||||
|
||||
import { useCreateExportDashboard } from '../useCreateExportDashboard';
|
||||
|
||||
jest.mock('hooks/useIsDashboardV2');
|
||||
jest.mock('api/v1/dashboards/create');
|
||||
jest.mock('api/generated/services/dashboard', () => ({
|
||||
createDashboardV2: jest.fn(),
|
||||
}));
|
||||
@@ -20,10 +14,6 @@ jest.mock('providers/ErrorModalProvider', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
const mockUseIsDashboardV2 = useIsDashboardV2 as jest.MockedFunction<
|
||||
typeof useIsDashboardV2
|
||||
>;
|
||||
const mockCreateV1 = createDashboardV1 as jest.Mock;
|
||||
const mockCreateV2 = createDashboardV2 as jest.Mock;
|
||||
|
||||
function wrapper({ children }: { children: ReactNode }): JSX.Element {
|
||||
@@ -40,35 +30,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
describe('useCreateExportDashboard', () => {
|
||||
it('creates via the V1 endpoint and returns the created dashboard when the flag is off', async () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(false);
|
||||
const v1Dashboard = {
|
||||
id: 'v1-new',
|
||||
data: { title: TITLE },
|
||||
} as unknown as Dashboard;
|
||||
mockCreateV1.mockResolvedValue({ httpStatusCode: 200, data: v1Dashboard });
|
||||
const onCreated = jest.fn();
|
||||
|
||||
const { result } = renderHook(
|
||||
() => useCreateExportDashboard({ title: TITLE, onCreated }),
|
||||
{ wrapper },
|
||||
);
|
||||
|
||||
act(() => result.current.create());
|
||||
|
||||
await waitFor(() =>
|
||||
expect(onCreated).toHaveBeenCalledWith({ id: 'v1-new', title: TITLE }),
|
||||
);
|
||||
expect(mockCreateV1).toHaveBeenCalledWith({
|
||||
title: TITLE,
|
||||
uploadedGrafana: false,
|
||||
version: ENTITY_VERSION_V5,
|
||||
});
|
||||
expect(mockCreateV2).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('creates via the V2 Perses endpoint and normalizes the response when the flag is on', async () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(true);
|
||||
it('creates via the V2 Perses endpoint and normalizes the response', async () => {
|
||||
mockCreateV2.mockResolvedValue({ data: { id: 'v2-new' } });
|
||||
const onCreated = jest.fn();
|
||||
|
||||
@@ -88,6 +50,5 @@ describe('useCreateExportDashboard', () => {
|
||||
spec: expect.objectContaining({ display: { name: TITLE } }),
|
||||
}),
|
||||
);
|
||||
expect(mockCreateV1).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,44 +1,18 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useListDashboardsForUserV2 } from 'api/generated/services/dashboard';
|
||||
import { useGetAllDashboard } from 'hooks/dashboard/useGetAllDashboard';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import { Dashboard } from 'types/api/dashboard/getAll';
|
||||
|
||||
import { useExportDashboards } from '../useExportDashboards';
|
||||
|
||||
jest.mock('hooks/useIsDashboardV2');
|
||||
jest.mock('hooks/dashboard/useGetAllDashboard');
|
||||
jest.mock('api/generated/services/dashboard', () => ({
|
||||
useListDashboardsForUserV2: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockUseIsDashboardV2 = useIsDashboardV2 as jest.MockedFunction<
|
||||
typeof useIsDashboardV2
|
||||
>;
|
||||
const mockUseGetAllDashboard = useGetAllDashboard as jest.Mock;
|
||||
const mockUseListV2 = useListDashboardsForUserV2 as jest.Mock;
|
||||
|
||||
const v1Refetch = jest.fn();
|
||||
const v2Refetch = jest.fn();
|
||||
|
||||
const v1Dashboard = {
|
||||
id: 'v1-1',
|
||||
data: { title: 'V1 Dashboard' },
|
||||
} as unknown as Dashboard;
|
||||
|
||||
const v1Other = {
|
||||
id: 'v1-2',
|
||||
data: { title: 'Other board' },
|
||||
} as unknown as Dashboard;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockUseGetAllDashboard.mockReturnValue({
|
||||
data: { data: [v1Dashboard, v1Other] },
|
||||
isLoading: false,
|
||||
isFetching: false,
|
||||
refetch: v1Refetch,
|
||||
});
|
||||
mockUseListV2.mockReturnValue({
|
||||
data: {
|
||||
data: {
|
||||
@@ -58,54 +32,21 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
describe('useExportDashboards', () => {
|
||||
it('returns the V1 list and disables the V2 query when the flag is off', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(false);
|
||||
|
||||
const { result } = renderHook(() => useExportDashboards());
|
||||
|
||||
expect(result.current.dashboards).toStrictEqual([
|
||||
{ id: 'v1-1', title: 'V1 Dashboard' },
|
||||
{ id: 'v1-2', title: 'Other board' },
|
||||
]);
|
||||
expect(mockUseGetAllDashboard).toHaveBeenCalledWith({ enabled: true });
|
||||
expect(mockUseListV2).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.objectContaining({
|
||||
query: { enabled: false, keepPreviousData: true },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('filters the V1 list in memory by title (case-insensitive)', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(false);
|
||||
|
||||
const { result } = renderHook(() => useExportDashboards('v1 dash'));
|
||||
|
||||
expect(result.current.dashboards).toStrictEqual([
|
||||
{ id: 'v1-1', title: 'V1 Dashboard' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns the V2 list normalized to the export shape when the flag is on', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(true);
|
||||
|
||||
it('returns the V2 list normalized to the export shape', () => {
|
||||
const { result } = renderHook(() => useExportDashboards());
|
||||
|
||||
expect(result.current.dashboards).toStrictEqual([
|
||||
{ id: 'v2-1', title: 'V2 Dashboard' },
|
||||
]);
|
||||
expect(mockUseGetAllDashboard).toHaveBeenCalledWith({ enabled: false });
|
||||
expect(mockUseListV2).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ query: undefined }),
|
||||
expect.objectContaining({
|
||||
query: { enabled: true, keepPreviousData: true },
|
||||
query: { keepPreviousData: true },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('passes the search term as a name-contains filter clause to the V2 query param', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(true);
|
||||
|
||||
renderHook(() => useExportDashboards('payments'));
|
||||
|
||||
expect(mockUseListV2).toHaveBeenCalledWith(
|
||||
@@ -114,12 +55,10 @@ describe('useExportDashboards', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('refetches the active source', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(true);
|
||||
it('refetches the V2 source', () => {
|
||||
const { result } = renderHook(() => useExportDashboards());
|
||||
|
||||
result.current.refetch();
|
||||
expect(v2Refetch).toHaveBeenCalledTimes(1);
|
||||
expect(v1Refetch).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import type { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
|
||||
import { useGetExportToDashboardLink } from '../useGetExportToDashboardLink';
|
||||
|
||||
jest.mock('hooks/useIsDashboardV2');
|
||||
const mockUseIsDashboardV2 = useIsDashboardV2 as jest.MockedFunction<
|
||||
typeof useIsDashboardV2
|
||||
>;
|
||||
|
||||
const query = { id: 'q1', queryType: 'builder' } as unknown as Query;
|
||||
const params = {
|
||||
dashboardId: 'dash-1',
|
||||
@@ -19,21 +13,7 @@ const params = {
|
||||
};
|
||||
|
||||
describe('useGetExportToDashboardLink', () => {
|
||||
it('builds a V1 new-widget link when the dashboard-v2 flag is off', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(false);
|
||||
|
||||
const { result } = renderHook(() => useGetExportToDashboardLink());
|
||||
const link = result.current(params);
|
||||
|
||||
expect(link?.startsWith('/dashboard/dash-1/new?')).toBe(true);
|
||||
expect(link).toContain('graphType=');
|
||||
expect(link).toContain('widgetId=w1');
|
||||
expect(link).toContain('compositeQuery=');
|
||||
});
|
||||
|
||||
it('builds a V2 panel/new link (ignoring widgetId) when the flag is on', () => {
|
||||
mockUseIsDashboardV2.mockReturnValue(true);
|
||||
|
||||
it('builds a V2 panel/new link (ignoring widgetId)', () => {
|
||||
const { result } = renderHook(() => useGetExportToDashboardLink());
|
||||
const link = result.current(params);
|
||||
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useMutation } from 'react-query';
|
||||
import { createDashboardV2 } from 'api/generated/services/dashboard';
|
||||
import createDashboardV1 from 'api/v1/dashboards/create';
|
||||
import { ENTITY_VERSION_V5 } from 'constants/app';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import { useErrorModal } from 'providers/ErrorModalProvider';
|
||||
import APIError from 'types/api/error';
|
||||
|
||||
@@ -20,14 +17,13 @@ interface UseCreateExportDashboardResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag-aware "create a new dashboard to export into". V2 uses the Perses-spec
|
||||
* `createDashboardV2`; V1 uses the legacy create. Both normalize to an `ExportDashboard`.
|
||||
* "Create a new dashboard to export into". Uses the Perses-spec `createDashboardV2`
|
||||
* and normalizes to an `ExportDashboard`.
|
||||
*/
|
||||
export function useCreateExportDashboard({
|
||||
title,
|
||||
onCreated,
|
||||
}: UseCreateExportDashboardParams): UseCreateExportDashboardResult {
|
||||
const isDashboardV2 = useIsDashboardV2();
|
||||
const { showErrorModal } = useErrorModal();
|
||||
|
||||
const onError = useCallback(
|
||||
@@ -35,16 +31,7 @@ export function useCreateExportDashboard({
|
||||
[showErrorModal],
|
||||
);
|
||||
|
||||
const v1 = useMutation(createDashboardV1, {
|
||||
onSuccess: (data) => {
|
||||
if (data.data) {
|
||||
onCreated({ id: data.data.id, title: data.data.data.title ?? '' });
|
||||
}
|
||||
},
|
||||
onError,
|
||||
});
|
||||
|
||||
const v2 = useMutation(
|
||||
const createDashboardMutation = useMutation(
|
||||
() =>
|
||||
createDashboardV2({
|
||||
schemaVersion: 'v6',
|
||||
@@ -66,15 +53,11 @@ export function useCreateExportDashboard({
|
||||
);
|
||||
|
||||
const create = useCallback((): void => {
|
||||
if (isDashboardV2) {
|
||||
v2.mutate();
|
||||
} else {
|
||||
v1.mutate({ title, uploadedGrafana: false, version: ENTITY_VERSION_V5 });
|
||||
}
|
||||
}, [isDashboardV2, v1, v2, title]);
|
||||
createDashboardMutation.mutate();
|
||||
}, [createDashboardMutation]);
|
||||
|
||||
return {
|
||||
create,
|
||||
isLoading: isDashboardV2 ? v2.isLoading : v1.isLoading,
|
||||
isLoading: createDashboardMutation.isLoading,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useListDashboardsForUserV2 } from 'api/generated/services/dashboard';
|
||||
import { DashboardtypesListedDashboardForUserV2DTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { useGetAllDashboard } from 'hooks/dashboard/useGetAllDashboard';
|
||||
import useDebounce from 'hooks/useDebounce';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import { Dashboard } from 'types/api/dashboard/getAll';
|
||||
|
||||
const V2_LIST_LIMIT = 1000;
|
||||
const SEARCH_DEBOUNCE_MS = 300;
|
||||
|
||||
/** Neutral id+title the picker uses in place of the V1/V2 dashboard entity. */
|
||||
/** Neutral id+title the picker uses in place of the dashboard entity. */
|
||||
export interface ExportDashboard {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -24,29 +21,12 @@ export interface UseExportDashboardsResult {
|
||||
refetch: () => void;
|
||||
}
|
||||
|
||||
function fromV2(
|
||||
function toExportDashboard(
|
||||
item: DashboardtypesListedDashboardForUserV2DTO,
|
||||
): ExportDashboard {
|
||||
return { id: item.id, title: item.spec.display?.name || item.name };
|
||||
}
|
||||
|
||||
function fromV1(dashboard: Dashboard): ExportDashboard {
|
||||
return { id: dashboard.id, title: dashboard.data.title ?? '' };
|
||||
}
|
||||
|
||||
function filterByTitle(
|
||||
dashboards: ExportDashboard[],
|
||||
search: string,
|
||||
): ExportDashboard[] {
|
||||
const term = search.trim().toLowerCase();
|
||||
if (!term) {
|
||||
return dashboards;
|
||||
}
|
||||
return dashboards.filter((dashboard) =>
|
||||
dashboard.title.toLowerCase().includes(term),
|
||||
);
|
||||
}
|
||||
|
||||
// The V2 list `query` is a filter DSL (`key OP value`), not free text — wrap a typed term
|
||||
// as a name-contains clause (single quotes escaped).
|
||||
function toNameQuery(search: string): string | undefined {
|
||||
@@ -54,37 +34,28 @@ function toNameQuery(search: string): string | undefined {
|
||||
return term ? `name CONTAINS '${term.replace(/'/g, "\\'")}'` : undefined;
|
||||
}
|
||||
|
||||
/** Flag-aware picker source: V2 searches server-side (debounced), V1 filters in memory. */
|
||||
/** Picker source: searches the V2 dashboard list server-side (debounced). */
|
||||
export function useExportDashboards(search = ''): UseExportDashboardsResult {
|
||||
const isDashboardV2 = useIsDashboardV2();
|
||||
const debouncedSearch = useDebounce(search, SEARCH_DEBOUNCE_MS);
|
||||
|
||||
const v1 = useGetAllDashboard({ enabled: !isDashboardV2 });
|
||||
const v2 = useListDashboardsForUserV2(
|
||||
const listQuery = useListDashboardsForUserV2(
|
||||
{ limit: V2_LIST_LIMIT, query: toNameQuery(debouncedSearch) },
|
||||
{ query: { enabled: isDashboardV2, keepPreviousData: true } },
|
||||
{ query: { keepPreviousData: true } },
|
||||
);
|
||||
|
||||
const dashboards = useMemo<ExportDashboard[]>(
|
||||
() =>
|
||||
isDashboardV2
|
||||
? (v2.data?.data?.dashboards ?? []).map(fromV2)
|
||||
: filterByTitle((v1.data?.data ?? []).map(fromV1), search),
|
||||
[isDashboardV2, v1.data, v2.data, search],
|
||||
() => (listQuery.data?.data?.dashboards ?? []).map(toExportDashboard),
|
||||
[listQuery.data],
|
||||
);
|
||||
|
||||
const refetch = useCallback((): void => {
|
||||
if (isDashboardV2) {
|
||||
void v2.refetch();
|
||||
} else {
|
||||
void v1.refetch();
|
||||
}
|
||||
}, [isDashboardV2, v1, v2]);
|
||||
void listQuery.refetch();
|
||||
}, [listQuery]);
|
||||
|
||||
return {
|
||||
dashboards,
|
||||
isLoading: isDashboardV2 ? v2.isLoading : v1.isLoading,
|
||||
isFetching: isDashboardV2 ? v2.isFetching : v1.isFetching,
|
||||
isLoading: listQuery.isLoading,
|
||||
isFetching: listQuery.isFetching,
|
||||
refetch,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { useCallback } from 'react';
|
||||
import type { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import { buildExportPanelLink } from 'pages/DashboardPageV2/DashboardContainer/PanelEditor/newPanelRoute';
|
||||
import type { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { generateExportToDashboardLink } from 'utils/dashboard/generateExportToDashboardLink';
|
||||
|
||||
interface ExportToDashboardLinkParams {
|
||||
dashboardId: string;
|
||||
@@ -13,25 +11,15 @@ interface ExportToDashboardLinkParams {
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag-aware "Add to Dashboard" link builder for the explorers. V2 targets the panel
|
||||
* editor; V1 uses the legacy new-widget link. `null` (V2 only) when the panel type has no
|
||||
* V2 kind, so callers skip navigation.
|
||||
* "Add to Dashboard" link builder for the explorers. Targets the V2 panel editor;
|
||||
* `null` when the panel type has no V2 kind, so callers skip navigation.
|
||||
*/
|
||||
export function useGetExportToDashboardLink(): (
|
||||
params: ExportToDashboardLinkParams,
|
||||
) => string | null {
|
||||
const isDashboardV2 = useIsDashboardV2();
|
||||
|
||||
return useCallback(
|
||||
({ dashboardId, panelType, query, widgetId }: ExportToDashboardLinkParams) =>
|
||||
isDashboardV2
|
||||
? buildExportPanelLink({ dashboardId, panelType, query })
|
||||
: generateExportToDashboardLink({
|
||||
query,
|
||||
panelType,
|
||||
dashboardId,
|
||||
widgetId,
|
||||
}),
|
||||
[isDashboardV2],
|
||||
({ dashboardId, panelType, query }: ExportToDashboardLinkParams) =>
|
||||
buildExportPanelLink({ dashboardId, panelType, query }),
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { FeatureKeys } from 'constants/features';
|
||||
import { useAppContext } from 'providers/App/App';
|
||||
|
||||
export function useIsDashboardV2(): boolean {
|
||||
const { featureFlags } = useAppContext();
|
||||
return Boolean(
|
||||
featureFlags?.find((flag) => flag.name === FeatureKeys.USE_DASHBOARD_V2)
|
||||
?.active,
|
||||
);
|
||||
}
|
||||
@@ -1,15 +1,7 @@
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import DashboardPageV2 from 'pages/DashboardPageV2';
|
||||
|
||||
import DashboardPage from './DashboardPage';
|
||||
|
||||
// Serves the V2 dashboard detail page when the `use_dashboard_v2` flag is active;
|
||||
// otherwise the existing V1 page. Lets V2 dark-ship behind the flag without
|
||||
// changing route definitions.
|
||||
function DashboardPageEntry(): JSX.Element {
|
||||
const isDashboardV2 = useIsDashboardV2();
|
||||
|
||||
return isDashboardV2 ? <DashboardPageV2 /> : <DashboardPage />;
|
||||
return <DashboardPageV2 />;
|
||||
}
|
||||
|
||||
export default DashboardPageEntry;
|
||||
|
||||
@@ -113,3 +113,15 @@
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
// Hidden tags revealed on hovering the `+N` badge: the same chips as inline, one per
|
||||
// line (easier to scan than a wrapped cloud) and width-capped so a long tag wraps
|
||||
// instead of stretching the tooltip off-screen.
|
||||
.overflowTags {
|
||||
display: flex;
|
||||
max-width: 360px;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 4px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ import { linkifyText } from 'utils/linkifyText';
|
||||
import { openInNewTab } from 'utils/navigation';
|
||||
|
||||
import styles from './DashboardInfo.module.scss';
|
||||
import { TOOLTIP_SCROLL_CONTENT_CLASS } from 'components/TooltipScrollArea/TooltipScrollArea';
|
||||
|
||||
import TagsOverflowTooltip from './TagsOverflowTooltip';
|
||||
import { DASHBOARD_NAME_MAX_LENGTH } from '../../constants';
|
||||
import { useDashboardStore } from '../../store/useDashboardStore';
|
||||
|
||||
@@ -231,7 +234,10 @@ function DashboardInfo({
|
||||
<TagBadge key={tag}>{tag}</TagBadge>
|
||||
))}
|
||||
{remainingTags.length > 0 && (
|
||||
<TooltipSimple title={remainingTags.join(', ')}>
|
||||
<TooltipSimple
|
||||
title={<TagsOverflowTooltip tags={remainingTags} />}
|
||||
tooltipContentProps={{ className: TOOLTIP_SCROLL_CONTENT_CLASS }}
|
||||
>
|
||||
<span data-testid="dashboard-tags-overflow">
|
||||
<TagBadge>+{remainingTags.length}</TagBadge>
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import TagBadge from 'components/TagBadge/TagBadge';
|
||||
import TooltipScrollArea from 'components/TooltipScrollArea/TooltipScrollArea';
|
||||
|
||||
import styles from './DashboardInfo.module.scss';
|
||||
|
||||
interface TagsOverflowTooltipProps {
|
||||
/** The tags the cluster isn't showing inline. */
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
function TagsOverflowTooltip({ tags }: TagsOverflowTooltipProps): JSX.Element {
|
||||
return (
|
||||
<TooltipScrollArea>
|
||||
<div className={styles.overflowTags} data-testid="dashboard-tags-tooltip">
|
||||
{tags.map((tag) => (
|
||||
<TagBadge key={tag}>{tag}</TagBadge>
|
||||
))}
|
||||
</div>
|
||||
</TooltipScrollArea>
|
||||
);
|
||||
}
|
||||
|
||||
export default TagsOverflowTooltip;
|
||||
@@ -0,0 +1,21 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
import TagsOverflowTooltip from '../TagsOverflowTooltip';
|
||||
|
||||
describe('TagsOverflowTooltip', () => {
|
||||
it('renders every hidden tag as its own chip', () => {
|
||||
render(
|
||||
<TagsOverflowTooltip tags={['production', 'team-checkout', 'tier-1']} />,
|
||||
);
|
||||
|
||||
const chips = screen
|
||||
.getByTestId('dashboard-tags-tooltip')
|
||||
.querySelectorAll('[data-slot="badge"]');
|
||||
|
||||
expect(Array.from(chips).map((chip) => chip.textContent)).toStrictEqual([
|
||||
'production',
|
||||
'team-checkout',
|
||||
'tier-1',
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -2,7 +2,7 @@
|
||||
from the collapsible config sections above by the same hairline divider. */
|
||||
.divider {
|
||||
height: 1px;
|
||||
background: var(--l2-border);
|
||||
background: var(--l1-border);
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bell } from '@signozhq/icons';
|
||||
import { Flame } from '@signozhq/icons';
|
||||
import type { DashboardtypesPanelDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { getPanelDefinition } from 'pages/DashboardPageV2/DashboardContainer/Panels/registry';
|
||||
import { useCreateAlertFromPanel } from 'pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/hooks/useCreateAlertFromPanel';
|
||||
@@ -38,7 +38,7 @@ function ConfigActions({
|
||||
<div className={styles.list}>
|
||||
<ConfigActionRow
|
||||
testId="panel-editor-v2-create-alert"
|
||||
icon={<Bell size={14} />}
|
||||
icon={<Flame size={14} />}
|
||||
label="Create alert"
|
||||
onClick={(): void => createAlert(panel, panelId)}
|
||||
/>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@use '../../../../../styles/scrollbar' as *;
|
||||
|
||||
.config {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -6,33 +8,24 @@
|
||||
background-color: var(--l1-background);
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
padding-bottom: 44px;
|
||||
|
||||
//TODO: replace this with custom-scrollbar mixin
|
||||
// Thin, unobtrusive scrollbar (replaces the chunky native bar).
|
||||
$thumb: color-mix(in srgb, var(--bg-vanilla-100) 16%, transparent);
|
||||
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: $thumb transparent;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 8px;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: $thumb;
|
||||
border-radius: 999px;
|
||||
border: 2px solid transparent;
|
||||
background-clip: padding-box;
|
||||
}
|
||||
@include custom-scrollbar;
|
||||
}
|
||||
|
||||
.heading {
|
||||
margin-bottom: 18px;
|
||||
padding: 16px 16px 0 16px;
|
||||
padding: 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.marker {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 4px;
|
||||
border-radius: 20px;
|
||||
background-color: var(--primary);
|
||||
}
|
||||
|
||||
.title {
|
||||
@@ -49,11 +42,10 @@
|
||||
|
||||
.eyebrow {
|
||||
display: block;
|
||||
margin: 0 2px 10px;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
padding: 16px;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--l1-foreground);
|
||||
}
|
||||
|
||||
@@ -61,7 +53,7 @@
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
padding: 0 16px;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.field {
|
||||
@@ -71,20 +63,19 @@
|
||||
}
|
||||
|
||||
.divider {
|
||||
// flex-shrink:0 keeps the 1px line from collapsing to 0 once the pane
|
||||
// content overflows and the flex column starts shrinking its children.
|
||||
flex-shrink: 0;
|
||||
height: 1px;
|
||||
background: var(--l2-border);
|
||||
margin: 18px 0;
|
||||
}
|
||||
|
||||
.sectionsContainer {
|
||||
padding: 0 16px;
|
||||
background: var(--l1-border);
|
||||
}
|
||||
|
||||
.sections {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
& > * + * {
|
||||
border-top: 1px solid var(--l2-border);
|
||||
& > * {
|
||||
padding: 0 16px;
|
||||
border-top: 1px solid var(--l1-border);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +77,10 @@ function ConfigPane({
|
||||
return (
|
||||
<div className={styles.config}>
|
||||
<header className={styles.heading}>
|
||||
<Typography.Text>Panel settings</Typography.Text>
|
||||
<span className={styles.marker} />
|
||||
<Typography.Text>Panel Details</Typography.Text>
|
||||
</header>
|
||||
<div className={styles.divider} />
|
||||
|
||||
<div className={styles.group}>
|
||||
<div className={styles.field}>
|
||||
@@ -108,7 +110,7 @@ function ConfigPane({
|
||||
<>
|
||||
<div className={styles.divider} />
|
||||
<div className={styles.sectionsContainer}>
|
||||
<span className={styles.eyebrow}>Display</span>
|
||||
<span className={styles.eyebrow}>DISPLAY OPTIONS</span>
|
||||
<div className={styles.sections}>
|
||||
{sections.map((config) => (
|
||||
<SectionSlot
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Plus } from '@signozhq/icons';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { TooltipSimple } from '@signozhq/ui/tooltip';
|
||||
|
||||
interface SectionHeaderQuickAddConfig {
|
||||
label: string;
|
||||
testId: string;
|
||||
}
|
||||
|
||||
interface SectionHeaderQuickAddProps {
|
||||
action: SectionHeaderQuickAddConfig;
|
||||
/** Expands the section and runs the editor's registered add handler. */
|
||||
onClick: () => void;
|
||||
}
|
||||
|
||||
/** Quick-add control rendered in a configuration section's header, beside the chevron. */
|
||||
function SectionHeaderQuickAdd({
|
||||
action,
|
||||
onClick,
|
||||
}: SectionHeaderQuickAddProps): JSX.Element {
|
||||
return (
|
||||
<TooltipSimple title="Quick Add" side="top" arrow>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
aria-label={action.label}
|
||||
// Not `testId`: TooltipTrigger's Slot merge overwrites it with undefined.
|
||||
data-testid={action.testId}
|
||||
onClick={onClick}
|
||||
>
|
||||
<Plus size={15} />
|
||||
</Button>
|
||||
</TooltipSimple>
|
||||
);
|
||||
}
|
||||
|
||||
export default SectionHeaderQuickAdd;
|
||||
@@ -1,3 +1,4 @@
|
||||
import { type ReactNode, useCallback, useRef, useState } from 'react';
|
||||
import type { DashboardtypesPanelSpecDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import {
|
||||
type PanelFormattingSlice,
|
||||
@@ -9,19 +10,41 @@ import {
|
||||
import type { SectionEditorContext } from '../sectionContext';
|
||||
import { resolveSectionEditor } from '../sectionRegistry';
|
||||
import SettingsSection from '../SettingsSection/SettingsSection';
|
||||
import SectionHeaderQuickAdd from './SectionHeaderQuickAdd';
|
||||
|
||||
// `yAxisUnit` is derived from the spec below, not forwarded, so it's omitted.
|
||||
type SectionSlotProps = {
|
||||
config: SectionConfig;
|
||||
spec: DashboardtypesPanelSpecDTO;
|
||||
onChangeSpec: (next: DashboardtypesPanelSpecDTO) => void;
|
||||
} & Omit<SectionEditorContext, 'yAxisUnit'>;
|
||||
} & Omit<SectionEditorContext, 'yAxisUnit' | 'registerHeaderAction'>;
|
||||
|
||||
// Per-section header content; `trigger` expands the section and runs the editor's handler.
|
||||
const SECTION_HEADER_SLOT: Partial<
|
||||
Record<SectionKind, (trigger: () => void) => ReactNode>
|
||||
> = {
|
||||
[SectionKind.Thresholds]: (trigger): ReactNode => (
|
||||
<SectionHeaderQuickAdd
|
||||
action={{
|
||||
label: 'Add Threshold',
|
||||
testId: 'panel-editor-v2-add-threshold-header',
|
||||
}}
|
||||
onClick={trigger}
|
||||
/>
|
||||
),
|
||||
[SectionKind.ContextLinks]: (trigger): ReactNode => (
|
||||
<SectionHeaderQuickAdd
|
||||
action={{
|
||||
label: 'Add Context Link',
|
||||
testId: 'panel-editor-v2-add-link-header',
|
||||
}}
|
||||
onClick={trigger}
|
||||
/>
|
||||
),
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders one configuration section: its collapsible wrapper plus the registered editor
|
||||
* for `config.kind`, wired through the registry's spec lens. Renders nothing when the
|
||||
* kind has no editor yet (sections roll out incrementally), so a kind can declare a
|
||||
* section before its editor exists.
|
||||
* for `config.kind`. Renders nothing when the kind has no editor yet.
|
||||
*/
|
||||
function SectionSlot({
|
||||
config,
|
||||
@@ -36,13 +59,43 @@ function SectionSlot({
|
||||
stepInterval,
|
||||
metricUnit,
|
||||
}: SectionSlotProps): JSX.Element | null {
|
||||
// A kind can hide a section based on current spec state (e.g. Histogram legend once
|
||||
// queries are merged) — skip it before resolving the editor.
|
||||
const editor = resolveSectionEditor(config.kind);
|
||||
// Controlled so the header slot can expand on click; list sections open when populated.
|
||||
const [open, setOpen] = useState(() => {
|
||||
if (config.kind === SectionKind.Visualization) {
|
||||
return true;
|
||||
}
|
||||
const value = editor?.get(spec);
|
||||
return Array.isArray(value) && value.length > 0;
|
||||
});
|
||||
// The editor mounts only while open, so a collapsed-click defers the handler until it registers.
|
||||
const actionHandlerRef = useRef<(() => void) | null>(null);
|
||||
const pendingActionRef = useRef(false);
|
||||
|
||||
const registerHeaderAction = useCallback(
|
||||
(handler: (() => void) | null): void => {
|
||||
actionHandlerRef.current = handler;
|
||||
if (handler && pendingActionRef.current) {
|
||||
pendingActionRef.current = false;
|
||||
handler();
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const triggerHeaderAction = useCallback((): void => {
|
||||
setOpen(true);
|
||||
if (actionHandlerRef.current) {
|
||||
actionHandlerRef.current();
|
||||
} else {
|
||||
pendingActionRef.current = true;
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (config.isHidden?.(spec)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const editor = resolveSectionEditor(config.kind);
|
||||
if (!editor) {
|
||||
return null;
|
||||
}
|
||||
@@ -51,17 +104,19 @@ function SectionSlot({
|
||||
const { Component, get, update } = editor;
|
||||
// Atomic sections carry no `controls`; controlled ones do.
|
||||
const controls = 'controls' in config ? config.controls : undefined;
|
||||
// The panel's formatting unit, forwarded to editors that scope to it (thresholds
|
||||
// restrict their unit picker to this unit's category, as in V1).
|
||||
// Forwarded to editors that scope to the panel's unit (e.g. the thresholds unit picker).
|
||||
const yAxisUnit = (spec.plugin.spec as { formatting?: PanelFormattingSlice })
|
||||
.formatting?.unit;
|
||||
|
||||
const headerSlot = SECTION_HEADER_SLOT[config.kind]?.(triggerHeaderAction);
|
||||
|
||||
return (
|
||||
<SettingsSection
|
||||
title={title}
|
||||
icon={<Icon size={15} />}
|
||||
// Open Visualization by default so the type switcher is visible.
|
||||
defaultOpen={config.kind === SectionKind.Visualization}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
headerSlot={headerSlot}
|
||||
>
|
||||
<Component
|
||||
value={get(spec)}
|
||||
@@ -76,6 +131,7 @@ function SectionSlot({
|
||||
queryType={queryType}
|
||||
stepInterval={stepInterval}
|
||||
metricUnit={metricUnit}
|
||||
registerHeaderAction={registerHeaderAction}
|
||||
/>
|
||||
</SettingsSection>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
import { useState } from 'react';
|
||||
import type { DashboardtypesPanelSpecDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import {
|
||||
type SectionConfig,
|
||||
SectionKind,
|
||||
ThresholdVariant,
|
||||
} from 'pages/DashboardPageV2/DashboardContainer/Panels/types/sections';
|
||||
import { render, screen, userEvent } from 'tests/test-utils';
|
||||
|
||||
import SectionSlot from '../SectionSlot';
|
||||
|
||||
const THRESHOLDS_CONFIG: SectionConfig = {
|
||||
kind: SectionKind.Thresholds,
|
||||
controls: { variant: ThresholdVariant.LABEL },
|
||||
};
|
||||
|
||||
function makeSpec(thresholds: unknown[] = []): DashboardtypesPanelSpecDTO {
|
||||
return {
|
||||
display: { name: 'CPU' },
|
||||
plugin: { kind: 'signoz/TimeSeriesPanel', spec: { thresholds } },
|
||||
queries: [],
|
||||
} as unknown as DashboardtypesPanelSpecDTO;
|
||||
}
|
||||
|
||||
// Stateful harness so onChange feeds back into the spec (as ConfigPane owns it).
|
||||
function Harness({ initial = [] }: { initial?: unknown[] } = {}): JSX.Element {
|
||||
const [spec, setSpec] = useState<DashboardtypesPanelSpecDTO>(
|
||||
makeSpec(initial),
|
||||
);
|
||||
return (
|
||||
<SectionSlot config={THRESHOLDS_CONFIG} spec={spec} onChangeSpec={setSpec} />
|
||||
);
|
||||
}
|
||||
|
||||
describe('SectionSlot header action', () => {
|
||||
it('shows the header "+" while the section is collapsed', () => {
|
||||
render(<Harness />);
|
||||
|
||||
// Collapsed: body (inline add) hidden, but the header quick-add is available.
|
||||
expect(
|
||||
screen.queryByTestId('panel-editor-v2-add-threshold'),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByTestId('panel-editor-v2-add-threshold-header'),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('starts expanded when the section already has items', () => {
|
||||
render(
|
||||
<Harness initial={[{ value: 80, color: '#F5B225', label: 'High' }]} />,
|
||||
);
|
||||
|
||||
// Body is shown on mount (no header click needed) because content exists.
|
||||
expect(
|
||||
screen.getByTestId('panel-editor-v2-add-threshold'),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText('High')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('expands the section and adds a threshold when the header "+" is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<Harness />);
|
||||
|
||||
await user.click(screen.getByTestId('panel-editor-v2-add-threshold-header'));
|
||||
|
||||
// Expanded, with a fresh row opened in edit mode.
|
||||
expect(
|
||||
screen.getByTestId('panel-editor-v2-add-threshold'),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByTestId('threshold-value-0')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,10 +1,19 @@
|
||||
.header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
|
||||
// Disclosure control (icon tile + title); fills the row so the action slot and chevron sit right.
|
||||
.toggle {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
align-items: center;
|
||||
gap: 11px;
|
||||
min-width: 0;
|
||||
padding: 0 !important;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
@@ -37,8 +46,6 @@
|
||||
}
|
||||
|
||||
.chevron {
|
||||
flex: none;
|
||||
color: var(--l2-border);
|
||||
transition: transform 0.15s ease;
|
||||
|
||||
&.open {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type ReactNode, useState } from 'react';
|
||||
import { ChevronDown } from '@signozhq/icons';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import cx from 'classnames';
|
||||
|
||||
@@ -9,45 +10,74 @@ interface SettingsSectionProps {
|
||||
title: string;
|
||||
icon?: ReactNode;
|
||||
defaultOpen?: boolean;
|
||||
/** Controlled open state; when set, the section defers to `onOpenChange`. */
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
/** Rendered between the title and the chevron. */
|
||||
headerSlot?: ReactNode;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapsible container for one configuration section in the V2 panel editor's
|
||||
* ConfigPane. Header shows an icon tile (accented when expanded), the title, and a
|
||||
* rotating chevron; sections are separated by hairline dividers (no surrounding boxes),
|
||||
* matching the Configure-panel design.
|
||||
* Collapsible container for one configuration section in the V2 panel editor's ConfigPane.
|
||||
*/
|
||||
function SettingsSection({
|
||||
title,
|
||||
icon,
|
||||
defaultOpen = false,
|
||||
open,
|
||||
onOpenChange,
|
||||
headerSlot,
|
||||
children,
|
||||
}: SettingsSectionProps): JSX.Element {
|
||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
||||
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
||||
const isControlled = open !== undefined;
|
||||
const isOpen = isControlled ? open : internalOpen;
|
||||
|
||||
const toggle = (): void => {
|
||||
const next = !isOpen;
|
||||
if (!isControlled) {
|
||||
setInternalOpen(next);
|
||||
}
|
||||
onOpenChange?.(next);
|
||||
};
|
||||
|
||||
const serializedTitle = title.toLowerCase().replace(/\s+/g, '-');
|
||||
|
||||
return (
|
||||
<section className={styles.section}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.header}
|
||||
aria-expanded={isOpen}
|
||||
data-testid={`config-section-${serializedTitle}`}
|
||||
onClick={(): void => setIsOpen((prev) => !prev)}
|
||||
>
|
||||
{icon && (
|
||||
<span className={cx(styles.iconTile, { [styles.iconTileOpen]: isOpen })}>
|
||||
{icon}
|
||||
</span>
|
||||
)}
|
||||
<Typography.Text className={styles.title}>{title}</Typography.Text>
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={cx(styles.chevron, { [styles.open]: isOpen })}
|
||||
<div className={styles.header}>
|
||||
<button
|
||||
type="button"
|
||||
className={styles.toggle}
|
||||
aria-expanded={isOpen}
|
||||
data-testid={`config-section-${serializedTitle}`}
|
||||
onClick={toggle}
|
||||
>
|
||||
{icon && (
|
||||
<span className={cx(styles.iconTile, { [styles.iconTileOpen]: isOpen })}>
|
||||
{icon}
|
||||
</span>
|
||||
)}
|
||||
<Typography.Text className={styles.title}>{title}</Typography.Text>
|
||||
</button>
|
||||
{headerSlot}
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
color="secondary"
|
||||
size="icon"
|
||||
prefix={
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={cx(styles.chevron, { [styles.open]: isOpen })}
|
||||
/>
|
||||
}
|
||||
aria-label={isOpen ? `Collapse ${title}` : `Expand ${title}`}
|
||||
tabIndex={-1}
|
||||
onClick={toggle}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
{isOpen && <div className={styles.body}>{children}</div>}
|
||||
</section>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import SettingsSection from '../SettingsSection';
|
||||
|
||||
describe('SettingsSection', () => {
|
||||
it('renders an arbitrary headerSlot node beside the header', () => {
|
||||
render(
|
||||
<SettingsSection
|
||||
title="Thresholds"
|
||||
headerSlot={
|
||||
<button type="button" aria-label="custom action" data-testid="my-action" />
|
||||
}
|
||||
>
|
||||
<div>body</div>
|
||||
</SettingsSection>,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('my-action')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('is collapsed by default: hides the body until the header is clicked', async () => {
|
||||
const user = userEvent.setup();
|
||||
render(
|
||||
<SettingsSection title="Thresholds">
|
||||
<div data-testid="body">body</div>
|
||||
</SettingsSection>,
|
||||
);
|
||||
|
||||
expect(screen.queryByTestId('body')).not.toBeInTheDocument();
|
||||
|
||||
await user.click(screen.getByTestId('config-section-thresholds'));
|
||||
expect(screen.getByTestId('body')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('defers to onOpenChange when open is controlled', async () => {
|
||||
const user = userEvent.setup();
|
||||
const onOpenChange = jest.fn();
|
||||
const { rerender } = render(
|
||||
<SettingsSection title="Thresholds" open={false} onOpenChange={onOpenChange}>
|
||||
<div data-testid="body">body</div>
|
||||
</SettingsSection>,
|
||||
);
|
||||
|
||||
expect(screen.queryByTestId('body')).not.toBeInTheDocument();
|
||||
await user.click(screen.getByTestId('config-section-thresholds'));
|
||||
expect(onOpenChange).toHaveBeenCalledWith(true);
|
||||
|
||||
rerender(
|
||||
<SettingsSection title="Thresholds" open onOpenChange={onOpenChange}>
|
||||
<div data-testid="body">body</div>
|
||||
</SettingsSection>,
|
||||
);
|
||||
expect(screen.getByTestId('body')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,20 +1,13 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { useState } from 'react';
|
||||
import type {
|
||||
DashboardtypesPanelDTO,
|
||||
DashboardtypesPanelSpecDTO,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import { render, screen, userEvent } from 'tests/test-utils';
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
|
||||
import ConfigPane from '../ConfigPane';
|
||||
|
||||
// The Actions group's hook navigates/logs; stub it so ConfigPane renders without a router.
|
||||
jest.mock(
|
||||
'pages/DashboardPageV2/DashboardContainer/PanelsAndSectionsLayout/Panel/hooks/useCreateAlertFromPanel',
|
||||
() => ({
|
||||
useCreateAlertFromPanel: (): jest.Mock => jest.fn(),
|
||||
}),
|
||||
);
|
||||
|
||||
function spec(unit?: string): DashboardtypesPanelSpecDTO {
|
||||
return {
|
||||
display: { name: 'CPU', description: 'usage' },
|
||||
@@ -40,7 +33,23 @@ function renderConfigPane(
|
||||
panelId: 'panel-1',
|
||||
...overrides,
|
||||
};
|
||||
render(<ConfigPane {...props} />);
|
||||
|
||||
// Stateful so typed edits feed back into the spec, as the panel editor owns it.
|
||||
function Harness(): JSX.Element {
|
||||
const [currentSpec, setCurrentSpec] = useState(props.spec);
|
||||
return (
|
||||
<ConfigPane
|
||||
{...props}
|
||||
spec={currentSpec}
|
||||
onChangeSpec={(next): void => {
|
||||
props.onChangeSpec(next);
|
||||
setCurrentSpec(next);
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render(<Harness />);
|
||||
return props;
|
||||
}
|
||||
|
||||
@@ -54,14 +63,15 @@ describe('ConfigPane', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('reports title edits through onChangeSpec (into spec.display)', () => {
|
||||
it('reports title edits through onChangeSpec (into spec.display)', async () => {
|
||||
const user = userEvent.setup();
|
||||
const { onChangeSpec } = renderConfigPane();
|
||||
|
||||
fireEvent.change(screen.getByTestId('panel-editor-v2-title'), {
|
||||
target: { value: 'Memory' },
|
||||
});
|
||||
const title = screen.getByTestId('panel-editor-v2-title');
|
||||
await user.clear(title);
|
||||
await user.type(title, 'Memory');
|
||||
|
||||
expect(onChangeSpec).toHaveBeenCalledWith(
|
||||
expect(onChangeSpec).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({
|
||||
display: { name: 'Memory', description: 'usage' },
|
||||
}),
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
// Fill the section field so the select lines up with the other full-width controls.
|
||||
.select {
|
||||
width: 100%;
|
||||
|
||||
:global(.ant-select-selector) {
|
||||
border-color: var(--l2-border) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.item {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
gap: 12px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--l2-border);
|
||||
border-radius: 6px;
|
||||
border-radius: 2px;
|
||||
background: var(--l2-background-60);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@use '../../../../../../../styles/scrollbar' as *;
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -5,6 +7,7 @@
|
||||
}
|
||||
|
||||
.list {
|
||||
@include custom-scrollbar;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,4 +21,6 @@ export interface SectionEditorContext {
|
||||
stepInterval?: number;
|
||||
/** Unit the selected metric was sent with; drives the unit selector's mismatch warning. */
|
||||
metricUnit?: string;
|
||||
/** An editor registers the handler its header action (e.g. a quick-add "+") triggers; `null` to clear. */
|
||||
registerHeaderAction?: (handler: (() => void) | null) => void;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Plus } from '@signozhq/icons';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import type { DashboardtypesLinkDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
SectionKind,
|
||||
} from 'pages/DashboardPageV2/DashboardContainer/Panels/types/sections';
|
||||
|
||||
import type { SectionEditorContext } from '../../sectionContext';
|
||||
import ContextLinkDialog from './ContextLinkDialog';
|
||||
import ContextLinkListItem from './ContextLinkListItem';
|
||||
import { useContextLinkVariables } from './useContextLinkVariables';
|
||||
@@ -21,7 +22,9 @@ import styles from './ContextLinksSection.module.scss';
|
||||
function ContextLinksSection({
|
||||
value,
|
||||
onChange,
|
||||
}: SectionEditorProps<SectionKind.ContextLinks>): JSX.Element {
|
||||
registerHeaderAction,
|
||||
}: SectionEditorProps<SectionKind.ContextLinks> &
|
||||
Pick<SectionEditorContext, 'registerHeaderAction'>): JSX.Element {
|
||||
const links = value ?? [];
|
||||
const variables = useContextLinkVariables();
|
||||
|
||||
@@ -31,6 +34,16 @@ function ContextLinksSection({
|
||||
index: null,
|
||||
});
|
||||
|
||||
const openAddDialog = useCallback(
|
||||
(): void => setDialog({ open: true, index: null }),
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
registerHeaderAction?.(openAddDialog);
|
||||
return (): void => registerHeaderAction?.(null);
|
||||
}, [registerHeaderAction, openAddDialog]);
|
||||
|
||||
const removeAt = (index: number): void =>
|
||||
onChange(links.filter((_, i) => i !== index));
|
||||
|
||||
@@ -66,7 +79,7 @@ function ContextLinksSection({
|
||||
color="secondary"
|
||||
prefix={<Plus size={14} />}
|
||||
data-testid="panel-editor-v2-add-link"
|
||||
onClick={(): void => setDialog({ open: true, index: null })}
|
||||
onClick={openAddDialog}
|
||||
>
|
||||
Add Context Link
|
||||
</Button>
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
:global(.ant-select) {
|
||||
width: 100%;
|
||||
}
|
||||
:global(.ant-select-selector) {
|
||||
border-color: var(--l2-border) !important;
|
||||
}
|
||||
}
|
||||
|
||||
// Stacked per-column unit pickers; each column keeps the standard field layout.
|
||||
|
||||
@@ -96,6 +96,9 @@
|
||||
:global(.ant-select) {
|
||||
width: 100%;
|
||||
}
|
||||
:global(.ant-select-selector) {
|
||||
border-color: var(--l2-border) !important;
|
||||
}
|
||||
}
|
||||
|
||||
.invalidUnit {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useRef, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { Plus } from '@signozhq/icons';
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import {
|
||||
@@ -63,7 +63,10 @@ type ThresholdsSectionProps = {
|
||||
/** `variant` picks the row editor + element shape; defaults to `label`. */
|
||||
controls?: { variant?: ThresholdVariant };
|
||||
onChange: (next: AnyThreshold[]) => void;
|
||||
} & Pick<SectionEditorContext, 'yAxisUnit' | 'tableColumns'>;
|
||||
} & Pick<
|
||||
SectionEditorContext,
|
||||
'yAxisUnit' | 'tableColumns' | 'registerHeaderAction'
|
||||
>;
|
||||
|
||||
/**
|
||||
* Edits the `thresholds` slice for every panel kind. All variants share the same
|
||||
@@ -77,6 +80,7 @@ function ThresholdsSection({
|
||||
onChange,
|
||||
yAxisUnit,
|
||||
tableColumns = [],
|
||||
registerHeaderAction,
|
||||
}: ThresholdsSectionProps): JSX.Element {
|
||||
const variant = controls?.variant ?? ThresholdVariant.LABEL;
|
||||
const thresholds = value ?? [];
|
||||
@@ -93,12 +97,17 @@ function ThresholdsSection({
|
||||
onChange(thresholds.map((t, i) => (i === index ? next : t)));
|
||||
};
|
||||
|
||||
const addThreshold = (): void => {
|
||||
const nextIndex = thresholds.length;
|
||||
onChange([...thresholds, defaultThreshold(variant, tableColumns)]);
|
||||
setEditingIndex(nextIndex);
|
||||
setUnsavedIndex(nextIndex);
|
||||
};
|
||||
const addThreshold = useCallback((): void => {
|
||||
const current = value ?? [];
|
||||
onChange([...current, defaultThreshold(variant, tableColumns)]);
|
||||
setEditingIndex(current.length);
|
||||
setUnsavedIndex(current.length);
|
||||
}, [value, onChange, variant, tableColumns]);
|
||||
|
||||
useEffect(() => {
|
||||
registerHeaderAction?.(addThreshold);
|
||||
return (): void => registerHeaderAction?.(null);
|
||||
}, [registerHeaderAction, addThreshold]);
|
||||
|
||||
const beginEdit = (index: number): void => {
|
||||
editSnapshot.current = thresholds[index] ?? null;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { DialogWrapper } from '@signozhq/ui/dialog';
|
||||
import { Divider } from '@signozhq/ui/divider';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import HeaderRightSection from 'components/HeaderRightSection/HeaderRightSection';
|
||||
import { useConfirmableAction } from 'hooks/useConfirmableAction';
|
||||
import { DashboardDetailEvents } from 'pages/DashboardPageV2/constants/events';
|
||||
|
||||
@@ -67,6 +68,11 @@ function Header({
|
||||
<Typography.Text>Configure panel</Typography.Text>
|
||||
</div>
|
||||
<div className={styles.actions}>
|
||||
<HeaderRightSection
|
||||
enableAnnouncements={false}
|
||||
enableShare={false}
|
||||
enableFeedback={false}
|
||||
/>
|
||||
{showSwitchToView && (
|
||||
<Button
|
||||
variant="outlined"
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { TooltipProvider } from '@signozhq/ui/tooltip';
|
||||
import { useIsAIAssistantEnabled } from 'hooks/useIsAIAssistantEnabled';
|
||||
|
||||
import Header from '../Header';
|
||||
|
||||
jest.mock('hooks/useIsAIAssistantEnabled', () => ({
|
||||
useIsAIAssistantEnabled: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock('hooks/useGetTenantLicense', () => ({
|
||||
useGetTenantLicense: (): unknown => ({
|
||||
isCloudUser: true,
|
||||
isEnterpriseSelfHostedUser: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('api/common/logEvent', () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockUseIsAIAssistantEnabled = useIsAIAssistantEnabled as jest.Mock;
|
||||
|
||||
function renderHeader(): void {
|
||||
// AppLayout supplies the TooltipProvider in the app; the header is rendered bare here.
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<TooltipProvider>
|
||||
<Header
|
||||
isDirty={false}
|
||||
isSaving={false}
|
||||
onSave={jest.fn()}
|
||||
onClose={jest.fn()}
|
||||
/>
|
||||
</TooltipProvider>
|
||||
</MemoryRouter>,
|
||||
);
|
||||
}
|
||||
|
||||
describe('PanelEditor Header', () => {
|
||||
afterEach(() => {
|
||||
mockUseIsAIAssistantEnabled.mockReset();
|
||||
});
|
||||
|
||||
// The editor is a full page, so the side nav's Noz entry point is gone while it is
|
||||
// open — the header has to offer it instead.
|
||||
it('offers Noz alongside the editor actions', () => {
|
||||
mockUseIsAIAssistantEnabled.mockReturnValue(true);
|
||||
|
||||
renderHeader();
|
||||
|
||||
expect(screen.getByRole('button', { name: 'Open Noz' })).toBeInTheDocument();
|
||||
expect(screen.getByTestId('panel-editor-v2-save')).toBeInTheDocument();
|
||||
expect(screen.getByTestId('panel-editor-v2-close')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('omits Noz when the AI assistant is disabled', () => {
|
||||
mockUseIsAIAssistantEnabled.mockReturnValue(false);
|
||||
|
||||
renderHeader();
|
||||
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'Open Noz' }),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.getByTestId('panel-editor-v2-save')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -9,7 +9,7 @@ import type { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { AllTheProviders } from 'tests/test-utils';
|
||||
|
||||
import { toPerses } from '../../../queryV5/persesQueryAdapters';
|
||||
import { fromPerses, toPerses } from '../../../queryV5/persesQueryAdapters';
|
||||
import { usePanelEditorQuerySync } from '../usePanelEditorQuerySync';
|
||||
|
||||
// Exercises the REAL query builder provider (not mocks) so the dirty check is
|
||||
@@ -45,6 +45,28 @@ function makePanel(queries: DashboardtypesQueryDTO[]): DashboardtypesPanelDTO {
|
||||
} as unknown as DashboardtypesPanelDTO;
|
||||
}
|
||||
|
||||
/** Providers whose URL already carries `query` as the compositeQuery param (a mid-edit refresh). */
|
||||
function makeUrlWrapper(
|
||||
query: Query,
|
||||
): ({ children }: { children: React.ReactNode }) => JSX.Element {
|
||||
const params = new URLSearchParams();
|
||||
params.set(
|
||||
QueryParams.compositeQuery,
|
||||
encodeURIComponent(JSON.stringify(query)),
|
||||
);
|
||||
return function UrlWrapper({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}): JSX.Element {
|
||||
return (
|
||||
<AllTheProviders initialRoute={`/?${params.toString()}`}>
|
||||
{children}
|
||||
</AllTheProviders>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
describe('usePanelEditorQuerySync (real query builder)', () => {
|
||||
it('an untouched existing panel is NOT query-dirty on mount', async () => {
|
||||
const saved = makeSavedQueries();
|
||||
@@ -112,6 +134,80 @@ describe('usePanelEditorQuerySync (real query builder)', () => {
|
||||
expect(result.current.isQueryDirty).toBe(false);
|
||||
});
|
||||
|
||||
it('a saved panel with no `having` is NOT dirty on mount (builder seeds an empty having)', async () => {
|
||||
// Reproduces the reported bug: a panel saved as a bare signoz/BuilderQuery that never
|
||||
// carried a `having`. On editor open the builder hydrates from the URL and
|
||||
// prepareQueryBuilderData seeds an empty `{ expression: '' }`, so a verbatim envelope
|
||||
// compare flags the untouched panel as dirty. Seed via the URL (not resetQuery) so the
|
||||
// hydration path that synthesizes the having actually runs.
|
||||
const savedNoHaving: DashboardtypesQueryDTO[] = [
|
||||
{
|
||||
kind: 'time_series',
|
||||
spec: {
|
||||
name: 'A',
|
||||
plugin: {
|
||||
kind: 'signoz/BuilderQuery',
|
||||
spec: {
|
||||
name: 'A',
|
||||
signal: 'metrics',
|
||||
source: '',
|
||||
aggregations: [
|
||||
{
|
||||
metricName: 'signoz_latency.bucket',
|
||||
temporality: 'delta',
|
||||
timeAggregation: '',
|
||||
spaceAggregation: 'p99',
|
||||
},
|
||||
],
|
||||
disabled: false,
|
||||
filter: { expression: 'service.name IN $service_name' },
|
||||
groupBy: [
|
||||
{
|
||||
name: 'service.name',
|
||||
signal: '',
|
||||
fieldContext: 'resource',
|
||||
fieldDataType: '',
|
||||
},
|
||||
],
|
||||
order: [
|
||||
{
|
||||
key: {
|
||||
name: '__result',
|
||||
signal: '',
|
||||
fieldContext: '',
|
||||
fieldDataType: '',
|
||||
},
|
||||
direction: 'desc',
|
||||
},
|
||||
],
|
||||
limit: 100,
|
||||
legend: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
] as unknown as DashboardtypesQueryDTO[];
|
||||
|
||||
// The editor puts the (having-less) seed query into the URL; the provider then hydrates
|
||||
// from it, which is where the empty having is added.
|
||||
const seededInUrl = fromPerses(savedNoHaving, panelType);
|
||||
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
usePanelEditorQuerySync({
|
||||
draft: makePanel(savedNoHaving),
|
||||
panelType,
|
||||
setSpec: jest.fn(),
|
||||
refetch: jest.fn(),
|
||||
savedQueries: savedNoHaving,
|
||||
}),
|
||||
{ wrapper: makeUrlWrapper(seededInUrl) },
|
||||
);
|
||||
|
||||
await waitFor(() => expect(result.current.isQueryDirty).toBe(false));
|
||||
expect(result.current.isQueryDirty).toBe(false);
|
||||
});
|
||||
|
||||
it('retains an in-editor query edit carried in the URL across a refresh (and reads dirty)', async () => {
|
||||
// Simulate a refresh mid-edit: the saved panel is unchanged, but the URL still
|
||||
// carries the last-run (edited) query. The builder must hydrate from the URL —
|
||||
@@ -130,23 +226,8 @@ describe('usePanelEditorQuerySync (real query builder)', () => {
|
||||
],
|
||||
},
|
||||
};
|
||||
const params = new URLSearchParams();
|
||||
params.set(
|
||||
QueryParams.compositeQuery,
|
||||
encodeURIComponent(JSON.stringify(editedInUrl)),
|
||||
);
|
||||
const setSpec = jest.fn();
|
||||
|
||||
const wrapper = ({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}): JSX.Element => (
|
||||
<AllTheProviders initialRoute={`/?${params.toString()}`}>
|
||||
{children}
|
||||
</AllTheProviders>
|
||||
);
|
||||
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
usePanelEditorQuerySync({
|
||||
@@ -157,7 +238,7 @@ describe('usePanelEditorQuerySync (real query builder)', () => {
|
||||
refetch: jest.fn(),
|
||||
savedQueries: saved,
|
||||
}),
|
||||
{ wrapper },
|
||||
{ wrapper: makeUrlWrapper(editedInUrl) },
|
||||
);
|
||||
|
||||
// The URL edit is retained → dirty, and it's synced into the draft so the
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
@use '../../../../../../styles/scrollbar' as *;
|
||||
|
||||
// Centred, vertically-stacked panel state (no query / no data / error). Fills
|
||||
// the panel body below the header and centres its content both axes.
|
||||
// the panel body below the header and centres its content both axes. When the
|
||||
// panel is too small to fit icon + text + actions, it scrolls instead of
|
||||
// clipping the buttons at the edge (`safe center` keeps the top reachable).
|
||||
.message {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
justify-content: safe center;
|
||||
gap: 6px;
|
||||
padding: 16px;
|
||||
text-align: center;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
overflow: auto;
|
||||
|
||||
// Match the shared panel scrollbar (chart legend, table/list panels).
|
||||
@include custom-scrollbar;
|
||||
}
|
||||
|
||||
// Muted glyph in a soft tinted disc so the icon reads as decorative chrome
|
||||
@@ -51,4 +59,5 @@
|
||||
justify-content: center;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ describe('preparePieData', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('keeps one slice per group row for a single value column', () => {
|
||||
it('serialises a single group-by column as {key="value"} (V1 parity)', () => {
|
||||
const table = tableWith(
|
||||
[
|
||||
{
|
||||
@@ -53,8 +53,59 @@ describe('preparePieData', () => {
|
||||
const slices = preparePieData(args([table]));
|
||||
|
||||
expect(slices.map((s) => [s.label, s.value])).toStrictEqual([
|
||||
['adservice', 100],
|
||||
['cartservice', 200],
|
||||
['{service.name="adservice"}', 100],
|
||||
['{service.name="cartservice"}', 200],
|
||||
]);
|
||||
});
|
||||
|
||||
it('serialises a grouped metrics query as {direction="write"} (V1 parity)', () => {
|
||||
const table = tableWith(
|
||||
[
|
||||
{
|
||||
name: 'direction',
|
||||
queryName: 'A',
|
||||
isValueColumn: false,
|
||||
id: 'direction',
|
||||
},
|
||||
{ name: 'A', queryName: 'A', isValueColumn: true, id: 'A' },
|
||||
],
|
||||
[
|
||||
{ data: { direction: 'write', A: 3170000000 } },
|
||||
{ data: { direction: 'read', A: 10000000 } },
|
||||
],
|
||||
);
|
||||
|
||||
const slices = preparePieData(args([table]));
|
||||
|
||||
expect(slices.map((s) => s.label)).toStrictEqual([
|
||||
'{direction="write"}',
|
||||
'{direction="read"}',
|
||||
]);
|
||||
});
|
||||
|
||||
it('substitutes a legend format template with the group-by values', () => {
|
||||
const table = tableWith(
|
||||
[
|
||||
{
|
||||
name: 'service.name',
|
||||
queryName: 'A',
|
||||
isValueColumn: false,
|
||||
id: 'service.name',
|
||||
},
|
||||
{ name: 'count', queryName: 'A', isValueColumn: true, id: 'A' },
|
||||
],
|
||||
[
|
||||
{ data: { 'service.name': 'adservice', A: 100 } },
|
||||
{ data: { 'service.name': 'cartservice', A: 200 } },
|
||||
],
|
||||
{ legend: 'service.name = {{service.name}}' },
|
||||
);
|
||||
|
||||
const slices = preparePieData(args([table]));
|
||||
|
||||
expect(slices.map((s) => s.label)).toStrictEqual([
|
||||
'service.name = adservice',
|
||||
'service.name = cartservice',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { themeColors } from 'constants/theme';
|
||||
import type { PieSlice } from 'container/DashboardContainer/visualization/charts/types';
|
||||
import getLabelName from 'lib/getLabelName';
|
||||
import { generateColor } from 'lib/uPlotLib/utils/generateColor';
|
||||
import type { PanelTable } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
|
||||
|
||||
@@ -51,7 +52,8 @@ export function preparePieData({
|
||||
if (hasMultipleValueColumns) {
|
||||
label = groupLabel ? `${groupLabel} · ${column.name}` : column.name;
|
||||
} else {
|
||||
label = groupLabel || table.legend || table.queryName || '';
|
||||
// V1 parity: serialise group-by labels as `{key="value"}`.
|
||||
label = getLabelName(labels, table.queryName || '', table.legend || '');
|
||||
}
|
||||
|
||||
const color = customColors?.[label] ?? generateColor(label, colorMap);
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import type { PanelTableColumn } from 'pages/DashboardPageV2/DashboardContainer/queryV5/types';
|
||||
|
||||
import { formatTableCellText } from '../tableColumns';
|
||||
|
||||
jest.mock('../../../utils/formatPanelValue', () => ({
|
||||
formatPanelValue: (value: number, unit?: string): string =>
|
||||
`${value}${unit ?? ''}`,
|
||||
}));
|
||||
|
||||
const valueColumn: PanelTableColumn = {
|
||||
name: 'p99',
|
||||
queryName: 'A',
|
||||
isValueColumn: true,
|
||||
id: 'A',
|
||||
};
|
||||
|
||||
const groupColumn: PanelTableColumn = {
|
||||
name: 'service',
|
||||
queryName: 'A',
|
||||
isValueColumn: false,
|
||||
id: 'service',
|
||||
};
|
||||
|
||||
describe('formatTableCellText', () => {
|
||||
it.each([null, undefined, ''])(
|
||||
'renders empty value-column cells (%p) as n/a instead of 0',
|
||||
(raw) => {
|
||||
expect(formatTableCellText(valueColumn, raw, 'ms', undefined)).toBe('n/a');
|
||||
},
|
||||
);
|
||||
|
||||
it('keeps a real zero as a formatted 0, not n/a', () => {
|
||||
expect(formatTableCellText(valueColumn, 0, 'ms', undefined)).toBe('0ms');
|
||||
});
|
||||
|
||||
it('formats a numeric value column through unit + precision', () => {
|
||||
expect(formatTableCellText(valueColumn, 1234, 'ms', undefined)).toBe(
|
||||
'1234ms',
|
||||
);
|
||||
});
|
||||
|
||||
it('renders a non-numeric value cell as raw text', () => {
|
||||
expect(formatTableCellText(valueColumn, 'n/a', 'ms', undefined)).toBe('n/a');
|
||||
});
|
||||
|
||||
it.each([null, undefined, ''])(
|
||||
'renders empty group-column cells (%p) as n/a',
|
||||
(raw) => {
|
||||
expect(formatTableCellText(groupColumn, raw, undefined, undefined)).toBe(
|
||||
'n/a',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it('renders group-column labels as raw text', () => {
|
||||
expect(
|
||||
formatTableCellText(groupColumn, 'frontend', undefined, undefined),
|
||||
).toBe('frontend');
|
||||
});
|
||||
});
|
||||
@@ -64,6 +64,19 @@ describe('buildTableCsvRows', () => {
|
||||
|
||||
expect(rows).toStrictEqual([{ service: 'api', p99: 'n/a' }]);
|
||||
});
|
||||
|
||||
it('exports empty value cells as n/a rather than 0', () => {
|
||||
const rows = buildTableCsvRows({
|
||||
table: {
|
||||
...table,
|
||||
rows: [{ data: { service: 'api', A: null } }],
|
||||
},
|
||||
columnUnits: { A: 'ms' },
|
||||
decimalPrecision: undefined,
|
||||
});
|
||||
|
||||
expect(rows).toStrictEqual([{ service: 'api', p99: 'n/a' }]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getTableCsvRows', () => {
|
||||
|
||||
@@ -18,6 +18,17 @@ import styles from './TablePanel.module.scss';
|
||||
/** A prepared scalar-table row flattened for the antd Table, with the antd key. */
|
||||
export type TableRowData = Record<string, unknown> & { key: number };
|
||||
|
||||
const NA_TEXT = 'n/a';
|
||||
|
||||
// Empty cells (null/undefined/'') aren't numbers: `Number(null)` is 0, which
|
||||
// would render/colour/sort an empty cell as a real zero.
|
||||
function toCellNumber(raw: unknown): number {
|
||||
if (raw == null || raw === '') {
|
||||
return NaN;
|
||||
}
|
||||
return Number(raw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Groups table thresholds by the column they target, mapping each onto the
|
||||
* V2-native `PanelThreshold` consumed by `resolveActiveThreshold`. A column with
|
||||
@@ -43,6 +54,9 @@ export function formatTableCellText(
|
||||
unit: string | undefined,
|
||||
decimalPrecision?: PrecisionOption,
|
||||
): string {
|
||||
if (raw == null || raw === '') {
|
||||
return NA_TEXT;
|
||||
}
|
||||
if (!col.isValueColumn) {
|
||||
return coerceToString(raw);
|
||||
}
|
||||
@@ -56,15 +70,17 @@ export function formatTableCellText(
|
||||
// Sort comparator: numeric when both cells parse as numbers (value columns and
|
||||
// numeric group keys), otherwise a locale string compare. Nullish sorts last.
|
||||
function compareCells(a: unknown, b: unknown): number {
|
||||
const aNum = Number(a);
|
||||
const bNum = Number(b);
|
||||
const aNum = toCellNumber(a);
|
||||
const bNum = toCellNumber(b);
|
||||
if (Number.isFinite(aNum) && Number.isFinite(bNum)) {
|
||||
return aNum - bNum;
|
||||
}
|
||||
if (a == null) {
|
||||
return b == null ? 0 : 1;
|
||||
const aEmpty = a == null || a === '';
|
||||
const bEmpty = b == null || b === '';
|
||||
if (aEmpty) {
|
||||
return bEmpty ? 0 : 1;
|
||||
}
|
||||
if (b == null) {
|
||||
if (bEmpty) {
|
||||
return -1;
|
||||
}
|
||||
return coerceToString(a).localeCompare(coerceToString(b));
|
||||
@@ -113,7 +129,7 @@ export function buildTableColumns({
|
||||
compareCells(a[key], b[key]),
|
||||
render: (raw: unknown): React.ReactNode => {
|
||||
const text = formatTableCellText(col, raw, unit, decimalPrecision);
|
||||
const num = Number(raw);
|
||||
const num = toCellNumber(raw);
|
||||
if (
|
||||
!col.isValueColumn ||
|
||||
colThresholds.length === 0 ||
|
||||
@@ -131,7 +147,7 @@ export function buildTableColumns({
|
||||
const cellProps: React.HTMLAttributes<HTMLElement> = {};
|
||||
|
||||
if (col.isValueColumn && colThresholds.length > 0) {
|
||||
const num = Number(record[key]);
|
||||
const num = toCellNumber(record[key]);
|
||||
if (Number.isFinite(num)) {
|
||||
const { threshold } = resolveActiveThreshold(colThresholds, num, unit);
|
||||
if (threshold?.format === 'background') {
|
||||
|
||||
@@ -14,15 +14,16 @@ import type {
|
||||
TelemetrytypesTelemetryFieldKeyDTO,
|
||||
} from 'api/generated/services/sigNoz.schemas';
|
||||
import {
|
||||
Antenna,
|
||||
BarChart,
|
||||
Columns3,
|
||||
Hash,
|
||||
Layers,
|
||||
LayoutDashboard,
|
||||
Link,
|
||||
Link2,
|
||||
Palette,
|
||||
Ruler,
|
||||
SlidersHorizontal,
|
||||
PencilRuler,
|
||||
Scale3D,
|
||||
Signpost,
|
||||
Wallpaper,
|
||||
} from '@signozhq/icons';
|
||||
|
||||
// Derived from an actual icon component so the type stays exact (size is a
|
||||
@@ -157,14 +158,14 @@ export type SectionConfig =
|
||||
// Per-section title + sidebar icon. Pure data; the editor component + spec lens
|
||||
// live in the ConfigPane section registry.
|
||||
export const SECTION_METADATA = {
|
||||
[SectionKind.Formatting]: { title: 'Formatting & Units', icon: Hash },
|
||||
[SectionKind.Axes]: { title: 'Axes', icon: Ruler },
|
||||
[SectionKind.Legend]: { title: 'Legend', icon: Layers },
|
||||
[SectionKind.Formatting]: { title: 'Formatting & Units', icon: PencilRuler },
|
||||
[SectionKind.Axes]: { title: 'Axes', icon: Scale3D },
|
||||
[SectionKind.Legend]: { title: 'Legend', icon: Signpost },
|
||||
[SectionKind.ChartAppearance]: { title: 'Chart appearance', icon: Palette },
|
||||
[SectionKind.Visualization]: { title: 'Visualization', icon: LayoutDashboard },
|
||||
[SectionKind.Visualization]: { title: 'Visualization', icon: Wallpaper },
|
||||
[SectionKind.Buckets]: { title: 'Histogram / Buckets', icon: BarChart },
|
||||
[SectionKind.Thresholds]: { title: 'Thresholds', icon: SlidersHorizontal },
|
||||
[SectionKind.ContextLinks]: { title: 'Context Links', icon: Link },
|
||||
[SectionKind.Thresholds]: { title: 'Thresholds', icon: Antenna },
|
||||
[SectionKind.ContextLinks]: { title: 'Context Links', icon: Link2 },
|
||||
[SectionKind.Columns]: { title: 'Columns', icon: Columns3 },
|
||||
} as const satisfies Record<SectionKind, SectionMetadata>;
|
||||
|
||||
|
||||
@@ -67,6 +67,16 @@
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
// The values behind a pill's `+N`, one bullet each, width-capped so a long value
|
||||
// wraps instead of stretching the tooltip off-screen.
|
||||
.overflowValues {
|
||||
max-width: 360px;
|
||||
margin: 0;
|
||||
padding-left: 14px;
|
||||
list-style: disc outside;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
// Shared by the Text and value selectors: strips the antd control chrome so the
|
||||
// selector blends into the variable pill.
|
||||
.control {
|
||||
@@ -128,13 +138,3 @@
|
||||
min-width: 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.overflowTooltip {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.overflowName {
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
|
||||
@@ -9,28 +9,13 @@ import { selectVariablesExpanded } from '../store/slices/collapseSlice';
|
||||
import { useDashboardStore } from '../store/useDashboardStore';
|
||||
import AddVariableFull from './components/AddVariable/AddVariableFull';
|
||||
import AddVariableIcon from './components/AddVariable/AddVariableIcon';
|
||||
import type { VariableSelection } from './selectionTypes';
|
||||
import { TOOLTIP_SCROLL_CONTENT_CLASS } from 'components/TooltipScrollArea/TooltipScrollArea';
|
||||
|
||||
import HiddenVariablesTooltip from './components/HiddenVariablesTooltip/HiddenVariablesTooltip';
|
||||
import { useVariableSelection } from './hooks/useVariableSelection';
|
||||
import VariableSelector from './components/VariableSelector/VariableSelector';
|
||||
import styles from './VariablesBar.module.scss';
|
||||
|
||||
// Short display of a variable's current selection, for the collapsed +N tooltip.
|
||||
function formatSelection(selection: VariableSelection | undefined): string {
|
||||
if (!selection) {
|
||||
return '—';
|
||||
}
|
||||
if (selection.allSelected) {
|
||||
return 'ALL';
|
||||
}
|
||||
const { value } = selection;
|
||||
if (Array.isArray(value)) {
|
||||
return value.length > 0 ? value.join(', ') : '—';
|
||||
}
|
||||
return value === '' || value === null || value === undefined
|
||||
? '—'
|
||||
: String(value);
|
||||
}
|
||||
|
||||
interface VariablesBarProps {
|
||||
dashboard: DashboardtypesGettableDashboardV2DTO;
|
||||
}
|
||||
@@ -130,15 +115,12 @@ function VariablesBar({ dashboard }: VariablesBarProps): JSX.Element | null {
|
||||
) : (
|
||||
<TooltipSimple
|
||||
side="top"
|
||||
tooltipContentProps={{ className: TOOLTIP_SCROLL_CONTENT_CLASS }}
|
||||
title={
|
||||
<div className={styles.overflowTooltip}>
|
||||
{hiddenVariables.map((variable) => (
|
||||
<div key={variable.name}>
|
||||
<span className={styles.overflowName}>{variable.name}</span>:{' '}
|
||||
{formatSelection(selection[variable.name])}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<HiddenVariablesTooltip
|
||||
variables={hiddenVariables}
|
||||
selections={selection}
|
||||
/>
|
||||
}
|
||||
>
|
||||
{moreButton}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
import {
|
||||
emptyVariableFormModel,
|
||||
type VariableFormModel,
|
||||
} from '../../DashboardSettings/Variables/variableFormModel';
|
||||
import type { VariableSelectionMap } from '../selectionTypes';
|
||||
import HiddenVariablesTooltip from '../components/HiddenVariablesTooltip/HiddenVariablesTooltip';
|
||||
|
||||
function variable(name: string): VariableFormModel {
|
||||
return { ...emptyVariableFormModel(), name };
|
||||
}
|
||||
|
||||
function renderTooltip(
|
||||
names: string[],
|
||||
selections: VariableSelectionMap,
|
||||
): HTMLElement {
|
||||
render(
|
||||
<HiddenVariablesTooltip
|
||||
variables={names.map(variable)}
|
||||
selections={selections}
|
||||
/>,
|
||||
);
|
||||
return screen.getByTestId('hidden-variables-tooltip');
|
||||
}
|
||||
|
||||
describe('HiddenVariablesTooltip', () => {
|
||||
it('names each hidden variable with a $ prefix, apart from its value', () => {
|
||||
renderTooltip(['env', 'service'], {
|
||||
env: { value: 'production', allSelected: false },
|
||||
service: { value: ['checkout', 'cart'], allSelected: false },
|
||||
});
|
||||
|
||||
expect(screen.getByText('$env')).toBeInTheDocument();
|
||||
expect(screen.getByText('$service')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('bullets out a variable holding several values', () => {
|
||||
renderTooltip(['service'], {
|
||||
service: { value: ['checkout', 'cart', 'api'], allSelected: false },
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getAllByRole('listitem').map((item) => item.textContent),
|
||||
).toStrictEqual(['checkout', 'cart', 'api']);
|
||||
});
|
||||
|
||||
it('keeps a lone value unbulleted', () => {
|
||||
renderTooltip(['env'], {
|
||||
env: { value: 'production', allSelected: false },
|
||||
});
|
||||
|
||||
expect(screen.queryByRole('list')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('production')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('labels all-selected and unset variables', () => {
|
||||
renderTooltip(['env', 'host'], {
|
||||
env: { value: null, allSelected: true },
|
||||
});
|
||||
|
||||
expect(screen.getByText('ALL')).toBeInTheDocument();
|
||||
expect(screen.getByText('—')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('lists every hidden variable, however many there are', () => {
|
||||
const names = Array.from({ length: 12 }, (_, i) => `var${i}`);
|
||||
|
||||
const tooltip = renderTooltip(names, {});
|
||||
|
||||
expect(tooltip).toHaveTextContent('$var0');
|
||||
expect(tooltip).toHaveTextContent('$var11');
|
||||
});
|
||||
|
||||
it('bullets every value it is given, without truncating', () => {
|
||||
const values = Array.from({ length: 14 }, (_, i) => `v${i}`);
|
||||
|
||||
renderTooltip(['service'], {
|
||||
service: { value: values, allSelected: false },
|
||||
});
|
||||
|
||||
expect(screen.getAllByRole('listitem')).toHaveLength(14);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { TooltipProvider } from '@signozhq/ui/tooltip';
|
||||
|
||||
import type { VariableSelection } from '../selectionTypes';
|
||||
import ValueSelector from '../components/selectors/ValueSelector';
|
||||
|
||||
jest.mock('api/common/logEvent', () => ({
|
||||
__esModule: true,
|
||||
default: jest.fn(),
|
||||
}));
|
||||
|
||||
const VALUES = ['checkout-service-prod', 'payments-service-prod'];
|
||||
// A strict subset of the options — selecting every option renders as ALL instead.
|
||||
const OPTIONS = [...VALUES, 'cart-service-prod'];
|
||||
|
||||
function renderSelector(
|
||||
selection: VariableSelection,
|
||||
options: string[],
|
||||
multiSelect = true,
|
||||
): void {
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<ValueSelector
|
||||
options={options}
|
||||
variableType="dynamic"
|
||||
multiSelect={multiSelect}
|
||||
showAllOption
|
||||
selection={selection}
|
||||
onChange={jest.fn()}
|
||||
emptyFallback={{ value: [], allSelected: false }}
|
||||
testId="variable-select-env"
|
||||
/>
|
||||
</TooltipProvider>,
|
||||
);
|
||||
}
|
||||
|
||||
/** Hovers an element and lets the tooltip's open delay elapse. */
|
||||
async function hover(element: HTMLElement): Promise<void> {
|
||||
const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
|
||||
await user.hover(element);
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(500);
|
||||
});
|
||||
}
|
||||
|
||||
describe('ValueSelector', () => {
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it("reveals a tag's full value on hovering that tag", async () => {
|
||||
renderSelector({ value: VALUES, allSelected: false }, OPTIONS);
|
||||
|
||||
// maxTagCount={1} + maxTagTextLength={10} → the one visible tag is cut short.
|
||||
await hover(screen.getByText('checkout-s...'));
|
||||
|
||||
expect(screen.getByRole('tooltip')).toHaveTextContent(
|
||||
'checkout-service-prod',
|
||||
);
|
||||
});
|
||||
|
||||
it('reveals the hidden values on hovering the +N overflow', async () => {
|
||||
renderSelector({ value: VALUES, allSelected: false }, OPTIONS);
|
||||
|
||||
await hover(screen.getByText('+1'));
|
||||
|
||||
expect(screen.getByRole('tooltip')).toHaveTextContent(
|
||||
'payments-service-prod',
|
||||
);
|
||||
});
|
||||
|
||||
it('does not reveal anything from the rest of the control', async () => {
|
||||
renderSelector({ value: VALUES, allSelected: false }, OPTIONS);
|
||||
|
||||
await hover(screen.getByTestId('variable-select-env'));
|
||||
|
||||
expect(screen.queryByRole('tooltip')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders ALL for an all-selected variable', () => {
|
||||
renderSelector({ value: null, allSelected: true }, ['a', 'b']);
|
||||
|
||||
expect(screen.getByText('ALL')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
import { describeSelection } from '../utils/selectionDisplay';
|
||||
|
||||
describe('describeSelection', () => {
|
||||
it('reports an all-selected variable as ALL', () => {
|
||||
expect(describeSelection({ value: null, allSelected: true })).toStrictEqual({
|
||||
kind: 'all',
|
||||
});
|
||||
});
|
||||
|
||||
it('lists a multi-select selection', () => {
|
||||
expect(
|
||||
describeSelection({ value: ['a', 'b'], allSelected: false }),
|
||||
).toStrictEqual({ kind: 'values', values: ['a', 'b'] });
|
||||
});
|
||||
|
||||
it('keeps every value, however many there are', () => {
|
||||
const values = Array.from({ length: 30 }, (_, i) => `v${i}`);
|
||||
|
||||
expect(
|
||||
describeSelection({ value: values, allSelected: false }),
|
||||
).toStrictEqual({ kind: 'values', values });
|
||||
});
|
||||
|
||||
it('lists a single value on its own', () => {
|
||||
expect(
|
||||
describeSelection({ value: 'production', allSelected: false }),
|
||||
).toStrictEqual({ kind: 'values', values: ['production'] });
|
||||
});
|
||||
|
||||
it('reports a missing or empty selection as empty', () => {
|
||||
expect(describeSelection(undefined)).toStrictEqual({ kind: 'empty' });
|
||||
expect(describeSelection({ value: '', allSelected: false })).toStrictEqual({
|
||||
kind: 'empty',
|
||||
});
|
||||
expect(describeSelection({ value: [], allSelected: false })).toStrictEqual({
|
||||
kind: 'empty',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { useSelector } from 'react-redux';
|
||||
import { QueryClient, QueryClientProvider } from 'react-query';
|
||||
import { act, renderHook, waitFor } from '@testing-library/react';
|
||||
import { getFieldValues } from 'api/dynamicVariables/getFieldValues';
|
||||
|
||||
import {
|
||||
emptyVariableFormModel,
|
||||
type VariableFormModel,
|
||||
} from '../../DashboardSettings/Variables/variableFormModel';
|
||||
import { VariableFetchState } from '../../store/slices/variableFetchSlice';
|
||||
import { useDashboardStore } from '../../store/useDashboardStore';
|
||||
import { useFetchedVariableOptions } from '../hooks/useFetchedVariableOptions';
|
||||
|
||||
jest.mock('react-redux', () => ({ useSelector: jest.fn() }));
|
||||
|
||||
jest.mock('api/dynamicVariables/getFieldValues', () => ({
|
||||
getFieldValues: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockUseSelector = useSelector as unknown as jest.Mock;
|
||||
const mockGetFieldValues = getFieldValues as unknown as jest.Mock;
|
||||
|
||||
function fieldValues(values: string[]): unknown {
|
||||
return { data: { normalizedValues: values, complete: true } };
|
||||
}
|
||||
|
||||
/** A promise resolved by the test, so the in-flight window is deterministic. */
|
||||
function deferred(): {
|
||||
promise: Promise<unknown>;
|
||||
resolve: (value: unknown) => void;
|
||||
} {
|
||||
let settle: (value: unknown) => void = () => {};
|
||||
const promise = new Promise<unknown>((resolve) => {
|
||||
settle = resolve;
|
||||
});
|
||||
return { promise, resolve: settle };
|
||||
}
|
||||
|
||||
function dynamicVariable(name: string): VariableFormModel {
|
||||
return {
|
||||
...emptyVariableFormModel(),
|
||||
name,
|
||||
type: 'DYNAMIC',
|
||||
dynamicAttribute: 'service.name',
|
||||
};
|
||||
}
|
||||
|
||||
function wrapper({ children }: { children: React.ReactNode }): JSX.Element {
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
return <QueryClientProvider client={client}>{children}</QueryClientProvider>;
|
||||
}
|
||||
|
||||
describe('useFetchedVariableOptions', () => {
|
||||
beforeEach(() => {
|
||||
mockUseSelector.mockImplementation((selector: (state: unknown) => unknown) =>
|
||||
selector({
|
||||
globalTime: {
|
||||
minTime: 1_000,
|
||||
maxTime: 2_000,
|
||||
isAutoRefreshDisabled: true,
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockGetFieldValues.mockReset();
|
||||
useDashboardStore.setState({
|
||||
variableFetchStates: {},
|
||||
variableLastUpdated: {},
|
||||
variableCycleIds: {},
|
||||
variableResolvedEmpty: {},
|
||||
});
|
||||
});
|
||||
|
||||
it('keeps the previous options while a new fetch cycle is in flight', async () => {
|
||||
const refetch = deferred();
|
||||
mockGetFieldValues
|
||||
.mockResolvedValueOnce(fieldValues(['prod', 'staging']))
|
||||
.mockReturnValueOnce(refetch.promise);
|
||||
|
||||
useDashboardStore.setState({
|
||||
variableFetchStates: { env: VariableFetchState.Loading },
|
||||
variableCycleIds: { env: 1 },
|
||||
});
|
||||
|
||||
const variable = dynamicVariable('env');
|
||||
const { result } = renderHook(
|
||||
() => useFetchedVariableOptions(variable, [variable], {}),
|
||||
{ wrapper },
|
||||
);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(result.current.options).toStrictEqual(['prod', 'staging']),
|
||||
);
|
||||
|
||||
// What a sibling dynamic's selection change does: bump the cycle id, which keys
|
||||
// a fresh request. The options must not blink empty in the meantime, or an ALL
|
||||
// selection (rendered from them) falls back to the placeholder.
|
||||
act(() => {
|
||||
useDashboardStore.setState({ variableCycleIds: { env: 2 } });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(result.current.loading).toBe(true));
|
||||
expect(result.current.options).toStrictEqual(['prod', 'staging']);
|
||||
|
||||
await act(async () => {
|
||||
refetch.resolve(fieldValues(['prod']));
|
||||
await refetch.promise;
|
||||
});
|
||||
|
||||
await waitFor(() => expect(result.current.options).toStrictEqual(['prod']));
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,39 @@
|
||||
.tooltip {
|
||||
display: flex;
|
||||
max-width: 360px;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.name {
|
||||
--typography-text-display: block;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
// A lone value, ALL, or the unset dash.
|
||||
.value {
|
||||
--typography-text-display: block;
|
||||
font-weight: var(--font-weight-medium);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
// One bullet per value when a variable holds several.
|
||||
.values {
|
||||
margin: 0;
|
||||
padding-left: 14px;
|
||||
list-style: disc outside;
|
||||
}
|
||||
|
||||
.valueItem {
|
||||
font-weight: var(--font-weight-medium);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import TooltipScrollArea from 'components/TooltipScrollArea/TooltipScrollArea';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
|
||||
import type { VariableFormModel } from '../../../DashboardSettings/Variables/variableFormModel';
|
||||
import type { VariableSelectionMap } from '../../selectionTypes';
|
||||
import SelectionValue from './SelectionValue';
|
||||
import styles from './HiddenVariablesTooltip.module.scss';
|
||||
|
||||
interface HiddenVariablesTooltipProps {
|
||||
/** The variables the collapsed bar isn't showing, in bar order. */
|
||||
variables: VariableFormModel[];
|
||||
selections: VariableSelectionMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Body of the collapsed bar's `+N` tooltip: what each hidden variable is set to.
|
||||
* Name and value sit on their own lines — `$name` muted above its value, which
|
||||
* bullets out when there are several — so the two read apart at a glance instead of
|
||||
* running together as `name: value`.
|
||||
* Every hidden variable is listed; the box scrolls rather than truncating.
|
||||
*/
|
||||
function HiddenVariablesTooltip({
|
||||
variables,
|
||||
selections,
|
||||
}: HiddenVariablesTooltipProps): JSX.Element {
|
||||
return (
|
||||
<TooltipScrollArea>
|
||||
<div className={styles.tooltip} data-testid="hidden-variables-tooltip">
|
||||
{variables.map((variable) => (
|
||||
<div className={styles.row} key={variable.name}>
|
||||
<Typography.Text size="xs" color="muted" className={styles.name}>
|
||||
${variable.name}
|
||||
</Typography.Text>
|
||||
<SelectionValue selection={selections[variable.name]} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</TooltipScrollArea>
|
||||
);
|
||||
}
|
||||
|
||||
export default HiddenVariablesTooltip;
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
|
||||
import type { VariableSelection } from '../../selectionTypes';
|
||||
import { describeSelection } from '../../utils/selectionDisplay';
|
||||
import styles from './HiddenVariablesTooltip.module.scss';
|
||||
|
||||
interface SelectionValueProps {
|
||||
selection?: VariableSelection;
|
||||
}
|
||||
|
||||
/**
|
||||
* A variable's current value as tooltip content: `ALL`, a dash when unset, the lone
|
||||
* value on its own, or — when it holds several — one bullet per value so the list
|
||||
* doesn't read as one run-on string.
|
||||
*/
|
||||
function SelectionValue({ selection }: SelectionValueProps): JSX.Element {
|
||||
const display = describeSelection(selection);
|
||||
|
||||
if (display.kind !== 'values') {
|
||||
return (
|
||||
<Typography.Text size="sm" className={styles.value}>
|
||||
{display.kind === 'all' ? 'ALL' : '—'}
|
||||
</Typography.Text>
|
||||
);
|
||||
}
|
||||
|
||||
if (display.values.length === 1) {
|
||||
return (
|
||||
<Typography.Text size="sm" className={styles.value}>
|
||||
{display.values[0]}
|
||||
</Typography.Text>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className={styles.values}>
|
||||
{display.values.map((value) => (
|
||||
<Typography.Text asChild size="sm" className={styles.valueItem} key={value}>
|
||||
<li>{value}</li>
|
||||
</Typography.Text>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export default SelectionValue;
|
||||
@@ -0,0 +1,43 @@
|
||||
import { TooltipSimple } from '@signozhq/ui/tooltip';
|
||||
import TooltipScrollArea, {
|
||||
TOOLTIP_SCROLL_CONTENT_CLASS,
|
||||
} from 'components/TooltipScrollArea/TooltipScrollArea';
|
||||
|
||||
import styles from '../../VariablesBar.module.scss';
|
||||
|
||||
interface OverflowValuesTooltipProps {
|
||||
/** The selected values the pill hides behind this `+N`. */
|
||||
values: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The multi-select's `+N` overflow item, revealing on hover the values it stands
|
||||
* for — one bullet each, all of them, scrolling rather than truncating. The
|
||||
* scrollbar stays put instead of auto-hiding, so a capped list reads as scrollable.
|
||||
*/
|
||||
function OverflowValuesTooltip({
|
||||
values,
|
||||
}: OverflowValuesTooltipProps): JSX.Element {
|
||||
return (
|
||||
<TooltipSimple
|
||||
side="top"
|
||||
delayDuration={300}
|
||||
tooltipContentProps={{ className: TOOLTIP_SCROLL_CONTENT_CLASS }}
|
||||
title={
|
||||
<TooltipScrollArea>
|
||||
<ul className={styles.overflowValues}>
|
||||
{values.map((value) => (
|
||||
<li key={value}>{value}</li>
|
||||
))}
|
||||
</ul>
|
||||
</TooltipScrollArea>
|
||||
}
|
||||
>
|
||||
{/* rc-select copies this node into the overflow wrapper's `title`; an empty
|
||||
one keeps the browser's own "[object Object]" tooltip out of the way. */}
|
||||
<span title="">+{values.length}</span>
|
||||
</TooltipSimple>
|
||||
);
|
||||
}
|
||||
|
||||
export default OverflowValuesTooltip;
|
||||
@@ -6,6 +6,7 @@ import { DashboardDetailEvents } from 'pages/DashboardPageV2/constants/events';
|
||||
|
||||
import type { VariableSelection } from '../../selectionTypes';
|
||||
import { areSelectionsEqual } from '../../utils/resolveVariableSelection';
|
||||
import OverflowValuesTooltip from './OverflowValuesTooltip';
|
||||
import styles from '../../VariablesBar.module.scss';
|
||||
|
||||
interface ValueSelectorProps {
|
||||
@@ -97,7 +98,13 @@ function ValueSelector({
|
||||
placeholder="Select value"
|
||||
maxTagCount={1}
|
||||
maxTagTextLength={10}
|
||||
maxTagPlaceholder={(omitted): string => `+${omitted.length}`}
|
||||
maxTagPlaceholder={(omitted): JSX.Element => (
|
||||
<OverflowValuesTooltip
|
||||
values={omitted.map((item) =>
|
||||
typeof item.label === 'string' ? item.label : String(item.value ?? ''),
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
// Offer ALL only once options load, else a concrete value reads as "all".
|
||||
enableAllSelection={showAllOption && options.length > 0}
|
||||
onDropdownVisibleChange={(open): void => {
|
||||
|
||||
@@ -89,6 +89,7 @@ export function useFetchedVariableOptions(
|
||||
enabled: variable.type === 'QUERY' && canFetch,
|
||||
refetchOnWindowFocus: false,
|
||||
cacheTime,
|
||||
keepPreviousData: true,
|
||||
onSettled: (_, error) =>
|
||||
error
|
||||
? onVariableFetchFailure(variable.name)
|
||||
@@ -124,6 +125,7 @@ export function useFetchedVariableOptions(
|
||||
variable.type === 'DYNAMIC' && !!variable.dynamicAttribute && canFetch,
|
||||
refetchOnWindowFocus: false,
|
||||
cacheTime,
|
||||
keepPreviousData: true,
|
||||
onSettled: (_, error) =>
|
||||
error
|
||||
? onVariableFetchFailure(variable.name)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { VariableSelection } from '../selectionTypes';
|
||||
|
||||
/**
|
||||
* What a selection reads as in a tooltip: the ALL label, nothing at all, or the
|
||||
* concrete values. Never truncated — the tooltip scrolls instead.
|
||||
*/
|
||||
export type SelectionDisplay =
|
||||
| { kind: 'all' }
|
||||
| { kind: 'empty' }
|
||||
| { kind: 'values'; values: string[] };
|
||||
|
||||
/** Describes a selection for display. */
|
||||
export function describeSelection(
|
||||
selection: VariableSelection | undefined,
|
||||
): SelectionDisplay {
|
||||
if (!selection) {
|
||||
return { kind: 'empty' };
|
||||
}
|
||||
if (selection.allSelected) {
|
||||
return { kind: 'all' };
|
||||
}
|
||||
|
||||
const { value } = selection;
|
||||
const values = (Array.isArray(value) ? value : [value])
|
||||
.filter((entry) => entry !== '' && entry !== null && entry !== undefined)
|
||||
.map(String);
|
||||
|
||||
return values.length === 0 ? { kind: 'empty' } : { kind: 'values', values };
|
||||
}
|
||||
@@ -387,15 +387,23 @@ describe('usePanelQuery', () => {
|
||||
expect(result.current.pagination?.canNext).toBe(false);
|
||||
});
|
||||
|
||||
it('drives canNext from the response cursor, not the row count', () => {
|
||||
// Full page but no cursor → backend says these are the last rows.
|
||||
it('drives canNext from the cursor OR a full page (offset fallback for non-timestamp sorts)', () => {
|
||||
// Full page, no cursor → the backend's offset path (a non-timestamp sort skips the
|
||||
// window/cursor path), so a full page is the has-more signal.
|
||||
withResponse(rawResponse(25));
|
||||
const noCursor = renderHook(() =>
|
||||
const fullPage = renderHook(() =>
|
||||
usePanelQuery({ panel: listPanel({}), panelId: 'p1' }),
|
||||
);
|
||||
expect(noCursor.result.current.pagination?.canNext).toBe(false);
|
||||
expect(fullPage.result.current.pagination?.canNext).toBe(true);
|
||||
|
||||
// Cursor present (even on a partial page) → more rows.
|
||||
// Partial page, no cursor → the last page.
|
||||
withResponse(rawResponse(3));
|
||||
const partialPage = renderHook(() =>
|
||||
usePanelQuery({ panel: listPanel({}), panelId: 'p1' }),
|
||||
);
|
||||
expect(partialPage.result.current.pagination?.canNext).toBe(false);
|
||||
|
||||
// Cursor present (even on a partial page) → more rows (timestamp window path).
|
||||
withResponse(rawResponse(3, 'cursor-1'));
|
||||
const withCursor = renderHook(() =>
|
||||
usePanelQuery({ panel: listPanel({}), panelId: 'p1' }),
|
||||
|
||||
@@ -283,8 +283,10 @@ export function usePanelQuery({
|
||||
[pageSize],
|
||||
);
|
||||
|
||||
// Paging handles for raw/list panels. The backend sets `nextCursor` iff the page filled,
|
||||
// so it's the authoritative has-more signal (there's no total count on the wire).
|
||||
// Paging handles for raw/list panels. The backend only emits `nextCursor` on the
|
||||
// timestamp-ordered window path (isWindowList); a non-timestamp sort falls back to plain
|
||||
// offset paging with no cursor. So treat a full page as a has-more signal too — matching the
|
||||
// offset heuristic the logs/traces explorers use (there's no total count on the wire).
|
||||
const pagination = useMemo<PanelPagination | undefined>(() => {
|
||||
if (!isPaginated) {
|
||||
return undefined;
|
||||
@@ -300,7 +302,7 @@ export function usePanelQuery({
|
||||
return {
|
||||
pageIndex: Math.floor(safeOffset / safePageSize),
|
||||
canPrev: safeOffset > 0,
|
||||
canNext: !!result?.nextCursor,
|
||||
canNext: !!result?.nextCursor || (result?.rows?.length ?? 0) >= safePageSize,
|
||||
goPrev,
|
||||
goNext,
|
||||
pageSize: safePageSize,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// small ones as data URIs — they ship in the bundle and render with no network
|
||||
// call. Logos are a large, JSON-only catalogue, so `?url` keeps them as emitted
|
||||
// files fetched (and cached) on demand rather than bloating the bundle.
|
||||
const iconModules = import.meta.glob('../../../assets/Icons/**/*.svg', {
|
||||
const iconModules = import.meta.glob('../../../assets/Icons/**/*.{svg,png}', {
|
||||
eager: true,
|
||||
import: 'default',
|
||||
});
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
import { useIsDashboardV2 } from 'hooks/useIsDashboardV2';
|
||||
import DashboardsListPageV2 from 'pages/DashboardsListPageV2';
|
||||
|
||||
import DashboardsListPage from './DashboardsListPage';
|
||||
|
||||
// Serves the V2 dashboards list when the `use_dashboard_v2` flag is active;
|
||||
// otherwise the existing V1 list. Lets V2 dark-ship behind the flag without
|
||||
// changing route definitions.
|
||||
function DashboardsListPageEntry(): JSX.Element {
|
||||
const isDashboardV2 = useIsDashboardV2();
|
||||
|
||||
return isDashboardV2 ? <DashboardsListPageV2 /> : <DashboardsListPage />;
|
||||
return <DashboardsListPageV2 />;
|
||||
}
|
||||
|
||||
export default DashboardsListPageEntry;
|
||||
|
||||
@@ -8,7 +8,10 @@ import {
|
||||
// top-level `name` / `image` / `tags` / `schemaVersion`) or a bare spec — wrap
|
||||
// the latter with defaults so users can paste either shape that exists in the
|
||||
// wild (e.g. testdata/perses.json is a bare spec). The legacy nested
|
||||
// `{ metadata: { ... }, spec }` shape is also accepted and flattened.
|
||||
// `{ metadata: { ... }, spec }` shape is also accepted and flattened. A legacy
|
||||
// v1 dashboard (top-level `version`, no `spec`/`schemaVersion`) is posted
|
||||
// unchanged: the create endpoint migrates it to v2 server-side, and wrapping
|
||||
// it here would misdeclare it as a v6 spec.
|
||||
//
|
||||
// The backend requires `name` (immutable identifier); if the payload doesn't
|
||||
// carry one, fall back to `generateName: true` so the server assigns one.
|
||||
@@ -16,6 +19,16 @@ export function normalizeToPostable(
|
||||
parsed: Record<string, unknown>,
|
||||
): DashboardtypesPostableDashboardV2DTO {
|
||||
const hasSpec = 'spec' in parsed;
|
||||
|
||||
if (
|
||||
!hasSpec &&
|
||||
!('schemaVersion' in parsed) &&
|
||||
typeof parsed.version === 'string' &&
|
||||
parsed.version !== ''
|
||||
) {
|
||||
return parsed as unknown as DashboardtypesPostableDashboardV2DTO;
|
||||
}
|
||||
|
||||
const legacyMeta = parsed.metadata as
|
||||
| {
|
||||
schemaVersion?: string;
|
||||
|
||||
@@ -2,329 +2,82 @@ package contextlinks
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
tracesV3 "github.com/SigNoz/signoz/pkg/query-service/app/traces/v3"
|
||||
v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
|
||||
"github.com/SigNoz/signoz/pkg/query-service/utils"
|
||||
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
|
||||
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
|
||||
)
|
||||
|
||||
func PrepareLinksToTraces(start, end time.Time, filterItems []v3.FilterItem) string {
|
||||
|
||||
// Traces list view expects time in nanoseconds
|
||||
tr := URLShareableTimeRange{
|
||||
Start: start.UnixNano(),
|
||||
End: end.UnixNano(),
|
||||
PageSize: 100,
|
||||
}
|
||||
|
||||
options := URLShareableOptions{
|
||||
MaxLines: 2,
|
||||
Format: "list",
|
||||
SelectColumns: tracesV3.TracesListViewDefaultSelectedColumns,
|
||||
}
|
||||
|
||||
period, _ := json.Marshal(tr)
|
||||
urlEncodedTimeRange := url.QueryEscape(string(period))
|
||||
|
||||
builderQuery := v3.BuilderQuery{
|
||||
DataSource: v3.DataSourceTraces,
|
||||
QueryName: "A",
|
||||
AggregateOperator: v3.AggregateOperatorNoOp,
|
||||
AggregateAttribute: v3.AttributeKey{},
|
||||
Filters: &v3.FilterSet{
|
||||
Items: filterItems,
|
||||
Operator: "AND",
|
||||
},
|
||||
Expression: "A",
|
||||
Disabled: false,
|
||||
Having: []v3.Having{},
|
||||
StepInterval: 60,
|
||||
OrderBy: []v3.OrderBy{
|
||||
{
|
||||
ColumnName: "timestamp",
|
||||
Order: "desc",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
urlData := URLShareableCompositeQuery{
|
||||
QueryType: string(v3.QueryTypeBuilder),
|
||||
Builder: URLShareableBuilderQuery{
|
||||
QueryData: []LinkQuery{
|
||||
{BuilderQuery: builderQuery},
|
||||
},
|
||||
QueryFormulas: make([]string, 0),
|
||||
},
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(urlData)
|
||||
compositeQuery := url.QueryEscape(url.QueryEscape(string(data)))
|
||||
|
||||
optionsData, _ := json.Marshal(options)
|
||||
urlEncodedOptions := url.QueryEscape(string(optionsData))
|
||||
|
||||
return fmt.Sprintf("compositeQuery=%s&timeRange=%s&startTime=%d&endTime=%d&options=%s", compositeQuery, urlEncodedTimeRange, tr.Start, tr.End, urlEncodedOptions)
|
||||
}
|
||||
|
||||
func PrepareLinksToLogs(start, end time.Time, filterItems []v3.FilterItem) string {
|
||||
|
||||
// Logs list view expects time in milliseconds
|
||||
tr := URLShareableTimeRange{
|
||||
Start: start.UnixMilli(),
|
||||
End: end.UnixMilli(),
|
||||
PageSize: 100,
|
||||
}
|
||||
|
||||
options := URLShareableOptions{
|
||||
MaxLines: 2,
|
||||
Format: "list",
|
||||
SelectColumns: []v3.AttributeKey{},
|
||||
}
|
||||
|
||||
period, _ := json.Marshal(tr)
|
||||
urlEncodedTimeRange := url.QueryEscape(string(period))
|
||||
|
||||
builderQuery := v3.BuilderQuery{
|
||||
DataSource: v3.DataSourceLogs,
|
||||
QueryName: "A",
|
||||
AggregateOperator: v3.AggregateOperatorNoOp,
|
||||
AggregateAttribute: v3.AttributeKey{},
|
||||
Filters: &v3.FilterSet{
|
||||
Items: filterItems,
|
||||
Operator: "AND",
|
||||
},
|
||||
Expression: "A",
|
||||
Disabled: false,
|
||||
Having: []v3.Having{},
|
||||
StepInterval: 60,
|
||||
OrderBy: []v3.OrderBy{
|
||||
{
|
||||
ColumnName: "timestamp",
|
||||
Order: "desc",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
urlData := URLShareableCompositeQuery{
|
||||
QueryType: string(v3.QueryTypeBuilder),
|
||||
Builder: URLShareableBuilderQuery{
|
||||
QueryData: []LinkQuery{
|
||||
{BuilderQuery: builderQuery},
|
||||
},
|
||||
QueryFormulas: make([]string, 0),
|
||||
},
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(urlData)
|
||||
compositeQuery := url.QueryEscape(url.QueryEscape(string(data)))
|
||||
|
||||
optionsData, _ := json.Marshal(options)
|
||||
urlEncodedOptions := url.QueryEscape(string(optionsData))
|
||||
|
||||
return fmt.Sprintf("compositeQuery=%s&timeRange=%s&startTime=%d&endTime=%d&options=%s", compositeQuery, urlEncodedTimeRange, tr.Start, tr.End, urlEncodedOptions)
|
||||
}
|
||||
|
||||
// The following function is used to prepare the where clause for the query
|
||||
// `lbls` contains the key value pairs of the labels from the result of the query
|
||||
// We iterate over the where clause and replace the labels with the actual values
|
||||
// There are two cases:
|
||||
// 1. The label is present in the where clause
|
||||
// 2. The label is not present in the where clause
|
||||
//
|
||||
// Example for case 2:
|
||||
// Latency by serviceName without any filter
|
||||
// In this case, for each service with latency > threshold we send a notification
|
||||
// The expectation will be that clicking on the related traces for service A, will
|
||||
// take us to the traces page with the filter serviceName=A
|
||||
// So for all the missing labels in the where clause, we add them as key = value
|
||||
//
|
||||
// Example for case 1:
|
||||
// Severity text IN (WARN, ERROR)
|
||||
// In this case, the Severity text will appear in the `lbls` if it were part of the group
|
||||
// by clause, in which case we replace it with the actual value for the notification
|
||||
// i.e Severity text = WARN
|
||||
// If the Severity text is not part of the group by clause, then we add it as it is.
|
||||
func PrepareFilters(labels map[string]string, whereClauseItems []v3.FilterItem, groupByItems []v3.AttributeKey, keys map[string]v3.AttributeKey) []v3.FilterItem {
|
||||
filterItems := make([]v3.FilterItem, 0)
|
||||
|
||||
//delete predefined alert labels
|
||||
for _, label := range PredefinedAlertLabels {
|
||||
delete(labels, label)
|
||||
}
|
||||
|
||||
added := make(map[string]struct{})
|
||||
|
||||
for _, item := range whereClauseItems {
|
||||
exists := false
|
||||
for key, value := range labels {
|
||||
if item.Key.Key == key {
|
||||
// if the label is present in the where clause, replace it with key = value
|
||||
filterItems = append(filterItems, v3.FilterItem{
|
||||
Key: item.Key,
|
||||
Operator: v3.FilterOperatorEqual,
|
||||
Value: value,
|
||||
})
|
||||
exists = true
|
||||
added[key] = struct{}{}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !exists {
|
||||
// if there is no label for the filter item, add it as it is
|
||||
filterItems = append(filterItems, item)
|
||||
}
|
||||
}
|
||||
|
||||
// if there are labels which are not part of the where clause, but
|
||||
// exist in the result, then they could be part of the group by clause
|
||||
for key, value := range labels {
|
||||
if _, ok := added[key]; !ok {
|
||||
// start by taking the attribute key from the keys map, if not present, create a new one
|
||||
var attributeKey v3.AttributeKey
|
||||
var attrFound bool
|
||||
|
||||
// as of now this logic will only apply for logs
|
||||
for _, tKey := range utils.GenerateEnrichmentKeys(v3.AttributeKey{Key: key}) {
|
||||
if val, ok := keys[tKey]; ok {
|
||||
attributeKey = val
|
||||
attrFound = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// check if the attribute key is directly present, as of now this will always be false for logs
|
||||
// as for logs it will be satisfied in the condition above
|
||||
if !attrFound {
|
||||
attributeKey, attrFound = keys[key]
|
||||
}
|
||||
|
||||
// if the attribute key is not present, create a new one
|
||||
if !attrFound {
|
||||
attributeKey = v3.AttributeKey{Key: key}
|
||||
}
|
||||
|
||||
// if there is a group by item with the same key, use that instead
|
||||
for _, groupByItem := range groupByItems {
|
||||
if groupByItem.Key == key {
|
||||
attributeKey = groupByItem
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
filterItems = append(filterItems, v3.FilterItem{
|
||||
Key: attributeKey,
|
||||
Operator: v3.FilterOperatorEqual,
|
||||
Value: value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return filterItems
|
||||
}
|
||||
|
||||
// PrepareParamsForTracesV5 returns the traces explorer query params for the
|
||||
// given range and filter; the traces explorer writes its time params in
|
||||
// nanoseconds.
|
||||
func PrepareParamsForTracesV5(start, end time.Time, whereClause string) url.Values {
|
||||
|
||||
// Traces list view expects time in nanoseconds
|
||||
tr := URLShareableTimeRange{
|
||||
Start: start.UnixNano(),
|
||||
End: end.UnixNano(),
|
||||
PageSize: 100,
|
||||
}
|
||||
|
||||
options := URLShareableOptions{}
|
||||
|
||||
period, _ := json.Marshal(tr)
|
||||
|
||||
linkQuery := LinkQuery{
|
||||
BuilderQuery: v3.BuilderQuery{
|
||||
DataSource: v3.DataSourceTraces,
|
||||
QueryName: "A",
|
||||
AggregateOperator: v3.AggregateOperatorNoOp,
|
||||
AggregateAttribute: v3.AttributeKey{},
|
||||
Expression: "A",
|
||||
Disabled: false,
|
||||
Having: []v3.Having{},
|
||||
StepInterval: 60,
|
||||
},
|
||||
Filter: &FilterExpression{Expression: whereClause},
|
||||
}
|
||||
|
||||
urlData := URLShareableCompositeQuery{
|
||||
QueryType: string(v3.QueryTypeBuilder),
|
||||
Builder: URLShareableBuilderQuery{
|
||||
QueryData: []LinkQuery{
|
||||
linkQuery,
|
||||
},
|
||||
QueryFormulas: make([]string, 0),
|
||||
},
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(urlData)
|
||||
compositeQuery := url.QueryEscape(string(data))
|
||||
|
||||
optionsData, _ := json.Marshal(options)
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("compositeQuery", compositeQuery)
|
||||
params.Set("timeRange", string(period))
|
||||
params.Set("startTime", strconv.FormatInt(tr.Start, 10))
|
||||
params.Set("endTime", strconv.FormatInt(tr.End, 10))
|
||||
params.Set("options", string(optionsData))
|
||||
return params
|
||||
return prepareExplorerParams("traces", start.UnixNano(), end.UnixNano(), whereClause)
|
||||
}
|
||||
|
||||
// PrepareParamsForLogsV5 returns the logs explorer query params for the given
|
||||
// range and filter; the logs explorer writes its time params in milliseconds.
|
||||
func PrepareParamsForLogsV5(start, end time.Time, whereClause string) url.Values {
|
||||
return prepareExplorerParams("logs", start.UnixMilli(), end.UnixMilli(), whereClause)
|
||||
}
|
||||
|
||||
// Logs list view expects time in milliseconds
|
||||
tr := URLShareableTimeRange{
|
||||
Start: start.UnixMilli(),
|
||||
End: end.UnixMilli(),
|
||||
PageSize: 100,
|
||||
}
|
||||
|
||||
options := URLShareableOptions{}
|
||||
|
||||
period, _ := json.Marshal(tr)
|
||||
|
||||
linkQuery := LinkQuery{
|
||||
BuilderQuery: v3.BuilderQuery{
|
||||
DataSource: v3.DataSourceLogs,
|
||||
QueryName: "A",
|
||||
AggregateOperator: v3.AggregateOperatorNoOp,
|
||||
AggregateAttribute: v3.AttributeKey{},
|
||||
Expression: "A",
|
||||
Disabled: false,
|
||||
Having: []v3.Having{},
|
||||
StepInterval: 60,
|
||||
},
|
||||
Filter: &FilterExpression{Expression: whereClause},
|
||||
}
|
||||
|
||||
// The end link is double encoded because otherwise a filter expression with `%` somewhere in it breaks.
|
||||
func prepareExplorerParams(dataSource string, start, end int64, whereClause string) url.Values {
|
||||
urlData := URLShareableCompositeQuery{
|
||||
QueryType: string(v3.QueryTypeBuilder),
|
||||
QueryType: "builder",
|
||||
Builder: URLShareableBuilderQuery{
|
||||
QueryData: []LinkQuery{
|
||||
linkQuery,
|
||||
},
|
||||
QueryData: []LinkQuery{{
|
||||
DataSource: dataSource,
|
||||
Filter: &FilterExpression{Expression: whereClause},
|
||||
}},
|
||||
QueryFormulas: make([]string, 0),
|
||||
},
|
||||
}
|
||||
|
||||
data, _ := json.Marshal(urlData)
|
||||
compositeQuery := url.QueryEscape(string(data))
|
||||
|
||||
optionsData, _ := json.Marshal(options)
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("compositeQuery", compositeQuery)
|
||||
params.Set("timeRange", string(period))
|
||||
params.Set("startTime", strconv.FormatInt(tr.Start, 10))
|
||||
params.Set("endTime", strconv.FormatInt(tr.End, 10))
|
||||
params.Set("options", string(optionsData))
|
||||
params.Set("compositeQuery", url.QueryEscape(string(data)))
|
||||
params.Set("startTime", strconv.FormatInt(start, 10))
|
||||
params.Set("endTime", strconv.FormatInt(end, 10))
|
||||
return params
|
||||
}
|
||||
|
||||
// BuilderQueryForSignal returns the filter expression and group-by keys of the
|
||||
// builder query for the given signal, or found=false when the composite query
|
||||
// has no builder query for it (e.g. PromQL or ClickHouse SQL alerts).
|
||||
// TODO(srikanthccv): re-visit this and support multiple queries.
|
||||
func BuilderQueryForSignal(queries []qbtypes.QueryEnvelope, signal telemetrytypes.Signal) (string, []qbtypes.GroupByKey, bool) {
|
||||
switch signal {
|
||||
case telemetrytypes.SignalLogs:
|
||||
return builderQueryForSignal[qbtypes.LogAggregation](queries, signal)
|
||||
case telemetrytypes.SignalTraces:
|
||||
return builderQueryForSignal[qbtypes.TraceAggregation](queries, signal)
|
||||
}
|
||||
return "", nil, false
|
||||
}
|
||||
|
||||
func builderQueryForSignal[T any](queries []qbtypes.QueryEnvelope, signal telemetrytypes.Signal) (string, []qbtypes.GroupByKey, bool) {
|
||||
var q qbtypes.QueryBuilderQuery[T]
|
||||
found := false
|
||||
for _, query := range queries {
|
||||
if query.Type != qbtypes.QueryTypeBuilder {
|
||||
continue
|
||||
}
|
||||
if spec, ok := query.Spec.(qbtypes.QueryBuilderQuery[T]); ok {
|
||||
q = spec
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found || q.Signal != signal {
|
||||
return "", nil, false
|
||||
}
|
||||
|
||||
filterExpr := ""
|
||||
if q.Filter != nil {
|
||||
filterExpr = q.Filter.Expression
|
||||
}
|
||||
return filterExpr, q.GroupBy, true
|
||||
}
|
||||
|
||||
63
pkg/contextlinks/links_test.go
Normal file
63
pkg/contextlinks/links_test.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package contextlinks
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
|
||||
"github.com/SigNoz/signoz/pkg/types/telemetrytypes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestBuilderQueryForSignal(t *testing.T) {
|
||||
logQuery := qbtypes.QueryEnvelope{
|
||||
Type: qbtypes.QueryTypeBuilder,
|
||||
Spec: qbtypes.QueryBuilderQuery[qbtypes.LogAggregation]{
|
||||
Name: "A",
|
||||
Signal: telemetrytypes.SignalLogs,
|
||||
Filter: &qbtypes.Filter{Expression: "severity_text = 'ERROR'"},
|
||||
GroupBy: []qbtypes.GroupByKey{{TelemetryFieldKey: telemetrytypes.TelemetryFieldKey{Name: "service.name"}}},
|
||||
},
|
||||
}
|
||||
traceQuery := qbtypes.QueryEnvelope{
|
||||
Type: qbtypes.QueryTypeBuilder,
|
||||
Spec: qbtypes.QueryBuilderQuery[qbtypes.TraceAggregation]{
|
||||
Name: "B",
|
||||
Signal: telemetrytypes.SignalTraces,
|
||||
},
|
||||
}
|
||||
promQuery := qbtypes.QueryEnvelope{
|
||||
Type: qbtypes.QueryTypePromQL,
|
||||
Spec: qbtypes.PromQuery{Name: "C"},
|
||||
}
|
||||
|
||||
t.Run("logs query among mixed queries", func(t *testing.T) {
|
||||
filterExpr, groupBy, found := BuilderQueryForSignal([]qbtypes.QueryEnvelope{promQuery, logQuery, traceQuery}, telemetrytypes.SignalLogs)
|
||||
require.True(t, found)
|
||||
assert.Equal(t, "severity_text = 'ERROR'", filterExpr)
|
||||
require.Len(t, groupBy, 1)
|
||||
assert.Equal(t, "service.name", groupBy[0].Name)
|
||||
})
|
||||
|
||||
t.Run("traces query without filter", func(t *testing.T) {
|
||||
filterExpr, groupBy, found := BuilderQueryForSignal([]qbtypes.QueryEnvelope{logQuery, traceQuery}, telemetrytypes.SignalTraces)
|
||||
require.True(t, found)
|
||||
assert.Empty(t, filterExpr)
|
||||
assert.Empty(t, groupBy)
|
||||
})
|
||||
|
||||
t.Run("no builder query for signal", func(t *testing.T) {
|
||||
_, _, found := BuilderQueryForSignal([]qbtypes.QueryEnvelope{traceQuery}, telemetrytypes.SignalLogs)
|
||||
assert.False(t, found)
|
||||
})
|
||||
|
||||
t.Run("no builder queries at all", func(t *testing.T) {
|
||||
_, _, found := BuilderQueryForSignal([]qbtypes.QueryEnvelope{promQuery}, telemetrytypes.SignalLogs)
|
||||
assert.False(t, found)
|
||||
})
|
||||
|
||||
t.Run("unsupported signal", func(t *testing.T) {
|
||||
_, _, found := BuilderQueryForSignal([]qbtypes.QueryEnvelope{logQuery}, telemetrytypes.SignalMetrics)
|
||||
assert.False(t, found)
|
||||
})
|
||||
}
|
||||
@@ -1,29 +1,20 @@
|
||||
package contextlinks
|
||||
|
||||
import (
|
||||
v3 "github.com/SigNoz/signoz/pkg/query-service/model/v3"
|
||||
"github.com/SigNoz/signoz/pkg/types/ruletypes"
|
||||
)
|
||||
|
||||
// TODO(srikanthccv): Fix the URL management.
|
||||
type URLShareableTimeRange struct {
|
||||
Start int64 `json:"start"`
|
||||
End int64 `json:"end"`
|
||||
PageSize int64 `json:"pageSize"`
|
||||
}
|
||||
|
||||
type FilterExpression struct {
|
||||
Expression string `json:"expression,omitempty"`
|
||||
}
|
||||
|
||||
type Aggregation struct {
|
||||
Expression string `json:"expression,omitempty"`
|
||||
}
|
||||
|
||||
// LinkQuery carries the only fields the explorer pages read from a shared
|
||||
// link; the frontend fills in the rest of the query shape with defaults.
|
||||
type LinkQuery struct {
|
||||
v3.BuilderQuery
|
||||
Filter *FilterExpression `json:"filter,omitempty"`
|
||||
Aggregations []*Aggregation `json:"aggregations,omitempty"`
|
||||
DataSource string `json:"dataSource"`
|
||||
Filter *FilterExpression `json:"filter,omitempty"`
|
||||
}
|
||||
|
||||
type URLShareableBuilderQuery struct {
|
||||
@@ -36,10 +27,4 @@ type URLShareableCompositeQuery struct {
|
||||
Builder URLShareableBuilderQuery `json:"builder"`
|
||||
}
|
||||
|
||||
type URLShareableOptions struct {
|
||||
MaxLines int `json:"maxLines"`
|
||||
Format string `json:"format"`
|
||||
SelectColumns []v3.AttributeKey `json:"selectColumns"`
|
||||
}
|
||||
|
||||
var PredefinedAlertLabels = []string{ruletypes.LabelThresholdName, ruletypes.LabelSeverityName, ruletypes.LabelLastSeen}
|
||||
|
||||
@@ -11,7 +11,6 @@ var (
|
||||
FeatureUseMeterReporter = featuretypes.MustNewName("use_meter_reporter")
|
||||
FeatureUseJSONBody = featuretypes.MustNewName("use_json_body")
|
||||
FeatureUseFineGrainedAuthz = featuretypes.MustNewName("use_fine_grained_authz")
|
||||
FeatureUseDashboardV2 = featuretypes.MustNewName("use_dashboard_v2")
|
||||
FeatureEnableAIObservability = featuretypes.MustNewName("enable_ai_observability")
|
||||
FeatureEnableMetricsReduction = featuretypes.MustNewName("enable_metrics_reduction")
|
||||
FeatureUseInfraMonitoringV2 = featuretypes.MustNewName("use_infra_monitoring_v2")
|
||||
@@ -83,14 +82,6 @@ func MustNewRegistry() featuretypes.Registry {
|
||||
DefaultVariant: featuretypes.MustNewName("disabled"),
|
||||
Variants: featuretypes.NewBooleanVariants(),
|
||||
},
|
||||
&featuretypes.Feature{
|
||||
Name: FeatureUseDashboardV2,
|
||||
Kind: featuretypes.KindBoolean,
|
||||
Stage: featuretypes.StageExperimental,
|
||||
Description: "Controls whether dashboard v2 is enabled",
|
||||
DefaultVariant: featuretypes.MustNewName("disabled"),
|
||||
Variants: featuretypes.NewBooleanVariants(),
|
||||
},
|
||||
&featuretypes.Feature{
|
||||
Name: FeatureEnableAIObservability,
|
||||
Kind: featuretypes.KindBoolean,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user