Skip to content

Commit

Permalink
update type and test
Browse files Browse the repository at this point in the history
Signed-off-by: tygao <[email protected]>
  • Loading branch information
raintygao committed Oct 24, 2024
1 parent 9f9eca3 commit 2244cfe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- feat: take index pattern and query assistant input to text2viz app([#349](https://github.com/opensearch-project/dashboards-assistant/pull/349))
- feat: Hide incompatible index patterns ([#354] (https://github.com/opensearch-project/dashboards-assistant/pull/354))
- feat: edit visualization with natural language in a dialog([#351](https://github.com/opensearch-project/dashboards-assistant/pull/351))
- fix: Update alerting DSL verify mechanism([#359](https://github.com/opensearch-project/dashboards-assistant/pull/359))


### 📈 Features/Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ const mockDSL = `{
}
}`;

const spyWindowOpen = jest.spyOn(window, 'open');
spyWindowOpen.mockImplementation(jest.fn());

describe('GeneratePopoverBody', () => {
const incontextInsightMock = {
contextProvider: jest.fn(),
Expand Down Expand Up @@ -384,7 +381,7 @@ describe('GeneratePopoverBody', () => {
const button = getByText('Discover details');
expect(button).toBeInTheDocument();
fireEvent.click(button);
expect(spyWindowOpen).toHaveBeenCalledWith('data-explorer/discover#?query');
});
expect(window.open).toHaveBeenCalledWith('formattedUrl', '_blank');
});
});
8 changes: 8 additions & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,11 @@ export type TabId = 'chat' | 'compose' | 'insights' | 'history' | 'trace';
export interface NestedRecord<T = string> {
[key: string]: T | NestedRecord<T>;
}

export interface DSL {
query?: {
bool?: {
filter?: unknown[];
};
};
}
10 changes: 5 additions & 5 deletions public/utils/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import {
Filter,
} from '../../../../src/plugins/data/public';
import { CoreStart } from '../../../../src/core/public';
import { NestedRecord } from '../types';
import { NestedRecord, DSL } from '../types';

export const buildFilter = (indexPatternId: string, dsl: Record<string, unknown>) => {
export const buildFilter = (indexPatternId: string, dsl: DSL) => {
const filterAlias = 'Alerting-filters';
return buildCustomFilter(
indexPatternId,
Expand Down Expand Up @@ -72,13 +72,13 @@ export const buildUrlQuery = async (
dataStart: DataPublicPluginStart,
savedObjects: CoreStart['savedObjects'],
indexPattern: IndexPattern,
dsl: NestedRecord,
dsl: DSL,
timeDsl: Record<'from' | 'to', string>,
dataSourceId?: string
) => {
let filters: Filter[] = [];
// If there is none filter after filtering timeRange filter, skip to build filter query.
if (dsl?.query?.bool?.filter?.length > 0) {
if ((dsl?.query?.bool?.filter?.length ?? 0) > 0) {
const filter = buildFilter(indexPattern.id!, dsl);
const filterManager = dataStart.query.filterManager;
// There are some map and flatten operations to filters in filterManager, use this to keep aligned with discover.
Expand Down Expand Up @@ -158,7 +158,7 @@ export const validateToTimeRange = (time: string) => {
export const extractTimeRangeDSL = (filters: NestedRecord[]) => {
let timeRangeDSL;
let timeFieldName;
const newFilters = filters.filter((filter: NestedRecord) => {
const newFilters = filters.filter((filter) => {
if (filter?.range && typeof filter.range === 'object') {
for (const key of Object.keys(filter.range)) {
const rangeValue = filter.range[key];
Expand Down

0 comments on commit 2244cfe

Please sign in to comment.