Skip to content

Commit

Permalink
Cleaned up some not used params and added position popover definition
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Feb 5, 2020
1 parent 293d985 commit e4e9f4b
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,13 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
// reset time field and expression fields if indices are deleted
if (indices.length === 0) {
setTimeFieldOptions([firstFieldOption]);
setAlertParams('timeFields', []);

setDefaultExpressionValues();
return;
}
const currentEsFields = await getFields(indices);
const timeFields = getTimeFieldOptions(currentEsFields as any);

setEsFields(currentEsFields);
setAlertParams('timeFields', timeFields);
setTimeFieldOptions([firstFieldOption, ...timeFields]);
}}
onSearchChange={async search => {
Expand Down Expand Up @@ -374,8 +371,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
</EuiFlexItem>
<EuiFlexItem grow={false}>
<WhenExpression
aggType={aggType}
defaultAggType={DEFAULT_VALUES.AGGREGATION_TYPE}
aggType={aggType ?? DEFAULT_VALUES.AGGREGATION_TYPE}
onChangeSelectedAggType={(selectedAggType: string) =>
setAlertParams('aggType', selectedAggType)
}
Expand Down Expand Up @@ -412,9 +408,8 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
</EuiFlexItem>
<EuiFlexItem grow={false}>
<ThresholdExpression
thresholdComparator={thresholdComparator || DEFAULT_VALUES.THRESHOLD_COMPARATOR}
thresholdComparator={thresholdComparator ?? DEFAULT_VALUES.THRESHOLD_COMPARATOR}
threshold={threshold}
defaultThresholdComparator={DEFAULT_VALUES.THRESHOLD_COMPARATOR}
errors={errors}
onChangeSelectedThreshold={selectedThresholds =>
setAlertParams('threshold', selectedThresholds)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ describe('for the last expression', () => {
wrapper.contains(
<EuiPopoverTitle>
<FormattedMessage
id="xpack.triggersActionsUI.common.expressionItems.forTheLast.popoverTitle"
defaultMessage="For the last"
id="xpack.triggersActionsUI.sections.alertAdd.threshold.forTheLastButtonLabel"
values={{}}
/>
</EuiPopoverTitle>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ interface ForLastExpressionProps {
errors: { [key: string]: string[] };
onChangeWindowSize: (selectedWindowSize: number | '') => void;
onChangeWindowUnit: (selectedWindowUnit: string) => void;
popupPosition?:
| 'upCenter'
| 'upLeft'
| 'upRight'
| 'downCenter'
| 'downLeft'
| 'downRight'
| 'leftCenter'
| 'leftUp'
| 'leftDown'
| 'rightCenter'
| 'rightUp'
| 'rightDown';
}

export const ForLastExpression = ({
Expand All @@ -35,16 +48,16 @@ export const ForLastExpression = ({
errors,
onChangeWindowSize,
onChangeWindowUnit,
popupPosition,
}: ForLastExpressionProps) => {
const [alertDurationPopoverOpen, setAlertDurationPopoverOpen] = useState(false);

return (
<EuiPopover
id="watchDurationPopover"
button={
<EuiExpression
description={i18n.translate(
'xpack.triggersActionsUI.sections.alertAdd.threshold.forTheLastLabel',
'xpack.triggersActionsUI.common.expressionItems.forTheLast.descriptionLabel',
{
defaultMessage: 'for the last',
}
Expand All @@ -66,12 +79,12 @@ export const ForLastExpression = ({
}}
ownFocus
withTitle
anchorPosition="downLeft"
anchorPosition={popupPosition ?? 'downLeft'}
>
<div>
<EuiPopoverTitle>
<FormattedMessage
id="xpack.triggersActionsUI.sections.alertAdd.threshold.forTheLastButtonLabel"
id="xpack.triggersActionsUI.common.expressionItems.forTheLast.popoverTitle"
defaultMessage="For the last"
/>
</EuiPopoverTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('group by expression', () => {
<EuiSelect
data-test-subj="fieldsExpressionSelect"
isInvalid={false}
onBlur={[Function]}
onChange={[Function]}
options={
Array [
Expand All @@ -76,7 +77,6 @@ describe('group by expression', () => {
},
]
}
value=""
/>
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ interface GroupByExpressionProps {
customGroupByTypes?: {
[key: string]: GroupByType;
};
popupPosition?:
| 'upCenter'
| 'upLeft'
| 'upRight'
| 'downCenter'
| 'downLeft'
| 'downRight'
| 'leftCenter'
| 'leftUp'
| 'leftDown'
| 'rightCenter'
| 'rightUp'
| 'rightDown';
}

export const GroupByExpression = ({
Expand All @@ -43,30 +56,39 @@ export const GroupByExpression = ({
termSize,
termField,
customGroupByTypes,
popupPosition,
}: GroupByExpressionProps) => {
const groupByTypes = customGroupByTypes ?? builtInGroupByTypes;
const [groupByPopoverOpen, setGroupByPopoverOpen] = useState(false);
const MIN_TERM_SIZE = 1;
const firstFieldOption = {
text: i18n.translate('xpack.triggersActionsUI.common.groupByType.timeFieldOptionLabel', {
defaultMessage: 'Select a field',
}),
text: i18n.translate(
'xpack.triggersActionsUI.common.expressionItems.groupByType.timeFieldOptionLabel',
{
defaultMessage: 'Select a field',
}
),
value: '',
};

return (
<EuiPopover
id="groupByPopover"
button={
<EuiExpression
description={`${
groupByTypes[groupBy].sizeRequired
? i18n.translate('xpack.triggersActionsUI.common.groupByType.groupedOverLabel', {
defaultMessage: 'grouped over',
})
: i18n.translate('xpack.triggersActionsUI.common.groupByType.overLabel', {
defaultMessage: 'over',
})
? i18n.translate(
'xpack.triggersActionsUI.common.expressionItems.groupByType.groupedOverLabel',
{
defaultMessage: 'grouped over',
}
)
: i18n.translate(
'xpack.triggersActionsUI.common.expressionItems.groupByType.overLabel',
{
defaultMessage: 'over',
}
)
}`}
value={`${groupByTypes[groupBy].text} ${
groupByTypes[groupBy].sizeRequired
Expand All @@ -86,13 +108,16 @@ export const GroupByExpression = ({
}}
ownFocus
withTitle
anchorPosition="downRight"
anchorPosition={popupPosition ?? 'downRight'}
>
<div>
<EuiPopoverTitle>
{i18n.translate('xpack.triggersActionsUI.common.groupByType.overButtonLabel', {
defaultMessage: 'over',
})}
{i18n.translate(
'xpack.triggersActionsUI.common.expressionItems.groupByType.overButtonLabel',
{
defaultMessage: 'over',
}
)}
</EuiPopoverTitle>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ describe('of expression', () => {
<EuiComboBox
compressed={false}
data-test-subj="availablefieldsOptionsComboBox"
fullWidth={false}
fullWidth={true}
isClearable={true}
isInvalid={false}
noSuggestions={true}
onChange={[Function]}
options={Array []}
placeholder="Select a field"
Expand Down Expand Up @@ -77,9 +78,10 @@ describe('of expression', () => {
<EuiComboBox
compressed={false}
data-test-subj="availablefieldsOptionsComboBox"
fullWidth={false}
fullWidth={true}
isClearable={true}
isInvalid={false}
noSuggestions={false}
onChange={[Function]}
options={
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ interface OfExpressionProps {
customAggTypesOptions?: {
[key: string]: AggregationType;
};
popupPosition?:
| 'upCenter'
| 'upLeft'
| 'upRight'
| 'downCenter'
| 'downLeft'
| 'downRight'
| 'leftCenter'
| 'leftUp'
| 'leftDown'
| 'rightCenter'
| 'rightUp'
| 'rightDown';
}

export const OfExpression = ({
Expand All @@ -36,6 +49,7 @@ export const OfExpression = ({
onChangeSelectedAggField,
fields,
customAggTypesOptions,
popupPosition,
}: OfExpressionProps) => {
const [aggFieldPopoverOpen, setAggFieldPopoverOpen] = useState(false);
const firstFieldOption = {
Expand Down Expand Up @@ -63,9 +77,12 @@ export const OfExpression = ({
id="aggFieldPopover"
button={
<EuiExpression
description={i18n.translate('xpack.triggersActionsUI.common.of.ofLabel', {
defaultMessage: 'of',
})}
description={i18n.translate(
'xpack.triggersActionsUI.common.expressionItems.of.buttonLabel',
{
defaultMessage: 'of',
}
)}
value={aggField || firstFieldOption.text}
isActive={aggFieldPopoverOpen || !aggField}
onClick={() => {
Expand All @@ -78,40 +95,43 @@ export const OfExpression = ({
closePopover={() => {
setAggFieldPopoverOpen(false);
}}
ownFocus
withTitle
anchorPosition="upRight"
anchorPosition={popupPosition ?? 'downRight'}
zIndex={8000}
>
<EuiPopoverTitle>
{i18n.translate('xpack.triggersActionsUI.common.of.ofButtonLabel', {
defaultMessage: 'of',
})}
</EuiPopoverTitle>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem>
<EuiFormRow
fullWidth
isInvalid={errors.aggField.length > 0 && aggField !== undefined}
error={errors.aggField}
>
<EuiComboBox
<div>
<EuiPopoverTitle>
{i18n.translate('xpack.triggersActionsUI.common.expressionItems.of.popoverTitle', {
defaultMessage: 'of',
})}
</EuiPopoverTitle>
<EuiFlexGroup>
<EuiFlexItem grow={false} className="watcherThresholdAlertAggFieldContainer">
<EuiFormRow
fullWidth
singleSelection={{ asPlainText: true }}
data-test-subj="availablefieldsOptionsComboBox"
isInvalid={errors.aggField.length > 0 && aggField !== undefined}
placeholder={firstFieldOption.text}
options={availablefieldsOptions}
selectedOptions={aggField ? [{ label: aggField }] : []}
onChange={selectedOptions => {
onChangeSelectedAggField(
selectedOptions.length === 1 ? selectedOptions[0].label : undefined
);
setAggFieldPopoverOpen(false);
}}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
error={errors.aggField}
>
<EuiComboBox
fullWidth
singleSelection={{ asPlainText: true }}
data-test-subj="availablefieldsOptionsComboBox"
isInvalid={errors.aggField.length > 0 && aggField !== undefined}
placeholder={firstFieldOption.text}
options={availablefieldsOptions}
noSuggestions={!availablefieldsOptions.length}
selectedOptions={aggField ? [{ label: aggField }] : []}
onChange={selectedOptions => {
onChangeSelectedAggField(
selectedOptions.length === 1 ? selectedOptions[0].label : undefined
);
setAggFieldPopoverOpen(false);
}}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
</div>
</EuiPopover>
);
};
Loading

0 comments on commit e4e9f4b

Please sign in to comment.