index.tsx 5.1 KB

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