index.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import {css} from '@emotion/react';
  2. import styled from '@emotion/styled';
  3. import sentryPattern from 'sentry-images/pattern/sentry-pattern.png';
  4. import {Alert} from 'sentry/components/alert';
  5. import ApiForm from 'sentry/components/forms/apiForm';
  6. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  7. import {t} from 'sentry/locale';
  8. import ConfigStore from 'sentry/stores/configStore';
  9. import {space} from 'sentry/styles/space';
  10. import DeprecatedAsyncView from 'sentry/views/deprecatedAsyncView';
  11. import {getForm, getOptionDefault, getOptionField} from '../options';
  12. export type InstallWizardProps = DeprecatedAsyncView['props'] & {
  13. onConfigured: () => void;
  14. };
  15. type State = DeprecatedAsyncView['state'];
  16. export default class InstallWizard extends DeprecatedAsyncView<
  17. InstallWizardProps,
  18. State
  19. > {
  20. getEndpoints(): ReturnType<DeprecatedAsyncView['getEndpoints']> {
  21. return [['data', '/internal/options/?query=is:required']];
  22. }
  23. renderFormFields() {
  24. const options = this.state.data;
  25. let missingOptions = new Set(
  26. Object.keys(options).filter(option => !options[option].field.isSet)
  27. );
  28. // This is to handle the initial installation case.
  29. // Even if all options are filled out, we want to prompt to confirm
  30. // them. This is a bit of a hack because we're assuming that
  31. // the backend only spit back all filled out options for
  32. // this case.
  33. if (missingOptions.size === 0) {
  34. missingOptions = new Set(Object.keys(options));
  35. }
  36. // A mapping of option name to Field object
  37. const fields = {};
  38. for (const key of missingOptions) {
  39. const option = options[key];
  40. if (option.field.disabled) {
  41. continue;
  42. }
  43. fields[key] = getOptionField(key, option.field);
  44. }
  45. return getForm(fields);
  46. }
  47. getInitialData() {
  48. const options = this.state.data;
  49. const data = {};
  50. Object.keys(options).forEach(optionName => {
  51. const option = options[optionName];
  52. if (option.field.disabled) {
  53. return;
  54. }
  55. // TODO(dcramer): we need to rethink this logic as doing multiple "is this value actually set"
  56. // is problematic
  57. // all values to their server-defaults (as client-side defaults don't really work)
  58. const displayValue = option.value || getOptionDefault(optionName);
  59. if (
  60. // XXX(dcramer): we need the user to explicitly choose beacon.anonymous
  61. // vs using an implied default so effectively this is binding
  62. optionName !== 'beacon.anonymous' &&
  63. // XXX(byk): if we don't have a set value but have a default value filled
  64. // instead, from the client, set it on the data so it is sent to the server
  65. !option.field.isSet &&
  66. displayValue !== undefined
  67. ) {
  68. data[optionName] = displayValue;
  69. }
  70. });
  71. return data;
  72. }
  73. getTitle() {
  74. return t('Setup Sentry');
  75. }
  76. render() {
  77. const version = ConfigStore.get('version');
  78. return (
  79. <SentryDocumentTitle noSuffix title={this.getTitle()}>
  80. <Wrapper>
  81. <Pattern />
  82. <SetupWizard>
  83. <Heading>
  84. <span>{t('Welcome to Sentry')}</span>
  85. <Version>{version.current}</Version>
  86. </Heading>
  87. {this.state.loading
  88. ? this.renderLoading()
  89. : this.state.error
  90. ? this.renderError()
  91. : this.renderBody()}
  92. </SetupWizard>
  93. </Wrapper>
  94. </SentryDocumentTitle>
  95. );
  96. }
  97. renderError() {
  98. return (
  99. <Alert type="error" showIcon>
  100. {t(
  101. 'We were unable to load the required configuration from the Sentry server. Please take a look at the service logs.'
  102. )}
  103. </Alert>
  104. );
  105. }
  106. renderBody() {
  107. return (
  108. <ApiForm
  109. apiMethod="PUT"
  110. apiEndpoint={this.getEndpoints()[0][1]}
  111. submitLabel={t('Continue')}
  112. initialData={this.getInitialData()}
  113. onSubmitSuccess={this.props.onConfigured}
  114. >
  115. <p>{t('Complete setup by filling out the required configuration.')}</p>
  116. {this.renderFormFields()}
  117. </ApiForm>
  118. );
  119. }
  120. }
  121. const Wrapper = styled('div')`
  122. display: flex;
  123. justify-content: center;
  124. `;
  125. const fixedStyle = css`
  126. position: fixed;
  127. top: 0;
  128. right: 0;
  129. bottom: 0;
  130. left: 0;
  131. `;
  132. const Pattern = styled('div')`
  133. z-index: -1;
  134. &::before {
  135. ${fixedStyle}
  136. content: '';
  137. background-image: linear-gradient(
  138. to right,
  139. ${p => p.theme.purple200} 0%,
  140. ${p => p.theme.purple300} 100%
  141. );
  142. background-repeat: repeat-y;
  143. }
  144. &::after {
  145. ${fixedStyle}
  146. content: '';
  147. background: url(${sentryPattern});
  148. background-size: 400px;
  149. opacity: 0.8;
  150. }
  151. `;
  152. const Heading = styled('h1')`
  153. display: grid;
  154. gap: ${space(1)};
  155. justify-content: space-between;
  156. grid-auto-flow: column;
  157. line-height: 36px;
  158. `;
  159. const Version = styled('small')`
  160. font-size: ${p => p.theme.fontSizeExtraLarge};
  161. line-height: inherit;
  162. `;
  163. const SetupWizard = styled('div')`
  164. background: ${p => p.theme.background};
  165. border-radius: ${p => p.theme.borderRadius};
  166. box-shadow: ${p => p.theme.dropShadowHeavy};
  167. margin-top: 40px;
  168. padding: 40px 40px 20px;
  169. width: 600px;
  170. z-index: ${p => p.theme.zIndex.initial};
  171. `;