Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
🐛 Fixed inconsistent publish/send messaging in publish menu
Browse files Browse the repository at this point in the history
no issue

- fixes the "publish/send" dropdown showing when mail is not allowed by tying it to the `canSendEmail` property rather than always showing when editing a draft post
  - was previously showing when mailgun is not configured and when default email recipients is set to "disabled", in both cases the recipient selection was never available so the dropdown was confusing and lead to invalid states
  - removed the unnecessary property`showEmailOnlyInput` - replaced with `@canSendEmail`
  - removed the unnecessary property `nextActionName` - it always resulted in "publish" because it was only being shown for pages and pages can't be sent by email
- removed the logic for setting the initial selected option in `<GhDistributionActionSelect>` because it meant the select was not directly tied to the real distribution action value leading to mixed states across components. Switched to using the passed in `@distributionAction` value directly.
- fixed the publish button incorrectly showing "Publish & send" when no send would be occurring for a post
  - if "Publish & Send" is selected, the button will now show "Publish" when no recipients are selected
- fixed the publish button incorrectly showing "Publish & send" for pages
- fixed the now/schedule radio texts not changing when publish type was set to "Send" - the conditionals were incorrectly looking at `this.args.post.emailOnly` which is incorrect syntax would only update _after_ saving, switched to the menu's internal `@emailOnly` argument instead
  • Loading branch information
kevinansfield committed Oct 21, 2021
1 parent a9a2692 commit fdfed84
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
39 changes: 12 additions & 27 deletions app/components/gh-distribution-action-select.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
import Component from '@glimmer/component';
import {action} from '@ember/object';
import {tracked} from '@glimmer/tracking';

export default class GhDistributionActionSelect extends Component {
@tracked
distributionValue;
availablePublishActions = [{
value: 'publish_send',
name: 'publish & send'
}, {
value: 'publish',
name: 'publish'
}, {
value: 'send',
name: 'send'
}];

constructor(...args) {
super(...args);

let distributionValue = this.args.emailOnly
? 'send'
: (this.args.emailRecipientFilter !== 'none')
? 'publish_send'
: 'publish';

this.distributionValue = this.availablePublishActions.findBy('value', distributionValue);
}

get availablePublishActions() {
return [{
value: 'publish_send',
name: 'publish & send'
}, {
value: 'publish',
name: 'publish'
}, {
value: 'send',
name: 'send'
}];
get distributionValue() {
return this.availablePublishActions.findBy('value', this.args.distributionAction);
}

@action
setDistributionAction(newAction) {
this.distributionValue = newAction;
this.args.setDistributionAction(newAction.value);
}
}
13 changes: 6 additions & 7 deletions app/components/gh-publishmenu-draft.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<div {{did-insert (fn this.setSaveType "publish")}} ...attributes>
<header class="gh-publishmenu-heading">Ready to
{{#if this.showEmailOnlyInput}}
{{#if @canSendEmail}}
<GhDistributionActionSelect
@emailOnly={{@emailOnly}}
@emailRecipientFilter={{@recipientsFilter}}
@distributionAction={{@distributionAction}}
@setDistributionAction={{@setDistributionAction}}
/>
{{else}}
{{this.nextActionName}}
publish
{{/if}}
this {{@post.displayName}}?
</header>
Expand All @@ -16,8 +15,8 @@
<div class="gh-publishmenu-radio {{if (eq @saveType "publish") "active"}}" {{on "click" (fn this.setSaveType "publish")}}>
<div class="gh-publishmenu-radio-button" data-test-publishmenu-published-option></div>
<div class="gh-publishmenu-radio-content">
<div class="gh-publishmenu-radio-label">{{#if this.args.post.emailOnly}}Send email now{{else}}Set it live now{{/if}}</div>
<div class="gh-publishmenu-radio-desc">{{#if this.args.post.emailOnly}}Deliver this immediately{{else}}Publish this {{@post.displayName}} immediately{{/if}}</div>
<div class="gh-publishmenu-radio-label">{{#if @emailOnly}}Send email now{{else}}Set it live now{{/if}}</div>
<div class="gh-publishmenu-radio-desc">{{#if @emailOnly}}Deliver this immediately{{else}}Publish this {{@post.displayName}} immediately{{/if}}</div>
</div>
</div>
<div class="gh-publishmenu-radio {{if (eq @saveType "schedule") "active"}}" {{on "click" (fn this.setSaveType "schedule")}}>
Expand All @@ -36,7 +35,7 @@
@minDate={{this._minDate}}
@isActive={{eq @saveType "schedule"}}
/>
<div class="gh-publishmenu-radio-desc">{{#if this.args.post.emailOnly}}Send email at a specific time{{else}}Set automatic future publish date{{/if}}</div>
<div class="gh-publishmenu-radio-desc">{{#if @emailOnly}}Send email at a specific time{{else}}Set automatic future publish date{{/if}}</div>
</div>
</div>
</div>
Expand Down
10 changes: 1 addition & 9 deletions app/components/gh-publishmenu-draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,8 @@ export default class GhPublishMenuDraftComponent extends Component {
return this.session.user.isAdmin && (this.totalMemberCount === 0 || this.countTotalMembersTask.isRunning);
}

get nextActionName() {
return this.args.emailOnly ? 'send' : 'publish';
}

get showEmailSection() {
return this.args.canSendEmail && this.args.recipientsFilter !== 'none';
}

get showEmailOnlyInput() {
return this.args.post.isPost;
return this.args.canSendEmail && this.args.distributionAction !== 'publish';
}

constructor() {
Expand Down
1 change: 1 addition & 0 deletions app/components/gh-publishmenu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@setSendEmailWhenPublished={{action "setSendEmailWhenPublished"}}
@isSendingEmailLimited={{this.isSendingEmailLimited}}
@sendingEmailLimitError={{this.sendingEmailLimitError}}
@distributionAction={{this.distributionAction}}
@setDistributionAction={{action "setDistributionAction"}}
data-test-publishmenu-draft="true" />
{{/if}}
Expand Down
14 changes: 11 additions & 3 deletions app/components/gh-publishmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,24 @@ export default Component.extend({
return runningText || 'Publishing';
}),

buttonText: computed('postState', 'saveType', 'distributionAction', function () {
buttonText: computed('postState', 'saveType', 'distributionAction', 'sendEmailWhenPublished', function () {
let saveType = this.saveType;
let postState = this.postState;
let distributionAction = this.get('distributionAction');
let distributionAction = this.distributionAction;
let buttonText;

if (postState === 'draft') {
switch (distributionAction) {
case 'publish_send':
buttonText = (saveType === 'publish') ? 'Publish & send' : 'Schedule';
if (saveType === 'publish') {
buttonText = 'Publish';

if (this.canSendEmail && this.sendEmailWhenPublished && this.sendEmailWhenPublished !== 'none') {
buttonText = `${buttonText} & send`;
}
} else {
buttonText = 'Schedule';
}
break;
case 'publish':
buttonText = (saveType === 'publish') ? 'Publish' : 'Schedule';
Expand Down

0 comments on commit fdfed84

Please sign in to comment.