FIX: ensures explorer is using default values when provided (#240)

This commit is contained in:
Joffrey JAFFEUX 2023-04-17 16:06:27 +02:00 committed by GitHub
parent 98e96fccc2
commit 97d60de92a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 6 deletions

View File

@ -7,12 +7,14 @@
@nameProperty="name"
@content={{this.boolTypes}}
@onChange={{this.updateNullableBoolValue}}
name={{@info.identifier}}
/>
{{else}}
<Input
@type="checkbox"
@checked={{this.boolvalue}}
{{on "change" this.updateBoolValue}}
name={{@info.identifier}}
/>
{{/if}}
<span class="param-name">{{@info.identifier}}</span>
@ -22,6 +24,7 @@
@type="number"
@value={{this.value}}
{{on "change" this.updateValue}}
name={{@info.identifier}}
/>
<span class="param-name">{{@info.identifier}}</span>
@ -30,6 +33,7 @@
@value={{this.value}}
@type="text"
@onChange={{this.updateValue}}
name={{@info.identifier}}
/>
<span class="param-name">{{@info.identifier}}</span>
@ -38,6 +42,7 @@
@value={{this.value}}
@options={{(hash maximum=1)}}
@onChange={{this.updateValue}}
name={{@info.identifier}}
/>
<span class="param-name">{{@info.identifier}}</span>
@ -45,11 +50,16 @@
<EmailGroupUserChooser
@value={{this.value}}
@onChange={{this.updateValue}}
name={{@info.identifier}}
/>
<span class="param-name">{{@info.identifier}}</span>
{{else}}
<TextField @value={{this.value}} @onChange={{this.updateValue}} />
<TextField
@value={{this.value}}
@onChange={{this.updateValue}}
name={{@info.identifier}}
/>
<span class="param-name">{{@info.identifier}}</span>
{{/if}}
</div>

View File

@ -69,13 +69,13 @@ export default class ParamInput extends Component {
}
} else {
// if no parsed params then get and set default values
const params = this.args.params;
const defaultValue = this.args.info.default;
this.value =
this.args.info.type === "category_id"
? this.dasherizeCategoryId(params[identifier])
: params[identifier];
this.boolValue = params[identifier] !== "false";
this.nullableBoolValue = params[identifier];
? this.dasherizeCategoryId(defaultValue)
: defaultValue;
this.boolValue = defaultValue !== "false";
this.nullableBoolValue = defaultValue;
}
}

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
RSpec.describe "Explorer", type: :system, js: true do
fab!(:current_user) { Fabricate(:admin) }
fab!(:group) { Fabricate(:group, name: "group") }
fab!(:group_user) { Fabricate(:group_user, user: current_user, group: group) }
before { SiteSetting.data_explorer_enabled = true }
context "with a query using a default param" do
fab!(:query_1) do
Fabricate(
:query,
name: "My default param query",
description: "Test default param query",
sql: "-- [params]\n-- string :limit = 42\n\nSELECT * FROM users LIMIT :limit",
user: current_user,
)
end
fab!(:query_group_1) { Fabricate(:query_group, query: query_1, group: group) }
it "pre-fills the field with the default param" do
sign_in(current_user)
visit("/g/group/reports/#{query_1.id}")
expect(page).to have_field("limit", with: 42)
end
end
end