Skip to content

Commit

Permalink
Set button color (matterpoll#374)
Browse files Browse the repository at this point in the history
* set button color

* set button color when experimental ui is enabled

* swap button position

* fix: set button colors for backward compatibility

* test: fix tests

* feat: fix opacity value

* fix: avoid webapp error when theme is invalid, and add tests

* fix: lint error

Co-authored-by: Ben Schumacher <[email protected]>
  • Loading branch information
kaakaa and hanzei authored Oct 2, 2021
1 parent a72900b commit 864ac37
Show file tree
Hide file tree
Showing 8 changed files with 379 additions and 161 deletions.
35 changes: 20 additions & 15 deletions server/poll/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ func (p *Poll) ToPostActions(localizer *i18n.Localizer, pluginID, authorName str
for i, o := range p.AnswerOptions {
numberOfVotes += len(o.Voter)
actions = append(actions, &model.PostAction{
Id: fmt.Sprintf("vote%v", i),
Name: p.getAnswerOptionName(o),
Type: model.POST_ACTION_TYPE_BUTTON,
Id: fmt.Sprintf("vote%v", i),
Name: p.getAnswerOptionName(o),
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/vote/%v", pluginID, p.ID, i),
},
Expand All @@ -61,7 +62,8 @@ func (p *Poll) ToPostActions(localizer *i18n.Localizer, pluginID, authorName str
ID: "poll.button.resetVotes",
Other: "Reset Votes",
}}),
Type: model.POST_ACTION_TYPE_BUTTON,
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/votes/reset", pluginID, p.ID),
},
Expand All @@ -75,29 +77,32 @@ func (p *Poll) ToPostActions(localizer *i18n.Localizer, pluginID, authorName str
ID: "poll.button.addOption",
Other: "Add Option",
}}),
Type: model.POST_ACTION_TYPE_BUTTON,
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/option/add/request", pluginID, p.ID),
},
}, &model.PostAction{
Id: "deletePoll",
Id: "endPoll",
Name: localizer.MustLocalize(&i18n.LocalizeConfig{DefaultMessage: &i18n.Message{
ID: "poll.button.deletePoll",
Other: "Delete Poll",
ID: "poll.button.endPoll",
Other: "End Poll",
}}),
Type: MatterpollAdminButtonType,
Type: MatterpollAdminButtonType,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/delete", pluginID, p.ID),
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/end", pluginID, p.ID),
},
}, &model.PostAction{
Id: "endPoll",
Id: "deletePoll",
Name: localizer.MustLocalize(&i18n.LocalizeConfig{DefaultMessage: &i18n.Message{
ID: "poll.button.endPoll",
Other: "End Poll",
ID: "poll.button.deletePoll",
Other: "Delete Poll",
}}),
Type: MatterpollAdminButtonType,
Type: MatterpollAdminButtonType,
Style: "danger",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/end", pluginID, p.ID),
URL: fmt.Sprintf("/plugins/%s/api/v1/polls/%s/delete", pluginID, p.ID),
},
},
)
Expand Down
187 changes: 106 additions & 81 deletions server/poll/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,40 +115,46 @@ func TestPollToPostActions(t *testing.T) {
Title: "Question",
Text: "---\n**Total votes**: 0",
Actions: []*model.PostAction{{
Id: "vote0",
Name: "Yes",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote0",
Name: "Yes",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/0", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote1",
Name: "No",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote1",
Name: "No",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/1", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/option/add/request", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Style: "danger",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
}},
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
},
},
},
}},
},
Expand All @@ -159,46 +165,52 @@ func TestPollToPostActions(t *testing.T) {
Title: "Question",
Text: "---\n**Poll Settings**: progress\n**Total votes**: 0",
Actions: []*model.PostAction{{
Id: "vote0",
Name: "Answer 1 (0)",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote0",
Name: "Answer 1 (0)",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/0", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote1",
Name: "Answer 2 (0)",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote1",
Name: "Answer 2 (0)",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/1", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote2",
Name: "Answer 3 (0)",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote2",
Name: "Answer 3 (0)",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/2", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/option/add/request", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Style: "danger",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
},
},
},
Expand All @@ -211,46 +223,52 @@ func TestPollToPostActions(t *testing.T) {
Title: "Question",
Text: "---\n**Poll Settings**: anonymous, public-add-option\n**Total votes**: 0",
Actions: []*model.PostAction{{
Id: "vote0",
Name: "Answer 1",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote0",
Name: "Answer 1",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/0", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote1",
Name: "Answer 2",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote1",
Name: "Answer 2",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/1", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote2",
Name: "Answer 3",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote2",
Name: "Answer 3",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/2", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/option/add/request", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Style: "danger",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
},
},
},
Expand All @@ -263,53 +281,60 @@ func TestPollToPostActions(t *testing.T) {
Title: "Question",
Text: "---\n**Poll Settings**: votes=3\n**Total votes**: 0",
Actions: []*model.PostAction{{
Id: "vote0",
Name: "Answer 1",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote0",
Name: "Answer 1",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/0", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote1",
Name: "Answer 2",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote1",
Name: "Answer 2",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/1", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "vote2",
Name: "Answer 3",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "vote2",
Name: "Answer 3",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "default",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/vote/2", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "resetVote",
Name: "Reset Votes",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "resetVote",
Name: "Reset Votes",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/votes/reset", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Id: "addOption",
Name: "Add Option",
Type: model.POST_ACTION_TYPE_BUTTON,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/option/add/request", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Style: "primary",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
},
}, {
Id: "endPoll",
Name: "End Poll",
Type: poll.MatterpollAdminButtonType,
Id: "deletePoll",
Name: "Delete Poll",
Type: poll.MatterpollAdminButtonType,
Style: "danger",
Integration: &model.PostActionIntegration{
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/end", PluginID, currentAPIVersion, testutils.GetPollID()),
URL: fmt.Sprintf("/plugins/%s/api/%s/polls/%s/delete", PluginID, currentAPIVersion, testutils.GetPollID()),
},
},
},
Expand Down
Loading

0 comments on commit 864ac37

Please sign in to comment.