From 8a8c2d37104990035b43076307e4fc75eb6afd56 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 16 Apr 2020 21:21:12 -0400 Subject: [PATCH] [Ingest] Fix agent config key sorting (#63488) --- .../details_page/components/yaml/index.tsx | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx index c1cdde730837fe..56b109a9bc062f 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/details_page/components/yaml/index.tsx @@ -25,7 +25,15 @@ import { import { ShellEnrollmentInstructions } from '../../../../../components/enrollment_instructions'; import { Loading } from '../../../../../components'; -const CONFIG_KEYS_ORDER = ['id', 'revision', 'outputs', 'datasources']; +const CONFIG_KEYS_ORDER = [ + 'id', + 'revision', + 'outputs', + 'datasources', + 'enabled', + 'package', + 'input', +]; export const ConfigYamlView = memo<{ config: AgentConfig }>(({ config }) => { const core = useCore(); @@ -47,7 +55,17 @@ export const ConfigYamlView = memo<{ config: AgentConfig }>(({ config }) => { {dump(fullConfigRequest.data.item, { sortKeys: (keyA: string, keyB: string) => { - return CONFIG_KEYS_ORDER.indexOf(keyA) - CONFIG_KEYS_ORDER.indexOf(keyB); + const indexA = CONFIG_KEYS_ORDER.indexOf(keyA); + const indexB = CONFIG_KEYS_ORDER.indexOf(keyB); + if (indexA >= 0 && indexB < 0) { + return -1; + } + + if (indexA < 0 && indexB >= 0) { + return 1; + } + + return indexA - indexB; }, })}