Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Vis: Default editor] EUIficate IP Ranges #36896

Merged
merged 23 commits into from
Jun 4, 2019
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
74097dd
Create IpRangeType and IpRanges controls
maryia-lapata May 20, 2019
0f2abdc
Add validation
maryia-lapata May 20, 2019
6e19ab3
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 21, 2019
b84928d
Refactoring
maryia-lapata May 21, 2019
8c130cd
Add behavior when discarding changes
maryia-lapata May 22, 2019
5faa3d1
Refactoring: create common input list
maryia-lapata May 22, 2019
5d358c1
Remove old template
maryia-lapata May 22, 2019
d8b582a
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 24, 2019
702d5b3
Move add btn to input_list, add placeholder
maryia-lapata May 24, 2019
fc4d91e
Remove unused directives
maryia-lapata May 24, 2019
fb73c67
Remove unused translations
maryia-lapata May 24, 2019
d036e78
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 27, 2019
c0e269a
Refactoring
maryia-lapata May 27, 2019
e182586
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 28, 2019
9c98c14
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 29, 2019
865afa1
Use EuiButtonGroup instead of toggle button
maryia-lapata May 29, 2019
bb54663
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 30, 2019
7a9e8ae
Update options ids, add aria-labels
maryia-lapata May 30, 2019
ba0d24a
Remove unused translations
maryia-lapata May 30, 2019
16a8d1a
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata May 31, 2019
65f29b4
Merge branch 'master' into vis-editor-ip-ranges
maryia-lapata Jun 3, 2019
e8b711d
Update mask model, update TS, update aria labels
maryia-lapata Jun 3, 2019
640d075
Add validation for CIRD mask
maryia-lapata Jun 3, 2019
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

This file was deleted.

96 changes: 0 additions & 96 deletions src/legacy/ui/public/agg_types/__tests__/directives/validate_ip.js

This file was deleted.

8 changes: 4 additions & 4 deletions src/legacy/ui/public/agg_types/buckets/ip_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
*/

import _ from 'lodash';
import '../directives/validate_ip';
import '../directives/validate_cidr_mask';
import { BucketAggType } from './_bucket_agg_type';
import { createFilterIpRange } from './create_filter/ip_range';
import ipRangesTemplate from '../controls/ip_ranges.html';
import { IpRangeTypeParamEditor } from '../controls/ip_range_type';
import { IpRangesParamEditor } from '../controls/ip_ranges';
import { i18n } from '@kbn/i18n';

export const ipRangeBucketAgg = new BucketAggType({
Expand Down Expand Up @@ -52,6 +51,7 @@ export const ipRangeBucketAgg = new BucketAggType({
filterFieldTypes: 'ip'
}, {
name: 'ipRangeType',
editorComponent: IpRangeTypeParamEditor,
default: 'fromTo',
write: _.noop
}, {
Expand All @@ -66,7 +66,7 @@ export const ipRangeBucketAgg = new BucketAggType({
{ mask: '128.0.0.0/2' }
]
},
editor: ipRangesTemplate,
editorComponent: IpRangesParamEditor,
write: function (aggConfig, output) {
const ipRangeType = aggConfig.params.ipRangeType;
let ranges = aggConfig.params.ranges[ipRangeType];
Expand Down
131 changes: 131 additions & 0 deletions src/legacy/ui/public/agg_types/controls/components/from_to_list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React from 'react';
import { EuiFieldText, EuiFlexItem } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import Ipv4Address from '../../../utils/ipv4_address';
import { InputList, InputListConfig, InputModel, InputObject } from './input_list';

const EMPTY_STRING = '';

export interface FromToObject extends InputObject {
from?: string;
to?: string;
}

interface FromToItem {
model: string;
value: string;
isInvalid: boolean;
}

type FromToModel = InputModel & {
from: FromToItem;
to: FromToItem;
};

interface FromToListProps {
list: FromToObject[];
showValidation: boolean;
onBlur(): void;
onChange(list: FromToObject[]): void;
setValidity(isValid: boolean): void;
}

function FromToList({ showValidation, onBlur, ...rest }: FromToListProps) {
const fromToListConfig: InputListConfig = {
defaultValue: {
from: { value: '0.0.0.0', model: '0.0.0.0', isInvalid: false },
to: { value: '255.255.255.255', model: '255.255.255.255', isInvalid: false },
},
defaultEmptyValue: {
from: { value: EMPTY_STRING, model: EMPTY_STRING, isInvalid: false },
to: { value: EMPTY_STRING, model: EMPTY_STRING, isInvalid: false },
},
validateClass: Ipv4Address,
getModelValue: (item: FromToObject) => ({
from: {
value: item.from || EMPTY_STRING,
model: item.from || EMPTY_STRING,
isInvalid: false,
},
to: { value: item.to || EMPTY_STRING, model: item.to || EMPTY_STRING, isInvalid: false },
}),
getModel: (models: FromToModel[], index, modelName: 'from' | 'to') => models[index][modelName],
getRemoveBtnAriaLabel: (item: FromToModel) =>
i18n.translate('common.ui.aggTypes.ipRanges.removeRangeAriaLabel', {
defaultMessage: 'Remove the range of {from} to {to}',
values: { from: item.from.value, to: item.to.value },
}),
onChangeFn: ({ from, to }: FromToModel) => {
const result: FromToObject = {};
if (from.model) {
result.from = from.model;
}
if (to.model) {
result.to = to.model;
}
return result;
},
hasInvalidValuesFn: ({ from, to }: FromToModel) => from.isInvalid || to.isInvalid,
renderInputRow: (item: FromToModel, index, onChangeValue) => (
<>
<EuiFlexItem>
<EuiFieldText
aria-label={i18n.translate('common.ui.aggTypes.ipRanges.ipRangeFromAriaLabel', {
defaultMessage: 'IP range from: {value}',
values: { value: item.value },
})}
isInvalid={showValidation ? item.from.isInvalid : false}
placeholder="*"
onChange={ev => {
onChangeValue(index, ev.target.value, 'from');
}}
value={item.from.value}
onBlur={onBlur}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFieldText
aria-label={i18n.translate('common.ui.aggTypes.ipRanges.ipRangeToAriaLabel', {
defaultMessage: 'IP range to: {value}',
values: { value: item.value },
})}
isInvalid={showValidation ? item.to.isInvalid : false}
placeholder="*"
onChange={ev => {
onChangeValue(index, ev.target.value, 'to');
}}
value={item.to.value}
onBlur={onBlur}
/>
</EuiFlexItem>
</>
),
validateModel: (validateFn, object: FromToObject, model: FromToModel) => {
validateFn(object.from, model.from);
validateFn(object.to, model.to);
},
};

return <InputList config={fromToListConfig} {...rest} />;
}

export { FromToList };
Loading