Skip to content

Commit

Permalink
Pass undefined when selecting all
Browse files Browse the repository at this point in the history
  • Loading branch information
kpatticha committed Apr 19, 2023
1 parent 6835d1c commit fce4ef8
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,28 @@ export default {
],
};

export const Example: Story = () => {
const [params, setParams] = useState<RuleParams>({
export const CreatingInApmServiceOverview: Story<Args> = ({
ruleParams,
metadata,
}) => {
const [params, setParams] = useState<RuleParams>(ruleParams);

function setRuleParams(property: string, value: any) {
setParams({ ...params, [property]: value });
}

return (
<TransactionDurationRuleType
ruleParams={params}
metadata={metadata}
setRuleParams={setRuleParams}
setRuleProperty={() => {}}
/>
);
};

CreatingInApmServiceOverview.args = {
ruleParams: {
aggregationType: AggregationType.Avg,
environment: 'testEnvironment',
serviceName: 'testServiceName',
Expand All @@ -42,7 +62,15 @@ export const Example: Story = () => {
transactionName: 'GET /api/customer/:id',
windowSize: 5,
windowUnit: 'm',
});
},
metadata: undefined,
};

export const CreatingInStackManagement: Story<Args> = ({
ruleParams,
metadata,
}) => {
const [params, setParams] = useState<RuleParams>(ruleParams);

function setRuleParams(property: string, value: any) {
setParams({ ...params, [property]: value });
Expand All @@ -51,8 +79,14 @@ export const Example: Story = () => {
return (
<TransactionDurationRuleType
ruleParams={params}
metadata={metadata}
setRuleParams={setRuleParams}
setRuleProperty={() => {}}
/>
);
};

CreatingInStackManagement.args = {
ruleParams: {},
metadata: undefined,
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import { PopoverExpression } from '../../ui_components/popover_expression';
export interface RuleParams {
aggregationType: AggregationType;
environment: string;
serviceName: string;
threshold: number;
transactionType: string;
transactionName: string;
transactionType?: string;
transactionName?: string;
serviceName?: string;
windowSize: number;
windowUnit: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function ServiceField({
>
<SuggestionsSelect
customOptions={
allowAll ? [{ label: allOptionText, value: '' }] : undefined
allowAll ? [{ label: allOptionText, value: undefined }] : undefined
}
customOptionText={i18n.translate(
'xpack.apm.serviceNamesSelectCustomOptionText',
Expand Down Expand Up @@ -104,7 +104,7 @@ export function TransactionNameField({
onChange,
serviceName,
}: {
currentValue: string;
currentValue?: string;
onChange: (value?: string) => void;
serviceName?: string;
}) {
Expand All @@ -115,7 +115,7 @@ export function TransactionNameField({
return (
<PopoverExpression value={currentValue || allOptionText} title={label}>
<SuggestionsSelect
customOptions={[{ label: allOptionText, value: '' }]}
customOptions={[{ label: allOptionText, value: undefined }]}
customOptionText={i18n.translate(
'xpack.apm.alerting.transaction.name.custom.text',
{
Expand Down Expand Up @@ -154,7 +154,7 @@ export function TransactionTypeField({
return (
<PopoverExpression value={currentValue || allOptionText} title={label}>
<SuggestionsSelect
customOptions={[{ label: allOptionText, value: '' }]}
customOptions={[{ label: allOptionText, value: undefined }]}
customOptionText={i18n.translate(
'xpack.apm.transactionTypesSelectCustomOptionText',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ export function registerErrorCountRuleType({
},
},
{ term: { [PROCESSOR_EVENT]: ProcessorEvent.error } },
...termQuery(SERVICE_NAME, ruleParams.serviceName, {
queryEmptyString: false,
}),
...termQuery(SERVICE_NAME, ruleParams.serviceName),
...environmentQuery(ruleParams.environment),
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,9 @@ export async function getTransactionDurationChartPreview({
const query = {
bool: {
filter: [
...termQuery(SERVICE_NAME, serviceName, {
queryEmptyString: false,
}),
...termQuery(TRANSACTION_TYPE, transactionType, {
queryEmptyString: false,
}),
...termQuery(TRANSACTION_NAME, transactionName, {
queryEmptyString: false,
}),
...termQuery(SERVICE_NAME, serviceName),
...termQuery(TRANSACTION_TYPE, transactionType),
...termQuery(TRANSACTION_NAME, transactionName),
...rangeQuery(start, end),
...environmentQuery(environment),
...getDocumentTypeFilterForTransactions(searchAggregatedTransactions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,9 @@ export function registerTransactionDurationRuleType({
...getDocumentTypeFilterForTransactions(
searchAggregatedTransactions
),
...termQuery(SERVICE_NAME, ruleParams.serviceName, {
queryEmptyString: false,
}),
...termQuery(TRANSACTION_TYPE, ruleParams.transactionType, {
queryEmptyString: false,
}),
...termQuery(TRANSACTION_NAME, ruleParams.transactionName, {
queryEmptyString: false,
}),
...termQuery(SERVICE_NAME, ruleParams.serviceName),
...termQuery(TRANSACTION_TYPE, ruleParams.transactionType),
...termQuery(TRANSACTION_NAME, ruleParams.transactionName),
...environmentQuery(ruleParams.environment),
] as QueryDslQueryContainer[],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,8 @@ export function registerTransactionErrorRateRuleType({
],
},
},
...termQuery(SERVICE_NAME, ruleParams.serviceName, {
queryEmptyString: false,
}),
...termQuery(TRANSACTION_TYPE, ruleParams.transactionType, {
queryEmptyString: false,
}),
...termQuery(SERVICE_NAME, ruleParams.serviceName),
...termQuery(TRANSACTION_TYPE, ruleParams.transactionType),
...environmentQuery(ruleParams.environment),
],
},
Expand Down

0 comments on commit fce4ef8

Please sign in to comment.