Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ describe('EsQueryRuleTypeExpression', () => {
size: [],
timeField: [],
timeWindowSize: [],
termSize: [],
termField: [],
};

return await act(async () =>
Expand Down Expand Up @@ -222,6 +224,22 @@ describe('EsQueryRuleTypeExpression', () => {
expect(result.getByTestId('sizeValueExpression')).toHaveTextContent('Size 0');
});

test('should render EsQueryRuleTypeExpression with chosen runtime group field', async () => {
const result = await setup({
...defaultEsQueryExpressionParams,
esQuery:
'{\n "query":{\n "match_all" : {}\n },\n "runtime_mappings": {\n "day_of_week": {\n "type": "keyword",\n "script": {\n "source": "emit(doc[\'@timestamp\'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"\n }\n }\n }\n }',
groupBy: 'top',
termField: 'day_of_week',
termSize: 3,
} as unknown as EsQueryRuleParams<SearchType.esQuery>);

fireEvent.click(screen.getByTestId('groupByExpression'));
expect(await screen.findByRole('dialog')).toBeInTheDocument();

expect(result.getByTestId('fieldsExpressionSelect')).toHaveTextContent('day_of_week');
});

test('should show success message if ungrouped Test Query is successful', async () => {
const searchResponseMock$ = of<IKibanaSearchResponse>({
rawResponse: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@ export const EsQueryExpression: React.FC<

const setDefaultExpressionValues = async () => {
setRuleProperty('params', currentRuleParams);
setXJson(esQuery ?? DEFAULT_VALUES.QUERY);
const query = esQuery ?? DEFAULT_VALUES.QUERY;
setXJson(query);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious, was it part of the fix to separate this into 2 lines?

Copy link
Copy Markdown
Contributor Author

@doakalexi doakalexi Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it's not necessary for the fix sorry! I just didnt want to repeat esQuery ?? DEFAULT_VALUES.QUERY in getRuntimeFields so I saved it in a variable. I can put it back tho!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't see it was reused later. All good.


if (index && index.length > 0) {
await refreshEsFields(index);
const initialRuntimeFields = getRuntimeFields(query);
await refreshEsFields(index, initialRuntimeFields);
}
};

Expand All @@ -110,10 +112,14 @@ export const EsQueryExpression: React.FC<
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const refreshEsFields = async (indices: string[]) => {
const refreshEsFields = async (indices: string[], initialRuntimeFields?: FieldOption[]) => {
const currentEsFields = await getFields(http, indices);
setEsFields(currentEsFields);
setCombinedFields(sortBy(currentEsFields.concat(runtimeFields), 'name'));

const combined = currentEsFields.concat(
initialRuntimeFields !== undefined ? initialRuntimeFields : runtimeFields
);
setCombinedFields(sortBy(combined, 'name'));
};

const getRuntimeFields = (xjson: string) => {
Expand All @@ -127,6 +133,7 @@ export const EsQueryExpression: React.FC<
const currentRuntimeFields = convertRawRuntimeFieldtoFieldOption(runtimeMappings);
setRuntimeFields(currentRuntimeFields);
setCombinedFields(sortBy(esFields.concat(currentRuntimeFields), 'name'));
return currentRuntimeFields;
}
};

Expand Down