Browse Source

ref: Refactor InstallWizard fixture to be typescript (#55944)

Ryan Albrecht 1 year ago
parent
commit
915b6effa4

+ 35 - 22
fixtures/js-stubs/installWizard.js → fixtures/js-stubs/installWizard.ts

@@ -1,113 +1,126 @@
-export function InstallWizard(params = {}) {
+import type {InstallWizardOptions} from 'sentry/views/admin/installWizard/index';
+
+export function InstallWizard(params = {}): InstallWizardOptions {
   return {
     'mail.use-tls': {
       field: {
-        disabledReason: null,
-        default: false,
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: true,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'mail.use-ssl': {
       field: {
-        disabledReason: null,
-        default: false,
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: true,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'mail.username': {
       field: {
-        disabledReason: null,
-        default: '',
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: true,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'mail.port': {
       field: {
-        disabledReason: null,
-        default: 25,
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: false,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'system.admin-email': {
       field: {
-        disabledReason: null,
-        default: '',
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: false,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'mail.password': {
       field: {
-        disabledReason: null,
-        default: '',
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: true,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'mail.from': {
       field: {
-        disabledReason: null,
-        default: 'root@localhost',
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: false,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'system.url-prefix': {
       field: {
         disabledReason: 'diskPriority',
-        default: '',
         required: true,
         disabled: true,
         allowEmpty: false,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'auth.allow-registration': {
       field: {
-        disabledReason: null,
-        default: false,
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: true,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'beacon.anonymous': {
       field: {
-        disabledReason: null,
-        default: false,
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: true,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     'mail.host': {
       field: {
-        disabledReason: null,
-        default: 'localhost',
+        disabledReason: undefined,
         required: true,
         disabled: false,
         allowEmpty: false,
         isSet: true,
+        key: '',
+        label: '',
       },
     },
     ...params,

+ 14 - 4
static/app/views/admin/installWizard/index.tsx

@@ -11,13 +11,23 @@ import ConfigStore from 'sentry/stores/configStore';
 import {space} from 'sentry/styles/space';
 import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
 
-import {getForm, getOptionDefault, getOptionField} from '../options';
+import {Field, getForm, getOptionDefault, getOptionField} from '../options';
 
 export type InstallWizardProps = DeprecatedAsyncView['props'] & {
   onConfigured: () => void;
 };
 
-type State = DeprecatedAsyncView['state'];
+export type InstallWizardOptions = Record<
+  string,
+  {
+    field: Field;
+    value?: unknown;
+  }
+>;
+
+type State = DeprecatedAsyncView['state'] & {
+  data: null | InstallWizardOptions;
+};
 
 export default class InstallWizard extends DeprecatedAsyncView<
   InstallWizardProps,
@@ -28,7 +38,7 @@ export default class InstallWizard extends DeprecatedAsyncView<
   }
 
   renderFormFields() {
-    const options = this.state.data;
+    const options = this.state.data!;
 
     let missingOptions = new Set(
       Object.keys(options).filter(option => !options[option].field.isSet)
@@ -57,7 +67,7 @@ export default class InstallWizard extends DeprecatedAsyncView<
   }
 
   getInitialData() {
-    const options = this.state.data;
+    const options = this.state.data!;
     const data = {};
     Object.keys(options).forEach(optionName => {
       const option = options[optionName];

+ 2 - 1
static/app/views/admin/options.tsx

@@ -16,7 +16,7 @@ type Section = {
 
 // TODO(epurkhiser): This should really use the types from the form system, but
 // they're still pretty bad so that's difficult I guess?
-type Field = {
+export type Field = {
   key: string;
   label: React.ReactNode;
   allowEmpty?: boolean;
@@ -26,6 +26,7 @@ type Field = {
   disabled?: boolean;
   disabledReason?: string;
   help?: React.ReactNode;
+  isSet?: boolean;
   max?: number;
   min?: number;
   placeholder?: string;