From ff6811ceb801aaedf3734d1e40c94413b7c42235 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Fri, 12 Jun 2020 14:52:32 +0300 Subject: [PATCH] Allow multiple groups which can vote when creating a poll (#10015) * FEATURE: Allow multiple groups which can vote when creating a poll * DEV: Fix select-kit deprecations * DEV: Fix lint --- .../admin/templates/user-index.hbs | 2 +- ...min-group-selector.js => group-chooser.js} | 4 +- .../controllers/poll-ui-builder.js.es6 | 6 ++- .../templates/modal/poll-ui-builder.hbs | 40 ++++++++++--------- .../stylesheets/common/poll-ui-builder.scss | 3 +- .../acceptance/admin-user-index-test.js | 10 ++--- 6 files changed, 36 insertions(+), 29 deletions(-) rename app/assets/javascripts/select-kit/addon/components/{admin-group-selector.js => group-chooser.js} (64%) diff --git a/app/assets/javascripts/admin/templates/user-index.hbs b/app/assets/javascripts/admin/templates/user-index.hbs index df9a6e196ff..62e500f8057 100644 --- a/app/assets/javascripts/admin/templates/user-index.hbs +++ b/app/assets/javascripts/admin/templates/user-index.hbs @@ -514,7 +514,7 @@
{{i18n "admin.groups.custom"}}
- {{admin-group-selector + {{group-chooser content=availableGroups value=customGroupIdsBuffer labelProperty="name" diff --git a/app/assets/javascripts/select-kit/addon/components/admin-group-selector.js b/app/assets/javascripts/select-kit/addon/components/group-chooser.js similarity index 64% rename from app/assets/javascripts/select-kit/addon/components/admin-group-selector.js rename to app/assets/javascripts/select-kit/addon/components/group-chooser.js index 1b02a45d280..740642c6746 100644 --- a/app/assets/javascripts/select-kit/addon/components/admin-group-selector.js +++ b/app/assets/javascripts/select-kit/addon/components/group-chooser.js @@ -1,8 +1,8 @@ import MultiSelectComponent from "select-kit/components/multi-select"; export default MultiSelectComponent.extend({ - pluginApiIdentifiers: ["admin-group-selector"], - classNames: ["admin-group-selector"], + pluginApiIdentifiers: ["group-chooser"], + classNames: ["group-chooser"], selectKitOptions: { allowAny: false } diff --git a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 index a653b8113bf..8dc72084c71 100644 --- a/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 +++ b/plugins/poll/assets/javascripts/controllers/poll-ui-builder.js.es6 @@ -97,7 +97,7 @@ export default Controller.extend({ .map(g => { // prevents group "everyone" to be listed if (g.id !== 0) { - return { name: g.name, value: g.name }; + return { name: g.name }; } }) .filter(Boolean); @@ -251,7 +251,9 @@ export default Controller.extend({ if (publicPoll) pollHeader += ` public=true`; if (chartType && pollType !== "number") pollHeader += ` chartType=${chartType}`; - if (pollGroups) pollHeader += ` groups=${pollGroups}`; + if (pollGroups && pollGroups.length > 0) { + pollHeader += ` groups=${pollGroups}`; + } if (autoClose) { let closeDate = moment( date + " " + time, diff --git a/plugins/poll/assets/javascripts/discourse/templates/modal/poll-ui-builder.hbs b/plugins/poll/assets/javascripts/discourse/templates/modal/poll-ui-builder.hbs index 28e9f7c8e4b..03e08acee7f 100644 --- a/plugins/poll/assets/javascripts/discourse/templates/modal/poll-ui-builder.hbs +++ b/plugins/poll/assets/javascripts/discourse/templates/modal/poll-ui-builder.hbs @@ -2,7 +2,7 @@
- + {{combo-box content=pollTypes value=pollType @@ -13,39 +13,43 @@
- + {{combo-box content=pollResults value=pollResult class="poll-result" valueProperty="value" + onChange=(action (mut pollResult)) }}
- - {{combo-box content=siteGroups - value=pollGroups - options=(hash clearable=true) - valueAttribute="value"}} + + {{group-chooser + content=siteGroups + value=pollGroups + onChange=(action (mut pollGroups)) + labelProperty="name" + valueProperty="name"}}
{{#unless isNumber}}
- + {{combo-box class="poll-chart-type" content=pollChartTypes value=chartType - valueAttribute="value" + valueProperty="value" + onChange=(action (mut chartType)) }}
{{/unless}} {{#if showMinMax}}
- - {{input type='number' + + {{input type="number" value=pollMin valueProperty="value" class="poll-options-min"}} @@ -53,8 +57,8 @@ {{input-tip validation=minMaxValueValidation}}
- - {{input type='number' + + {{input type="number" value=pollMax valueProperty="value" class="poll-options-max"}} @@ -62,8 +66,8 @@ {{#if isNumber}}
- - {{input type='number' + + {{input type="number" value=pollStep valueProperty="value" min="1" @@ -75,7 +79,7 @@ {{#unless isNumber}}
- + {{textarea value=pollOptions autocomplete="discourse"}}
{{input-tip validation=minNumOfOptionsValidation}} @@ -84,7 +88,7 @@ {{#unless isPie}}
@@ -116,5 +120,5 @@ {{/d-modal-body}} diff --git a/plugins/poll/assets/stylesheets/common/poll-ui-builder.scss b/plugins/poll/assets/stylesheets/common/poll-ui-builder.scss index df3c17eacb6..7f38887ed47 100644 --- a/plugins/poll/assets/stylesheets/common/poll-ui-builder.scss +++ b/plugins/poll/assets/stylesheets/common/poll-ui-builder.scss @@ -8,7 +8,8 @@ $poll-margin: 10px; flex-shrink: 0; width: 280px; } - .combo-box { + .combo-box, + .multi-select { min-width: 180px; width: 180px; } diff --git a/test/javascripts/acceptance/admin-user-index-test.js b/test/javascripts/acceptance/admin-user-index-test.js index 4c57cbbf979..5e20f3d2acd 100644 --- a/test/javascripts/acceptance/admin-user-index-test.js +++ b/test/javascripts/acceptance/admin-user-index-test.js @@ -86,10 +86,10 @@ QUnit.test("will clear unsaved groups when switching user", async assert => { "the name should be correct" ); - const groupSelector = selectKit(".admin-group-selector"); - await groupSelector.expand(); - await groupSelector.selectRowByValue(42); - assert.equal(groupSelector.header().value(), 42, "group should be set"); + const groupChooser = selectKit(".group-chooser"); + await groupChooser.expand(); + await groupChooser.selectRowByValue(42); + assert.equal(groupChooser.header().value(), 42, "group should be set"); await visit("/admin/users/1/eviltrout"); @@ -102,7 +102,7 @@ QUnit.test("will clear unsaved groups when switching user", async assert => { ); assert.equal( - find('.admin-group-selector span[title="Macdonald"]').length, + find('.group-chooser span[title="Macdonald"]').length, 0, "group should not be set" );