Skip to content
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

fix(installWizard): Fix client default values not set #13726

Merged
merged 5 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/sentry/static/sentry/app/options.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ export function getOption(option) {
return definitionsMap[option];
}

export function getOptionDefault(option) {
const meta = getOption(option);
return meta.defaultValue ? meta.defaultValue() : undefined;
}

function optionsForSection(section) {
return definitions.filter(option => option.key.split('.')[0] === section.key);
}
Expand All @@ -183,7 +188,7 @@ export function getOptionField(option, field) {
{...meta}
name={option}
key={option}
defaultValue={meta.defaultValue ? meta.defaultValue() : undefined}
defaultValue={getOptionDefault(option)}
required={meta.required && !meta.allowEmpty}
disabledReason={meta.disabledReason && disabledReasons[meta.disabledReason]}
/>
Expand Down
21 changes: 12 additions & 9 deletions src/sentry/static/sentry/app/views/installWizard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AsyncView from 'app/views/asyncView';
import {t} from 'app/locale';
import ConfigStore from 'app/stores/configStore';
import {ApiForm} from 'app/components/forms';
import {getOptionField, getForm} from 'app/options';
import {getOptionDefault, getOptionField, getForm} from 'app/options';

export default class InstallWizard extends AsyncView {
static propTypes = {
Expand Down Expand Up @@ -64,18 +64,21 @@ export default class InstallWizard extends AsyncView {
if (option.field.disabled) {
return;
}
// XXX(dcramer): we need the user to explicitly choose beacon.anonymous
// vs using an implied default so effectively this is binding
// all values to their server-defaults (as client-side defaults dont really work)

// TODO(dcramer): we need to rethink this logic as doing multiple "is this value actually set"
// is problematic
// all values to their server-defaults (as client-side defaults dont really work)
const displayValue = option.value || getOptionDefault(optionName);
if (
option.value !== undefined &&
option.value !== '' &&
option.value !== null &&
(option.field.isSet || optionName != 'beacon.anonymous')
// XXX(dcramer): we need the user to explicitly choose beacon.anonymous
// vs using an implied default so effectively this is binding
optionName != 'beacon.anonymous' &&
// XXX(byk): if we don't have a set value but have a default value filled
// instead, from the client, set it on the data so it is sent to the server
!option.field.isSet &&
displayValue !== undefined
) {
data[optionName] = option.value;
data[optionName] = displayValue;
}
});
return data;
Expand Down
6 changes: 3 additions & 3 deletions tests/js/spec/views/installWizard.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ describe('InstallWizard', function() {

expect(
wrapper.find('input[name="beacon.anonymous"][value="false"]').prop('checked')
).toBe(true);
).toBe(false);
BYK marked this conversation as resolved.
Show resolved Hide resolved

expect(
wrapper.find('input[name="beacon.anonymous"][value="true"]').prop('checked')
).toBe(false);
});

it('has "Please keep my usage anonymous" when beacon.anonymous is true', function() {
it('has "Please keep my usage anonymous" when beacon.anonymous is false', function() {
MockApiClient.addMockResponse({
url: '/internal/options/?query=is:required',
body: TestStubs.InstallWizard({
Expand All @@ -112,6 +112,6 @@ describe('InstallWizard', function() {

expect(
wrapper.find('input[name="beacon.anonymous"][value="true"]').prop('checked')
).toBe(true);
).toBe(false);
});
});