From 50b4141a2118cd84b69c7e49e2acab6b8adab74b Mon Sep 17 00:00:00 2001 From: Jen Huang Date: Tue, 17 Mar 2020 10:24:58 -0700 Subject: [PATCH] [Ingest] Support `show_user` package registry flag (#60338) * Support registry `show_user` var definition property (elastic/package-registry#266) * Add tests --- .../ingest_manager/common/types/models/epm.ts | 1 + .../components/datasource_input_config.tsx | 7 ++- .../datasource_input_stream_config.tsx | 7 ++- .../create_datasource_page/services/index.ts | 6 ++ .../services/is_advanced_var.test.ts | 62 +++++++++++++++++++ .../services/is_advanced_var.ts | 13 ++++ 6 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/index.ts create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.test.ts create mode 100644 x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.ts diff --git a/x-pack/plugins/ingest_manager/common/types/models/epm.ts b/x-pack/plugins/ingest_manager/common/types/models/epm.ts index 6b8403b74a759..28786530db018 100644 --- a/x-pack/plugins/ingest_manager/common/types/models/epm.ts +++ b/x-pack/plugins/ingest_manager/common/types/models/epm.ts @@ -186,6 +186,7 @@ export interface RegistryVarsEntry { description?: string; type: string; required?: boolean; + show_user?: boolean; multi?: boolean; default?: string | string[]; os?: { diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_config.tsx index 39f2f048ab88d..69d2194638441 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_config.tsx @@ -15,6 +15,7 @@ import { EuiTitle, } from '@elastic/eui'; import { DatasourceInput, RegistryVarsEntry } from '../../../../types'; +import { isAdvancedVar } from '../services'; import { DatasourceInputVarField } from './datasource_input_var_field'; export const DatasourceInputConfig: React.FunctionComponent<{ @@ -30,10 +31,10 @@ export const DatasourceInputConfig: React.FunctionComponent<{ if (packageInputVars) { packageInputVars.forEach(varDef => { - if (varDef.required && !varDef.default) { - requiredVars.push(varDef); - } else { + if (isAdvancedVar(varDef)) { advancedVars.push(varDef); + } else { + requiredVars.push(varDef); } }); } diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_stream_config.tsx b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_stream_config.tsx index e4b138932cb53..1f483f1911bcc 100644 --- a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_stream_config.tsx +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/components/datasource_input_stream_config.tsx @@ -16,6 +16,7 @@ import { EuiButtonEmpty, } from '@elastic/eui'; import { DatasourceInputStream, RegistryStream, RegistryVarsEntry } from '../../../../types'; +import { isAdvancedVar } from '../services'; import { DatasourceInputVarField } from './datasource_input_var_field'; export const DatasourceInputStreamConfig: React.FunctionComponent<{ @@ -31,10 +32,10 @@ export const DatasourceInputStreamConfig: React.FunctionComponent<{ if (packageInputStream.vars && packageInputStream.vars.length) { packageInputStream.vars.forEach(varDef => { - if (varDef.required && !varDef.default) { - requiredVars.push(varDef); - } else { + if (isAdvancedVar(varDef)) { advancedVars.push(varDef); + } else { + requiredVars.push(varDef); } }); } diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/index.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/index.ts new file mode 100644 index 0000000000000..44e5bfa41cb9b --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/index.ts @@ -0,0 +1,6 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +export { isAdvancedVar } from './is_advanced_var'; diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.test.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.test.ts new file mode 100644 index 0000000000000..67796d69863fa --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.test.ts @@ -0,0 +1,62 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { isAdvancedVar } from './is_advanced_var'; + +describe('Ingest Manager - isAdvancedVar', () => { + it('returns true for vars that should be show under advanced options', () => { + expect( + isAdvancedVar({ + name: 'mock_var', + type: 'text', + required: true, + default: 'default string', + }) + ).toBe(true); + + expect( + isAdvancedVar({ + name: 'mock_var', + type: 'text', + default: 'default string', + }) + ).toBe(true); + + expect( + isAdvancedVar({ + name: 'mock_var', + type: 'text', + }) + ).toBe(true); + }); + + it('returns false for vars that should be show by default', () => { + expect( + isAdvancedVar({ + name: 'mock_var', + type: 'text', + required: true, + default: 'default string', + show_user: true, + }) + ).toBe(false); + + expect( + isAdvancedVar({ + name: 'mock_var', + type: 'text', + required: true, + }) + ).toBe(false); + + expect( + isAdvancedVar({ + name: 'mock_var', + type: 'text', + show_user: true, + }) + ).toBe(false); + }); +}); diff --git a/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.ts b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.ts new file mode 100644 index 0000000000000..398f1d675c5df --- /dev/null +++ b/x-pack/plugins/ingest_manager/public/applications/ingest_manager/sections/agent_config/create_datasource_page/services/is_advanced_var.ts @@ -0,0 +1,13 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { RegistryVarsEntry } from '../../../../types'; + +export const isAdvancedVar = (varDef: RegistryVarsEntry): boolean => { + if (varDef.show_user || (varDef.required && !varDef.default)) { + return false; + } + return true; +};