Skip to content

Commit c1c3104

Browse files
committed
ENH Add UnsavedChangesIndicator to edit form
1 parent 9414157 commit c1c3104

6 files changed

Lines changed: 36 additions & 7 deletions

File tree

client/dist/js/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/containers/CampaignAdmin/CampaignAdmin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ By removing this item all linked items will be removed unless used elsewhere.`;
314314
</Toolbar>
315315
<FormBuilderLoaderComponent
316316
fieldHolder={{ className: 'panel panel--padded panel--scrollable flexbox-area-grow form--inline' }}
317-
actionHolder={{ className: 'toolbar--south' }}
317+
actionHolder={{ className: 'toolbar--south btn-toolbar' }}
318318
onSubmit={handleCreateCampaignSubmit}
319319
onAction={handleFormAction}
320320
schemaUrl={schemaUrl}
@@ -343,7 +343,7 @@ By removing this item all linked items will be removed unless used elsewhere.`;
343343

344344
<FormBuilderLoaderComponent
345345
fieldHolder={{ className: 'panel panel--padded panel--scrollable flexbox-area-grow form--inline' }}
346-
actionHolder={{ className: 'toolbar--south' }}
346+
actionHolder={{ className: 'toolbar--south btn-toolbar' }}
347347
onAction={handleFormAction}
348348
schemaUrl={schemaUrl}
349349
identifier="Campaign.EditView"

client/src/containers/CampaignAdmin/CampaignAdminList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ const CampaignAdminList = ({
378378
<div className={bodyClass}>
379379
{body}
380380
</div>
381-
<div className="toolbar toolbar--south">
381+
<div className="toolbar toolbar--south btn-toolbar">
382382
{renderButtonToolbar()}
383383
</div>
384384
</div>

src/CampaignAdmin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SilverStripe\CampaignAdmin;
44

55
use LogicException;
6+
use SilverStripe\Admin\Forms\UnsavedChangesIndicator;
67
use SilverStripe\Admin\LeftAndMain;
78
use SilverStripe\Admin\LeftAndMainFormRequestHandler;
89
use SilverStripe\Control\Controller;
@@ -658,7 +659,8 @@ public function getCampaignEditForm($id)
658659
],
659660
]),
660661
FormAction::create('cancel', _t(__CLASS__.'.CANCEL', 'Cancel'))
661-
->setUseButtonTag(true)
662+
->setUseButtonTag(true),
663+
UnsavedChangesIndicator::create('UnsavedChangesIndicator')
662664
),
663665
RequiredFieldsValidator::create('Name')
664666
);
@@ -722,7 +724,8 @@ public function getCampaignCreateForm()
722724
FormAction::create('save', _t(__CLASS__.'.CREATE', 'Create'))
723725
->setIcon('plus'),
724726
FormAction::create('cancel', _t(__CLASS__.'.CANCEL', 'Cancel'))
725-
->setUseButtonTag(true)
727+
->setUseButtonTag(true),
728+
UnsavedChangesIndicator::create('UnsavedChangesIndicator')
726729
),
727730
RequiredFieldsValidator::create('Name')
728731
);

tests/behat/features/manage-campaigns.feature

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ Feature: Manage campaigns
55
So that I can control bulk publication of content efficiently
66

77
Background:
8+
89
Given a "ChangeSet" "Test Campaign" with "Description"="this is a test"
10+
# Config will put ~2 second delay until the unsaved changes notice shows
11+
And I have a config file "unsaved-changes-indicator-campaign-admin.yml"
912
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Campaigns' section" and "Access to 'Files' section" and "FILE_EDIT_ALL"
1013
And the "group" "CAMPAIGNS_EDITOR" has permissions "Access to 'Campaigns' section"
1114

@@ -14,7 +17,13 @@ Feature: Manage campaigns
1417
And I go to "/admin/campaigns"
1518
When I press the "Add new campaign" button
1619
Then I should see the "Form_campaignCreateForm" form
17-
When I fill in "Name" with "newcampaign"
20+
When I fill in "Name" with "something"
21+
Then I should not see the ".unsaved-changes-indicator" element
22+
When I wait for 3 seconds
23+
Then I should see the ".unsaved-changes-indicator" element
24+
# Not testing reverting the name to "" to see if .unsaved-changes-indicator no longer shows
25+
# because `When I fill in "Name" with ""` i.e. a blank value, does not work in react context
26+
# We do test the 'no longer shows' functionality below in "I can edit campaign"
1827
And I fill in "Description" with "awesome campaign"
1928
And I press the "Create" button
2029
Then the "p.alert" element should contain "Nice one! You have successfully created a campaign."
@@ -30,6 +39,12 @@ Feature: Manage campaigns
3039
And the "State" field should contain "open"
3140
And I should see a "button[name=action_save] .font-icon-tick" element
3241
When I fill in "Name" with "changed"
42+
Then I should not see the ".unsaved-changes-indicator" element
43+
When I wait for 3 seconds
44+
Then I should see the ".unsaved-changes-indicator" element
45+
When I fill in "Name" with "Test Campaign"
46+
Then I should not see the ".unsaved-changes-indicator" element
47+
And I fill in "Name" with "changed"
3348
Then I should see a "button[name=action_save] .font-icon-save" element
3449
When I fill in "Name" with "Test Campaign"
3550
Then I should see a "button[name=action_save] .font-icon-tick" element
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
Name: unsaved-changes-indicator-campaign-admin
3+
---
4+
SilverStripe\Admin\Forms\UnsavedChangesIndicator:
5+
minutes:
6+
# 0.03 is about 2 seconds
7+
notice: 0.03
8+
# Not testing the warning level because that is covered by
9+
# silverstripe/admin UnsavedChangesIndicatorTimer-test.js and do not want to:
10+
# a) slow down behat tests unnecessarily, and
11+
# b) introduce potentional flakiness in behat tests due to timing issues

0 commit comments

Comments
 (0)