Skip to content

Commit

Permalink
Keep 'is-selected' class on program flow header when the program flow…
Browse files Browse the repository at this point in the history
… is edited via the sidebar
  • Loading branch information
nmajor25 committed Oct 24, 2023
1 parent 90492d8 commit d506949
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
14 changes: 12 additions & 2 deletions src/js/apps/programs/program/flow/flow_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SubRouterApp from 'js/base/subrouterapp';

import ActionApp from 'js/apps/programs/program/action/action_app';

import { LayoutView, ContextTrailView, HeaderView, ListView } from 'js/views/programs/program/flow/flow_views';
import { LayoutView, ContextTrailView, HeaderView, AddActionView, ListView } from 'js/views/programs/program/flow/flow_views';
import { SidebarView } from 'js/views/programs/program/sidebar/sidebar-views';

export default SubRouterApp.extend({
Expand Down Expand Up @@ -43,6 +43,7 @@ export default SubRouterApp.extend({
}));

this.showHeader();
this.showAddAction();
this.showActionList();
this.showProgramSidebar();
},
Expand All @@ -63,12 +64,21 @@ export default SubRouterApp.extend({

this.listenTo(headerView, {
'edit': this.onEditFlow,
});

this.showChildView('header', headerView);
},

showAddAction() {
const addActionView = new AddActionView();

this.listenTo(addActionView, {
'click:addAction': () => {
Radio.trigger('event-router', 'programFlow:action:new', this.flow.id);
},
});

this.showChildView('header', headerView);
this.showChildView('addAction', addActionView);
},

showActionList() {
Expand Down
3 changes: 1 addition & 2 deletions src/js/i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -678,10 +678,9 @@ careOptsFrontend:
actionItemTemplate:
newProgramFlowAction: New Flow Action
flowViews:
addActionBtn: Action
contextBackBtn: Back to List
emptyView: No Actions
headerTemplate:
action: Action
programViews:
contextBackBtn: Back to List
sidebar:
Expand Down
23 changes: 17 additions & 6 deletions src/js/views/programs/program/flow/flow_views.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,21 @@ const ContextTrailView = View.extend({
});

const HeaderView = View.extend({
className: 'program-flow__header',
modelEvents: {
'editing': 'onEditing',
'change': 'render',
},
onEditing(isEditing) {
this.ui.flow.toggleClass('is-selected', isEditing);
this.$el.toggleClass('is-selected', isEditing);
},
template: HeaderTemplate,
regions: {
behavior: '[data-behavior-region]',
owner: '[data-owner-region]',
},
triggers: {
'click @ui.flow': 'edit',
'click .js-add-action': 'click:addAction',
},
ui: {
flow: '.js-flow',
'click': 'edit',
},
onRender() {
this.showBehavior();
Expand Down Expand Up @@ -97,6 +94,17 @@ const HeaderView = View.extend({
},
});

const AddActionView = View.extend({
template: hbs`
<div class="program-flow__actions">
<button class="button-primary js-add-action">{{far "circle-plus"}}<span>{{ @intl.programs.program.flow.flowViews.addActionBtn }}</span></button>
</div>
`,
triggers: {
'click .js-add-action': 'click:addAction',
},
});

const EmptyView = View.extend({
tagName: 'tr',
template: hbs`
Expand Down Expand Up @@ -223,6 +231,7 @@ const LayoutView = View.extend({
<div class="program-flow__layout">
<div data-context-trail-region></div>
<div data-header-region></div>
<div data-add-action-region></div>
<div data-action-list-region></div>
</div>
<div class="program-flow__sidebar" data-sidebar-region></div>
Expand All @@ -233,6 +242,7 @@ const LayoutView = View.extend({
replaceElement: true,
},
header: '[data-header-region]',
addAction: '[data-add-action-region]',
sidebar: '[data-sidebar-region]',
actionList: {
el: '[data-action-list-region]',
Expand All @@ -246,5 +256,6 @@ export {
LayoutView,
ContextTrailView,
HeaderView,
AddActionView,
ListView,
};
27 changes: 11 additions & 16 deletions src/js/views/programs/program/flow/header.hbs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
<div class="program-flow__header js-flow">
<h1 class="program-flow__name">{{fas "folder-open"}} {{ name }}</h1>
<div>
<p class="program-flow__details">
{{#if details}}
{{ details }}
{{ else }}
<button class="program-flow__meta button-secondary">{{far "pen-to-square"}} Add Details</button>
{{/if}}
</p>{{~ remove_whitespace ~}}
<span class="program-flow__meta" data-behavior-region></span>
<span class="program-flow__meta" data-owner-region></span>
</div>
</div>
<div class="program-flow__actions">
<button class="button-primary js-add-action">{{far "circle-plus"}}<span>{{ @intl.programs.program.flow.headerTemplate.action }}</span></button>
<h1 class="program-flow__name">{{fas "folder-open"}} {{ name }}</h1>
<div>
<p class="program-flow__details">
{{#if details}}
{{ details }}
{{ else }}
<button class="program-flow__meta button-secondary">{{far "pen-to-square"}} Add Details</button>
{{/if}}
</p>{{~ remove_whitespace ~}}
<span class="program-flow__meta" data-behavior-region></span>
<span class="program-flow__meta" data-owner-region></span>
</div>
6 changes: 4 additions & 2 deletions test/integration/programs/sidebar/flow-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ context('flow sidebar', function() {
.as('routePatchFlow');

cy
.get('.js-flow')
.get('.program-flow__header')
.as('flowHeader')
.click('right')
.should('have.class', 'is-selected');
Expand All @@ -222,6 +222,7 @@ context('flow sidebar', function() {

cy
.get('@flowHeader')
.should('not.have.class', 'is-selected')
.click('right');

cy
Expand Down Expand Up @@ -278,6 +279,7 @@ context('flow sidebar', function() {

cy
.get('@flowHeader')
.should('have.class', 'is-selected')
.should('contain', 'Here are some details');

cy
Expand Down Expand Up @@ -494,7 +496,7 @@ context('flow sidebar', function() {
.wait('@routeProgramFlow');

cy
.get('.js-flow')
.get('.program-flow__header')
.as('flowHeader')
.click('right');

Expand Down

0 comments on commit d506949

Please sign in to comment.