-
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
Advanced Settings management => typescript #54477
Advanced Settings management => typescript #54477
Conversation
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.
Code LGTM, just a couple of comments about //@ts-ignore
usage.
@@ -764,6 +774,7 @@ export class Field extends PureComponent { | |||
helpText={this.renderHelpText(setting)} | |||
describedByIds={[`${setting.name}-aria`]} | |||
className="mgtAdvancedSettings__fieldRow" | |||
// @ts-ignore | |||
hasChildLabel={setting.type !== 'boolean'} |
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.
Can we cast here a variable to the required type, instead of using // @ts-ignore
.
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.
This is here due to incomplete eui typescript type defs.
// @ts-ignore | ||
if (!component.displayName) { | ||
// @ts-ignore | ||
component.displayName = id; |
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.
Instead of disabling TypeScript compiler for these lines, is it possible to cast here?
if (!(component as any).displayName) {
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.
Why is this actually needed ? The property seems present
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement | null;
propTypes?: WeakValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: Partial<P>;
displayName?: string;
}
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.
I removed the tests for this code as its just for debugging and it was giving me some trouble.
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.
Code LGTM, just a couple of comments about // @ts-ignore
usage.
Pinging @elastic/kibana-app-arch (Team:AppArch) |
@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.
Nothing seems to be impacting platform code, but saw it too late, so here's some NITs 😄
const registry: { [key: string]: any } = {}; | ||
type Id = string; |
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.
NIT: if Id aliases string, registry should probably be { [key: Id]: any }
or even { [key: Id]: FunctionComponent }
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.
Addressed.
src/legacy/core_plugins/kibana/public/management/sections/settings/types.ts
Outdated
Show resolved
Hide resolved
const settingPartial = { | ||
name: 'name', |
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.
Should this be explicitly typed?
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.
I attempted doing this and it seemed like more work than its worth - the types are verified when the functions are called. But I might be misunderstanding something.
…ttings_management
…kibana into typescript_settings_management
import { UiSettingsType } from 'src/core/server/types'; | ||
import { FieldSetting } from '../types'; | ||
|
||
export function getValType(def: Partial<FieldSetting>, value?: any): UiSettingsType { |
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.
Changing the return type from string to UiSettingsType is causing the current test failures.
There are a number of nonconforming def
values being passed. whyyyyyyy
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.
Allowing this to return undefined seems to allow everything to work. Will take a look at master to verify this is preexisting behavior and not something I introduced.
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.
Verified that this is behavior on master in this pr - #55551
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. Only component types can be improved and would be nice to not use //@ts-ignore
.
@@ -26,7 +29,7 @@ const registry = {}; | |||
* @param {*} id the id of the component to register | |||
* @param {*} component the component | |||
*/ | |||
export function tryRegisterSettingsComponent(id, component) { | |||
export function tryRegisterSettingsComponent(id: Id, component: FunctionComponent) { |
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.
export function tryRegisterSettingsComponent(id: Id, component: FunctionComponent) { | |
export function tryRegisterSettingsComponent(id: Id, component: React.ComponentType) { |
import { FunctionComponent } from 'react'; | ||
|
||
type Id = string; | ||
const registry: Record<Id, FunctionComponent> = {}; |
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.
const registry: Record<Id, FunctionComponent> = {}; | |
const registry: Record<Id, React.ComponentType> = {}; |
export function registerSettingsComponent(id, component, allowOverride = false) { | ||
export function registerSettingsComponent( | ||
id: Id, | ||
component: FunctionComponent<Record<string, any>>, |
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.
component: FunctionComponent<Record<string, any>>, | |
component: ComponentType, |
@@ -65,7 +72,7 @@ export function registerSettingsComponent(id, component, allowOverride = false) | |||
* | |||
* @param {*} id the ID of the component to retrieve | |||
*/ | |||
export function getSettingsComponent(id) { | |||
export function getSettingsComponent(id: Id): FunctionComponent<Record<string, any>> { |
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.
export function getSettingsComponent(id: Id): FunctionComponent<Record<string, any>> { | |
export function getSettingsComponent(id: Id): ComponentType { |
@@ -263,6 +276,7 @@ describe('Field', () => { | |||
/> | |||
); | |||
const select = findTestSubject(component, `advancedSetting-editField-${setting.name}`); | |||
// @ts-ignore |
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.
nit: Can we remove this and use casting, if needed?
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.
I'm happy to do this if you can show me which type is needed as I've been unable to find a good example.
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.
const labels = select.find('option').map((option: any) => option.text());
or
const labels = select.find('option').map((option: { text: () => string[] }) => option.text());
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.
I'm a little confused about this. Is this useful aside from removing // @ts-ignore
? Is a very incomplete type better than an ignore statement?
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.
No, my comment was just about removing // @ts-ignore
. It is just a nit.
@@ -280,13 +294,14 @@ describe('Field', () => { | |||
/> | |||
); | |||
const select = findTestSubject(component, `advancedSetting-editField-${setting.name}`); | |||
// @ts-ignore |
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.
nit: Can we remove this and use casting, if needed?
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.
Tested on Ubuntu \ Chrome.
I still see some minor comments that haven't been addressed, but overall LGTM
src/core/server/ui_settings/types.ts
Outdated
@@ -88,7 +88,16 @@ export interface DeprecationSettings { | |||
* UI element type to represent the settings. | |||
* @public | |||
* */ | |||
export type UiSettingsType = 'json' | 'markdown' | 'number' | 'select' | 'boolean' | 'string'; | |||
export type UiSettingsType = | |||
| 'undefined' // I don't know why malformed UiSettings objects exist |
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.
This actually makes it unneeded, right?
https://github.com/elastic/kibana/pull/55551/files
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.
Sorry, I should have been more clear - that PR will be deleted. It was to prove that the undefined
UiSettingsType is preexisting and not a result of another change in this PR
src/core/server/ui_settings/types.ts
Outdated
export interface StringValidation { | ||
export type StringValidation = StringValidationRegex | StringValidationRegexString; | ||
|
||
export interface StringValidationRegex { |
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.
// nit why not create StringVlalidaiton as a compound type?
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.
Are you asking why StringValidationRegex and StringValidationRegexString are individually exported? I do refer to them individually.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* advanced settings => typescript
Summary
Conversion of advanced settings management to typescript.
Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers
[ ] This includes a feature addition or change that requires a release note and was labeled appropriately