forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
elastic#69750 Auto-expand inputs with required & empty (invalid) vars
- Loading branch information
Showing
8 changed files
with
156 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...ons/agent_config/create_package_config_page/services/has_invalid_but_required_var.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* 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 { hasInvalidButRequiredVar } from './has_invalid_but_required_var'; | ||
|
||
describe('Ingest Manager - hasInvalidButRequiredVar', () => { | ||
it('returns true for invalid & required vars', () => { | ||
expect( | ||
hasInvalidButRequiredVar( | ||
[ | ||
{ | ||
name: 'mock_var', | ||
type: 'text', | ||
required: true, | ||
}, | ||
], | ||
{} | ||
) | ||
).toBe(true); | ||
|
||
expect( | ||
hasInvalidButRequiredVar( | ||
[ | ||
{ | ||
name: 'mock_var', | ||
type: 'text', | ||
required: true, | ||
}, | ||
], | ||
{ | ||
mock_var: { | ||
value: undefined, | ||
}, | ||
} | ||
) | ||
).toBe(true); | ||
}); | ||
|
||
it('returns false for valid & required vars', () => { | ||
expect( | ||
hasInvalidButRequiredVar( | ||
[ | ||
{ | ||
name: 'mock_var', | ||
type: 'text', | ||
required: true, | ||
}, | ||
], | ||
{ | ||
mock_var: { | ||
value: 'foo', | ||
}, | ||
} | ||
) | ||
).toBe(false); | ||
}); | ||
|
||
it('returns false for optional vars', () => { | ||
expect( | ||
hasInvalidButRequiredVar( | ||
[ | ||
{ | ||
name: 'mock_var', | ||
type: 'text', | ||
}, | ||
], | ||
{ | ||
mock_var: { | ||
value: 'foo', | ||
}, | ||
} | ||
) | ||
).toBe(false); | ||
|
||
expect( | ||
hasInvalidButRequiredVar( | ||
[ | ||
{ | ||
name: 'mock_var', | ||
type: 'text', | ||
required: false, | ||
}, | ||
], | ||
{ | ||
mock_var: { | ||
value: undefined, | ||
}, | ||
} | ||
) | ||
).toBe(false); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...sections/agent_config/create_package_config_page/services/has_invalid_but_required_var.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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 { PackageConfigConfigRecord, RegistryVarsEntry } from '../../../../types'; | ||
import { validatePackageConfigConfig } from './'; | ||
|
||
export const hasInvalidButRequiredVar = ( | ||
registryVars?: RegistryVarsEntry[], | ||
packageConfigVars?: PackageConfigConfigRecord | ||
): boolean => { | ||
return ( | ||
!packageConfigVars || | ||
Boolean( | ||
registryVars && | ||
registryVars.find( | ||
(registryVar) => | ||
registryVar.required && | ||
(!packageConfigVars[registryVar.name] || | ||
validatePackageConfigConfig(packageConfigVars[registryVar.name], registryVar)?.length) | ||
) | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters