forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Vis: Default editor] EUIficate IP Ranges (elastic#36896)
* Create IpRangeType and IpRanges controls * Add validation * Refactoring * Add behavior when discarding changes * Refactoring: create common input list * Remove old template * Move add btn to input_list, add placeholder * Remove unused directives * Remove unused translations * Refactoring * Use EuiButtonGroup instead of toggle button * Update options ids, add aria-labels * Remove unused translations * Update mask model, update TS, update aria labels * Add validation for CIRD mask
- Loading branch information
1 parent
3299c4d
commit c952920
Showing
15 changed files
with
600 additions
and
490 deletions.
There are no files selected for viewing
104 changes: 0 additions & 104 deletions
104
src/legacy/ui/public/agg_types/__tests__/directives/validate_cidr_mask.js
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
src/legacy/ui/public/agg_types/__tests__/directives/validate_ip.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
src/legacy/ui/public/agg_types/controls/components/from_to_list.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* 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, InputItem } from './input_list'; | ||
|
||
const EMPTY_STRING = ''; | ||
|
||
export interface FromToObject extends InputObject { | ||
from?: string; | ||
to?: string; | ||
} | ||
|
||
type FromToModel = InputModel & { | ||
from: InputItem; | ||
to: InputItem; | ||
}; | ||
|
||
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 }, | ||
}), | ||
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.from.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.to.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 }; |
Oops, something went wrong.