[Synthetics] Handle string filters in url (#161780)

This commit is contained in:
Shahzad 2023-07-17 16:39:30 +02:00 committed by GitHub
parent 885fb43651
commit 82285ac7c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 10 deletions

View file

@ -32,7 +32,7 @@ export const FilterButton = ({
// Transform the values to readable labels (if any) so that selected values are checked on filter dropdown
const selectedValueLabels = getSyntheticsFilterDisplayValues(
(urlParams[field] || []).map(valueToLabelWithEmptyCount),
valueToLabelWithEmptyCount(urlParams[field]),
field,
[]
).map(({ label: selectedValueLabel }) => selectedValueLabel);

View file

@ -23,9 +23,17 @@ import { FilterButton } from './filter_button';
const mixUrlValues = (
values?: LabelWithCountValue[],
urlLabels?: string[]
urlLabels?: string[] | string
): LabelWithCountValue[] => {
const urlValues = urlLabels?.map((label) => ({ label, count: 0 })) ?? [];
let urlValues: Array<{
label: string;
count: number;
}> = [];
if (typeof urlLabels === 'string' && urlLabels) {
urlValues.push({ label: urlLabels, count: 0 });
} else if (Array.isArray(urlLabels)) {
urlValues = urlLabels?.map((label) => ({ label, count: 0 })) ?? [];
}
const newValues = [...(values ?? [])];
// add url values that are not in the values
urlValues.forEach((urlValue) => {

View file

@ -81,10 +81,12 @@ export function getSyntheticsFilterKeyForLabel(value: string, field: SyntheticsM
}
}
export const valueToLabelWithEmptyCount = (value: string): LabelWithCountValue => ({
label: value,
count: 0,
});
export const valueToLabelWithEmptyCount = (value?: string | string[]): LabelWithCountValue[] => {
if (Array.isArray(value)) {
return value.map((v) => ({ label: v, count: 0 }));
}
return value ? [{ label: value, count: 0 }] : [];
};
export const monitorTypeKeyLabelMap: Record<DataStream, string> = {
[DataStream.BROWSER]: 'Journey / Page',

View file

@ -29,11 +29,11 @@ export interface SyntheticsUrlParams {
query?: string;
tags?: string[];
locations?: string[];
monitorTypes?: string[];
monitorTypes?: string[] | string;
status?: string[];
locationId?: string;
projects?: string[];
schedules?: string[];
projects?: string[] | string;
schedules?: string[] | string;
groupBy?: MonitorOverviewState['groupBy']['field'];
groupOrderBy?: MonitorOverviewState['groupBy']['order'];
packagePolicyId?: string;