import isEqual from 'lodash/isEqual'; import Form from 'sentry/components/deprecatedforms/form'; import FormState from 'sentry/components/forms/state'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import DefaultSettings from 'sentry/plugins/components/settings'; type Props = DefaultSettings['props']; type State = DefaultSettings['state'] & { // NB: "On-premises" here refers to on-premises SessionStack, not Sentry. // That said, we only support connecting to an on-premises SessionStack from // a self-hosted Sentry: https://docs.sessionstack.com/docs/sentry. showOnPremisesConfiguration?: boolean; }; class Settings extends DefaultSettings { REQUIRED_FIELDS = ['account_email', 'api_token', 'website_id']; ON_PREMISES_FIELDS = ['api_url', 'player_url']; renderFields(fields: State['fieldList']) { return fields?.map(f => this.renderField({ config: f, formData: this.state.formData, formErrors: this.state.errors, onChange: this.changeField.bind(this, f.name), }) ); } filterFields(fields: State['fieldList'], fieldNames: string[]) { return fields?.filter(field => fieldNames.includes(field.name)) ?? []; } toggleOnPremisesConfiguration = () => { this.setState({ showOnPremisesConfiguration: !this.state.showOnPremisesConfiguration, }); }; render() { if (this.state.state === FormState.LOADING) { return ; } if (this.state.state === FormState.ERROR && !this.state.fieldList) { return (
An unknown error occurred. Need help with this?{' '} Contact support
); } const isSaving = this.state.state === FormState.SAVING; const hasChanges = !isEqual(this.state.initialData, this.state.formData); const requiredFields = this.filterFields(this.state.fieldList, this.REQUIRED_FIELDS); const onPremisesFields = this.filterFields( this.state.fieldList, this.ON_PREMISES_FIELDS ); return (
{this.state.errors.__all__ && (
  • {this.state.errors.__all__}
)} {this.renderFields(requiredFields)} {onPremisesFields.length > 0 ? (
) : null} {this.state.showOnPremisesConfiguration ? this.renderFields(onPremisesFields) : null}
); } } export default Settings;