Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX ModelAdmin toast elements #1615

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions client/lang/src/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"Admin.REMOVE_LINK": "Remove link",
"Admin.SELECTONEPAGE": "Please select at least one page",
"Admin.VALIDATIONERROR": "Validation Error",
"Admin.DELETE_CONFIRM_MESSAGE": "Deleted",
"Admin.ARCHIVE_CONFIRM_MESSAGE": "Archived",
"Admin.VALIDATION_ERRORS_IN_TAB": "This tab contains validation errors.",
"Admin.VALIDATION_ERRORS_IN_TAB_SCREEN_READER": "(Has validation errors)",
"Admin.VALIDATION_ERRORS_ON_PAGE": "There are validation errors on this page, please fix them before saving or publishing.",
Expand Down
10 changes: 9 additions & 1 deletion client/src/legacy/GridField.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ $.entwine('ss', function($) {
});

// Covers both tabular delete button, and the button on the detail form
$('.grid-field .grid-field__col-compact .action--delete, .grid-field .grid-field__col-compact .action--archive, .cms-edit-form .btn-toolbar .action--delete, .cms-edit-form .btn-toolbar .action--archive').entwine({
$('.grid-field .grid-field__col-compact .action--delete, .grid-field .grid-field__col-compact .action--archive, .cms-edit-form .btn-toolbar .action--delete, .cms-edit-form .btn-toolbar .action--archive, .grid-field__col-compact .gridfield-button-unlink').entwine({
onclick: function(e){
const confirmMessage = $(this).hasClass('action--archive')
? i18n._t('Admin.ARCHIVECONFIRMMESSAGE', 'Are you sure you want to archive this record?')
Expand All @@ -569,6 +569,14 @@ $.entwine('ss', function($) {
} else {
this._super(e);
}

const toastNotificationMessage = $(this).hasClass('action--archive')
? ss.i18n._t('Admin.ARCHIVE_CONFIRM_MESSAGE', 'Archived')
: ss.i18n._t('Admin.DELETE_CONFIRM_MESSAGE', 'Deleted');

if ($(this).hasClass('dropdown-item')) {
jQuery.noticeAdd({text: toastNotificationMessage, type: 'success', stayTime: 5000, inEffect: {left: '0', opacity: 'show'}});
}
}
});

Expand Down
24 changes: 13 additions & 11 deletions client/src/legacy/LeftAndMain.EditForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ $.entwine('ss', function($){

this._super();
},

'from .cms-tabset': {
onafterredrawtabs: function () {

Expand All @@ -126,10 +127,7 @@ $.entwine('ss', function($){
'Admin.VALIDATION_ERRORS_ON_PAGE',
'There are validation errors on this page, please fix them before saving or publishing.'
);
const toastNotificationMessage = ss.i18n._t(
'Admin.VALIDATIONERROR',
'Validation Error'
);

const $editFormErrorBanner = $("#Form_EditForm_error");

// Remove any existing invalid tab icons and screen-reader text
Expand Down Expand Up @@ -159,13 +157,6 @@ $.entwine('ss', function($){
return;
}

// Show a toast notification for DataObject::getCMSValidator() validation errors
if (!this.getValidationErrorShown() && this.hasClass('validationerror')) {
errorMessage(toastNotificationMessage);
// Ensure that this error message popup won't be added more than once
this.setValidationErrorShown(true);
}

// Find tab-pane's with decedent validation .alert's
const $invalidTabPanes = this.find('.tab-pane .alert-danger, .tab-pane .alert.error').closest('.tab-pane');
if (!$invalidTabPanes.length) {
Expand Down Expand Up @@ -213,6 +204,17 @@ $.entwine('ss', function($){
redraw: function() {
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));

if (!this.getValidationErrorShown() && this.hasClass('validationerror')) {
const toastNotificationMessage = ss.i18n._t(
'Admin.VALIDATIONERROR',
'Validation Error'
);

errorMessage(toastNotificationMessage);
// Ensure that this error message popup won't be added more than once
this.setValidationErrorShown(true);
}

// Force initialization of tabsets to avoid layout glitches
this.add(this.find('.cms-tabset')).redrawTabs();
this.find('.cms-content-header').redraw();
Expand Down
83 changes: 83 additions & 0 deletions tests/behat/features/gridfield-toast-messages.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
Feature: Show toast messages
As an author
I want to see toast message in the CMS when I create, edit, delete, publish, unpublish, archive a record

Background:
Given the "Company" "Company A" with "Category"="Other"
And the "Company" "Company B" with "Category"="Other"
And the "Company" "Company C" with "Category"="Other"
And the "Employee" "Employee A" with "Company"="1"
And the "Employee" "Employee B" with "Company"="1"
And the "Employee" "Employee C" with "Company"="1"
And the "group" "EDITOR" has permissions "Access to 'Pages' section" and "Access to 'Test ModelAdmin' section" and "TEST_DATAOBJECT_EDIT"
And I am logged in as a member of "EDITOR" group
And I go to "/admin/test"

Scenario: I can see toast message when I successfully create or publish a record
When I press the "Add Company" button
And I fill in "Name" with "My Company"
And I press the "Create" button
Then I should see a "Saved Company "My Company" successfully" success toast
And I fill in "Name" with "My New Company"
And I wait for 5 seconds
And I press the "Publish" button
Then I should see a "Published Company "My New Company"" success toast

Scenario: I can see toast message when I successfully unpublish and archive a record
When I click "Company B" in the "#Form_EditForm" element
And I press the "Publish" button
Then I should see a "Published Company "Company B"" success toast
And I wait for 5 seconds
And I click "More options" in the "#ActionMenus" element
And I press the "Unpublish" button, confirming the dialog
Then I should see a "Unpublished Company "Company B"" success toast
And I wait for 5 seconds
And I click "More options" in the "#ActionMenus" element
And I press the "Archive" button, confirming the dialog
And I should not see "Validation Error"
And I should see a "Archived Company "Company B"" success toast

Scenario: I can see toast message when I successfully delete a record
When I click "Company A" in the "#Form_EditForm" element
And I click "Employees" in the ".ui-tabs-nav" element
Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element
And I click "Employee A" in the "#Form_ItemEditForm_Employees" element
And I press the "Delete" button, confirming the dialog
Then I should see a "Deleted Employee "Employee A"" success toast
Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element

Scenario: I can see toast message when I successfully delete a record by clicking the Unlink button in action menu
When I click "Company A" in the "#Form_EditForm" element
And I click "Employees" in the ".ui-tabs-nav" element
Then I should see "Employee A" in the "#Form_ItemEditForm_Employees" element
And I press the "View actions" button
And I press the "Unlink" button, confirming the dialog
And I wait for 1 seconds
Then I should see a "Deleted" success toast
Then I should not see "Employee A" in the "#Form_ItemEditForm_Employees" element

Scenario: I can see toast message when I successfully delete a record by clicking the Archive button in action menu
And I should see "Company A" in the "#Form_EditForm" element
And I press the "View actions" button
And I press the "Archive" button, confirming the dialog
And I wait for 2 seconds
Then I should see a "Archived" success toast
Then I should not see "Company A" in the "#Form_EditForm" element

Scenario: I can see toast message when I have validation errors
When I click "Company C" in the "#Form_EditForm" element
And I fill in "Name" with ""
And I press the "Save" button
Then I should see "Validation Error"
And I fill in "Name" with "New Company C"
And I press the "Save" button
Then I should see a "Saved Company "New Company C" successfully" success toast

Scenario: I can see toast message when I have validation errors when I edit a nested record
When I click "Company A" in the "#Form_EditForm" element
And I click "Employees" in the ".ui-tabs-nav" element
Then I should see "Employee B" in the "#Form_ItemEditForm_Employees" element
And I click "Employee B" in the "#Form_ItemEditForm_Employees" element
And I fill in "Name" with ""
And I press the "Save" button
Then I should see "Validation Error"
6 changes: 3 additions & 3 deletions tests/behat/features/lostpassword.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Lost Password
And there should be an email to "[email protected]" titled "Your password reset link"
When I click on the "password reset link" link in the email to "[email protected]"
Then I should see "Please enter a new password"
When I fill in "newpassword" for "New Password"
And I fill in "newpassword" for "Confirm New Password"
When I fill in "NEWsecret!@#*&^" for "New Password"
And I fill in "NEWsecret!@#*&^" for "Confirm New Password"
And I press the "Change Password" button
Then the password for "[email protected]" should be "newpassword"
Then the password for "[email protected]" should be "NEWsecret!@#*&^"
7 changes: 4 additions & 3 deletions tests/behat/features/manage-users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ Feature: Manage users
Then I click "Groups" in the ".breadcrumbs-wrapper" element
And I click the "Groups" CMS tab
And I click "ADMIN group2" in the "#Root_Groups" element
And I should see the "Unlink" button in the "Members" gridfield for the "ADMIN" row
Then I click the "Unlink" button in the "Members" gridfield for the "ADMIN" row
And I should not see the "Unlink" button in the "Members" gridfield for the "ADMIN" row
And I press the "View actions" button
And I press the "Unlink" button, confirming the dialog
And I wait for 1 seconds
Then I should see a "Deleted" success toast
Then I click "Groups" in the ".breadcrumbs-wrapper" element
And I click the "Groups" CMS tab
And I click "ADMIN group" in the "#Root_Groups" element
Expand Down
10 changes: 5 additions & 5 deletions tests/behat/features/profile.feature
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Feature: Manage my own settings
Scenario: I can't reset the password without the original
Given I follow "Change Password"
And I fill in "Current Password" with "idontknow"
And I fill in "New Password" with "newsecret"
And I fill in "Confirm Password" with "newsecret"
And I fill in "New Password" with "NEWsecret!@#*&^"
And I fill in "Confirm Password" with "NEWsecret!@#*&^"
And I press the "Save" button
Then I should see "The current password you have entered is not correct."

Expand All @@ -53,11 +53,11 @@ Feature: Manage my own settings
Scenario: I can change my password
Given I follow "Change Password"
And I fill in "Current Password" with "secret"
And I fill in "New Password" with "newsecret"
And I fill in "Confirm Password" with "newsecret"
And I fill in "New Password" with "NEWsecret!@#*&^"
And I fill in "Confirm Password" with "NEWsecret!@#*&^"
And I press the "Save" button
And I am not logged in
When I log in with "[email protected]" and "newsecret"
When I log in with "[email protected]" and "NEWsecret!@#*&^"
And I go to "admin/myprofile"
Then I should see the CMS

Expand Down