-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
use union of strings instead of enum #62493
use union of strings instead of enum #62493
Conversation
Pinging @elastic/kibana-platform (Team:Platform) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alerting changes LGTM
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ES UI apps look good but I have a question about DX.
Checked these apps:
- Painless Lab
- Remote Clusters
- Search Profiler
- Snapshot Restore
- Watcher
In terms of DX, how are developers expected to discover the valid values of this string union? If I make a typo, the TS checker gives me this error:
x-pack/plugins/painless_lab/server/services/license.ts:40:34 - error TS2367: This condition will always return 'false' since the types 'LicenseCheckState' and '"vaild"' have no overlap.
40 const hasRequiredLicense = state === 'vaild';
What is the expected experience for a developer who is trying to fix this, or trying to compare against a different value?
@@ -37,7 +37,7 @@ export class License { | |||
) { | |||
licensing.license$.subscribe(license => { | |||
const { state, message } = license.check(pluginId, minimumLicenseType); | |||
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid; | |||
const hasRequiredLicense = state === 'valid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -82,7 +81,7 @@ export class PainlessLabUIPlugin implements Plugin<void, void, PluginDependencie | |||
PLUGIN.id, | |||
PLUGIN.minimumLicenseType | |||
); | |||
const isValidLicense = state === LICENSE_CHECK_STATE.Valid; | |||
const isValidLicense = state === 'valid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -54,7 +53,7 @@ export class RemoteClustersServerPlugin implements Plugin<void, void, any, any> | |||
|
|||
licensing.license$.subscribe(license => { | |||
const { state, message } = license.check(PLUGIN.getI18nName(), PLUGIN.minimumLicenseType); | |||
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid; | |||
const hasRequiredLicense = state === 'valid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -50,7 +49,7 @@ export class SearchProfilerUIPlugin implements Plugin<void, void, AppPublicPlugi | |||
const license = await licensing.license$.pipe(first()).toPromise(); | |||
const { state, message } = license.check(PLUGIN.id, PLUGIN.minimumLicenseType); | |||
const initialLicenseStatus = | |||
state === LICENSE_CHECK_STATE.Valid ? { valid: true } : { valid: false, message }; | |||
state === 'valid' ? { valid: true } : { valid: false, message }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -33,7 +31,7 @@ export class SearchProfilerServerPlugin implements Plugin { | |||
|
|||
licensing.license$.subscribe(license => { | |||
const { state, message } = license.check(PLUGIN.id, PLUGIN.minimumLicenseType); | |||
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid; | |||
const hasRequiredLicense = state === 'valid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -38,7 +37,7 @@ export class License { | |||
) { | |||
licensing.license$.subscribe(license => { | |||
const { state, message } = license.check(pluginId, minimumLicenseType); | |||
const hasRequiredLicense = state === LICENSE_CHECK_STATE.Valid; | |||
const hasRequiredLicense = state === 'valid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
import { TimeBuckets } from './legacy'; | ||
import { PLUGIN } from '../common/constants'; | ||
import { Dependencies } from './types'; | ||
|
||
const licenseToLicenseStatus = (license: ILicense): LicenseStatus => { | ||
const { state, message } = license.check(PLUGIN.ID, PLUGIN.MINIMUM_LICENSE_REQUIRED); | ||
return { | ||
valid: state === LICENSE_CHECK_STATE.Valid && license.getFeature(PLUGIN.ID).isAvailable, | ||
valid: state === 'valid' && license.getFeature(PLUGIN.ID).isAvailable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -73,7 +72,7 @@ export class WatcherServerPlugin implements Plugin<void, void, any, any> { | |||
|
|||
licensing.license$.subscribe(async license => { | |||
const { state, message } = license.check(PLUGIN.ID, PLUGIN.MINIMUM_LICENSE_REQUIRED); | |||
const hasMinimumLicense = state === LICENSE_CHECK_STATE.Valid; | |||
const hasMinimumLicense = state === 'valid'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ML/transform changes LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security changes LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maps/* lgtm, code review
|
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
Summary
Part of #62263
Prevents licensing plugin code leakage into plugin bundles.
Before:
After: