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

[7.x] fix can't edit a scripted field with special char (#79842) #79974

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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