Skip to content

Commit ce140d5

Browse files
address review feedback
1 parent 9470201 commit ce140d5

File tree

8 files changed

+42
-35
lines changed

8 files changed

+42
-35
lines changed

x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/component_template_list.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ScopedHistory } from 'kibana/public';
1212

1313
import { SectionLoading, ComponentTemplateDeserialized } from '../shared_imports';
1414
import { UIM_COMPONENT_TEMPLATE_LIST_LOAD } from '../constants';
15+
import { attemptToDecodeURI } from '../lib';
1516
import { useComponentTemplatesContext } from '../component_templates_context';
1617
import { ComponentTemplateDetailsFlyout } from '../component_template_details';
1718
import { EmptyPrompt } from './empty_prompt';
@@ -35,15 +36,21 @@ export const ComponentTemplateList: React.FunctionComponent<Props> = ({
3536
const [componentTemplatesToDelete, setComponentTemplatesToDelete] = useState<string[]>([]);
3637

3738
const goToComponentTemplateList = () => {
38-
return history.push('component_templates');
39+
return history.push({
40+
pathname: 'component_templates',
41+
});
3942
};
4043

4144
const goToEditComponentTemplate = (name: string) => {
42-
return history.push(`edit_component_template/${encodeURIComponent(name)}`);
45+
return history.push({
46+
pathname: encodeURI(`edit_component_template/${encodeURIComponent(name)}`),
47+
});
4348
};
4449

4550
const goToCloneComponentTemplate = (name: string) => {
46-
return history.push(`create_component_template/${encodeURIComponent(name)}`);
51+
return history.push({
52+
pathname: encodeURI(`create_component_template/${encodeURIComponent(name)}`),
53+
});
4754
};
4855

4956
// Track component loaded
@@ -110,14 +117,16 @@ export const ComponentTemplateList: React.FunctionComponent<Props> = ({
110117
defaultMessage: 'Edit',
111118
}),
112119
icon: 'pencil',
113-
handleActionClick: () => goToEditComponentTemplate(componentTemplateName),
120+
handleActionClick: () =>
121+
goToEditComponentTemplate(attemptToDecodeURI(componentTemplateName)),
114122
},
115123
{
116124
name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.cloneActionLabel', {
117125
defaultMessage: 'Clone',
118126
}),
119127
icon: 'copy',
120-
handleActionClick: () => goToCloneComponentTemplate(componentTemplateName),
128+
handleActionClick: () =>
129+
goToCloneComponentTemplate(attemptToDecodeURI(componentTemplateName)),
121130
},
122131
{
123132
name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.deleteButtonLabel', {
@@ -128,7 +137,7 @@ export const ComponentTemplateList: React.FunctionComponent<Props> = ({
128137
details._kbnMeta.usedBy.length > 0,
129138
closePopoverOnClick: true,
130139
handleActionClick: () => {
131-
setComponentTemplatesToDelete([componentTemplateName]);
140+
setComponentTemplatesToDelete([attemptToDecodeURI(componentTemplateName)]);
132141
},
133142
},
134143
]}

x-pack/plugins/index_management/public/application/components/component_templates/component_template_list/table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ export const ComponentTable: FunctionComponent<Props> = ({
150150
{...reactRouterNavigate(
151151
history,
152152
{
153-
pathname: `/component_templates/${encodeURIComponent(name)}`,
153+
pathname: encodeURI(`/component_templates/${encodeURIComponent(name)}`),
154154
},
155155
() => trackMetric('click', UIM_COMPONENT_TEMPLATE_DETAILS)
156156
)}

x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_clone/component_template_clone.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ export interface Params {
2020

2121
export const ComponentTemplateClone: FunctionComponent<RouteComponentProps<Params>> = (props) => {
2222
const { sourceComponentTemplateName } = props.match.params;
23-
const decodedSourceComponentTemplateName = attemptToDecodeURI(sourceComponentTemplateName);
23+
const decodedSourceName = attemptToDecodeURI(sourceComponentTemplateName);
2424

2525
const { toasts, api } = useComponentTemplatesContext();
2626

27-
const {
28-
error,
29-
data: componentTemplateToClone,
30-
isLoading,
31-
isInitialRequest,
32-
} = api.useLoadComponentTemplate(decodedSourceComponentTemplateName);
27+
const { error, data: componentTemplateToClone, isLoading } = api.useLoadComponentTemplate(
28+
decodedSourceName
29+
);
3330

3431
useEffect(() => {
3532
if (error && !isLoading) {
@@ -43,7 +40,7 @@ export const ComponentTemplateClone: FunctionComponent<RouteComponentProps<Param
4340
// eslint-disable-next-line react-hooks/exhaustive-deps
4441
}, [error, isLoading]);
4542

46-
if (isLoading && isInitialRequest) {
43+
if (isLoading) {
4744
return (
4845
<SectionLoading>
4946
<FormattedMessage

x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_create/component_template_create.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export const ComponentTemplateCreate: React.FunctionComponent<RouteComponentProp
4343
return;
4444
}
4545

46-
history.push(`/component_templates/${encodeURIComponent(name)}`);
46+
history.push({
47+
pathname: encodeURI(`/component_templates/${encodeURIComponent(name)}`),
48+
});
4749
};
4850

4951
const clearSaveError = () => {

x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_edit/component_template_edit.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export const ComponentTemplateEdit: React.FunctionComponent<RouteComponentProps<
4949
return;
5050
}
5151

52-
history.push(`/component_templates/${encodeURIComponent(name)}`);
52+
history.push({
53+
pathname: encodeURI(`/component_templates/${encodeURIComponent(name)}`),
54+
});
5355
};
5456

5557
const clearSaveError = () => {

x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_logistics_schema.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,15 @@ export const logisticsFormSchema: FormSchema = {
8787
deserializer: stringifyJson,
8888
validations: [
8989
{
90-
validator: (validationArg) => {
91-
if (!validationArg.value) {
92-
return;
93-
}
94-
return isJsonField(
95-
i18n.translate(
96-
'xpack.idxMgmt.componentTemplateForm.stepLogistics.validation.metaJsonError',
97-
{
98-
defaultMessage: 'The input is not valid.',
99-
}
100-
)
101-
)(validationArg);
102-
},
90+
validator: isJsonField(
91+
i18n.translate(
92+
'xpack.idxMgmt.componentTemplateForm.stepLogistics.validation.metaJsonError',
93+
{
94+
defaultMessage: 'The input is not valid.',
95+
}
96+
),
97+
{ allowEmptyString: true }
98+
),
10399
},
104100
],
105101
},

x-pack/plugins/index_management/public/application/components/component_templates/component_template_wizard/component_template_form/steps/step_review.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ interface Props {
4848
}
4949

5050
export const StepReview: React.FunctionComponent<Props> = React.memo(({ componentTemplate }) => {
51-
const { name, version } = componentTemplate!;
51+
const { name, version } = componentTemplate;
5252

5353
const serializedComponentTemplate = serializeComponentTemplate(
54-
stripEmptyFields(componentTemplate!, {
54+
stripEmptyFields(componentTemplate, {
5555
types: ['string', 'object'],
5656
}) as ComponentTemplateDeserialized
5757
);
@@ -73,7 +73,7 @@ export const StepReview: React.FunctionComponent<Props> = React.memo(({ componen
7373
<EuiFlexItem>
7474
<EuiDescriptionList textStyle="reverse">
7575
{/* Version */}
76-
{version && (
76+
{version !== '' && (
7777
<>
7878
<EuiDescriptionListTitle>
7979
<FormattedMessage

x-pack/plugins/index_management/public/application/components/component_templates/lib/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ export const attemptToDecodeURI = (value: string) => {
88
let result: string;
99

1010
try {
11-
result = decodeURIComponent(value);
11+
result = decodeURI(value);
12+
result = decodeURIComponent(result);
1213
} catch (e) {
13-
result = value;
14+
result = decodeURIComponent(value);
1415
}
1516

1617
return result;

0 commit comments

Comments
 (0)