Skip to content

Commit

Permalink
fix can't edit a scripted field with special char (elastic#79842)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Oct 8, 2020
1 parent 9a74a36 commit 1cc6175
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ import { useKibana } from '../../../../../../plugins/kibana_react/public';
import { IndexPatternManagmentContext } from '../../../types';
import { CreateEditField } from './create_edit_field';

export type CreateEditFieldContainerProps = RouteComponentProps<{ id: string; fieldName: string }>;
export type CreateEditFieldContainerProps = RouteComponentProps<{ id: string; fieldName?: string }>;

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

useEffect(() => {
data.indexPatterns.get(props.match.params.id).then((ip: IndexPattern) => {
setIndexPattern(ip);
if (ip) {
setBreadcrumbs(
props.match.params.fieldName
? getEditFieldBreadcrumbs(ip, props.match.params.fieldName)
: getCreateFieldBreadcrumbs(ip)
fieldName ? getEditFieldBreadcrumbs(ip, fieldName) : getCreateFieldBreadcrumbs(ip)
);
}
});
}, [props.match.params.id, props.match.params.fieldName, setBreadcrumbs, data.indexPatterns]);
}, [props.match.params.id, fieldName, setBreadcrumbs, data.indexPatterns]);

if (indexPattern) {
return (
<CreateEditField
indexPattern={indexPattern}
mode={props.match.params.fieldName ? 'edit' : 'create'}
fieldName={props.match.params.fieldName}
mode={fieldName ? 'edit' : 'create'}
fieldName={fieldName}
/>
);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { getPath } from './utils';
import { IndexPatternField, IndexPattern } from '../../../../../data/public';

test('getPath() should encode "fieldName"', () => {
expect(
getPath(
({ name: 'Memory: Allocated Bytes/sec' } as unknown) as IndexPatternField,
({ id: 'id' } as unknown) as IndexPattern
)
).toMatchInlineSnapshot(`"/patterns/id/field/Memory%3A%20Allocated%20Bytes%2Fsec"`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export function getTabs(
}

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

const allTypesDropDown = i18n.translate(
Expand Down

0 comments on commit 1cc6175

Please sign in to comment.