Skip to content

Commit db2aa05

Browse files
committed
fix can't edit a scripted field with special char
1 parent 718702c commit db2aa05

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/plugins/index_pattern_management/public/components/edit_index_pattern/create_edit_field/create_edit_field_container.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,31 @@ import { useKibana } from '../../../../../../plugins/kibana_react/public';
2626
import { IndexPatternManagmentContext } from '../../../types';
2727
import { CreateEditField } from './create_edit_field';
2828

29-
export type CreateEditFieldContainerProps = RouteComponentProps<{ id: string; fieldName: string }>;
29+
export type CreateEditFieldContainerProps = RouteComponentProps<{ id: string; fieldName?: string }>;
3030

3131
const CreateEditFieldCont: React.FC<CreateEditFieldContainerProps> = ({ ...props }) => {
3232
const { setBreadcrumbs, data } = useKibana<IndexPatternManagmentContext>().services;
3333
const [indexPattern, setIndexPattern] = useState<IndexPattern>();
34+
const fieldName =
35+
props.match.params.fieldName && decodeURIComponent(props.match.params.fieldName);
3436

3537
useEffect(() => {
3638
data.indexPatterns.get(props.match.params.id).then((ip: IndexPattern) => {
3739
setIndexPattern(ip);
3840
if (ip) {
3941
setBreadcrumbs(
40-
props.match.params.fieldName
41-
? getEditFieldBreadcrumbs(ip, props.match.params.fieldName)
42-
: getCreateFieldBreadcrumbs(ip)
42+
fieldName ? getEditFieldBreadcrumbs(ip, fieldName) : getCreateFieldBreadcrumbs(ip)
4343
);
4444
}
4545
});
46-
}, [props.match.params.id, props.match.params.fieldName, setBreadcrumbs, data.indexPatterns]);
46+
}, [props.match.params.id, fieldName, setBreadcrumbs, data.indexPatterns]);
4747

4848
if (indexPattern) {
4949
return (
5050
<CreateEditField
5151
indexPattern={indexPattern}
52-
mode={props.match.params.fieldName ? 'edit' : 'create'}
53-
fieldName={props.match.params.fieldName}
52+
mode={fieldName ? 'edit' : 'create'}
53+
fieldName={fieldName}
5454
/>
5555
);
5656
} else {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { getPath } from './utils';
21+
import { IndexPatternField, IndexPattern } from '../../../../../data/public';
22+
23+
test('getPath() should encode "fieldName"', () => {
24+
expect(
25+
getPath(
26+
({ name: 'Memory: Allocated Bytes/sec' } as unknown) as IndexPatternField,
27+
({ id: 'id' } as unknown) as IndexPattern
28+
)
29+
).toMatchInlineSnapshot(`"/patterns/id/field/Memory%3A%20Allocated%20Bytes%2Fsec"`);
30+
});

src/plugins/index_pattern_management/public/components/edit_index_pattern/tabs/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export function getTabs(
117117
}
118118

119119
export function getPath(field: IndexPatternField, indexPattern: IndexPattern) {
120-
return `/patterns/${indexPattern?.id}/field/${field.name}`;
120+
return `/patterns/${indexPattern?.id}/field/${encodeURIComponent(field.name)}`;
121121
}
122122

123123
const allTypesDropDown = i18n.translate(

0 commit comments

Comments
 (0)