Skip to content

Commit

Permalink
FIX Allow publishing non-inline-editable blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Feb 2, 2025
1 parent 720284f commit 28461ef
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions client/src/components/ElementEditor/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const Element = (props) => {
const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
const [publishBlock] = useMutation(publishBlockMutation);

const formRenderedIfNeeded = formHasRendered || !props.type.inlineEditable;

useEffect(() => {
// Note that formDirty from redux can be set to undefined after failed validation
// which is confusing as the block still has unsaved changes, hence why we create
Expand Down Expand Up @@ -77,7 +79,7 @@ const Element = (props) => {
}, []);

useEffect(() => {
if (justClickedPublishButton && formHasRendered) {
if (justClickedPublishButton && formRenderedIfNeeded) {
setJustClickedPublishButton(false);
if (hasUnsavedChanges) {
// Save the element first before publishing, which may trigger validation errors
Expand Down Expand Up @@ -165,12 +167,12 @@ const Element = (props) => {

// Publish action
useEffect(() => {
if (formHasRendered && doPublishElement) {
if (doPublishElement && formRenderedIfNeeded) {
publishBlock({ variables: { blockId: props.element.id } })
.then(() => handleAfterPublish(false))
.catch(() => handleAfterPublish(true));
}
}, [formHasRendered, doPublishElement]);
}, [doPublishElement, formHasRendered]);

/**
* Returns the applicable versioned state class names for the element
Expand Down Expand Up @@ -314,7 +316,9 @@ const Element = (props) => {

const handlePublishButtonClick = () => {
setJustClickedPublishButton(true);
setEnsureFormRendered(true);
if (props.type.inlineEditable) {
setEnsureFormRendered(true);
}
};

const handleFormInit = (activeTab) => {
Expand Down
3 changes: 1 addition & 2 deletions tests/Behat/Context/FixtureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\DB;
use SilverStripe\ORM\Queries\SQLInsert;
use SilverStripe\FrameworkTest\Elemental\Model\ElementalSearchableFieldsBlock;

/**
* Context used to create fixtures in the SilverStripe ORM.
Expand Down Expand Up @@ -47,7 +46,7 @@ public function theHasAContentElementWithContent($type, $pageTitle, $elementTitl
}

/**
* @Given /a "([^"]+)" "([^"]+)" with a "([^"]+)" element titled "([^"]+)"/
* @Given /(?:the|a) "([^"]+)" "([^"]+)" (?:with|has) a "([^"]+)" element titled "([^"]+)"/
*
* e.g. Given a "page" "My page" with a "My\App\MyBlock" element titled "Some block"
*
Expand Down
32 changes: 23 additions & 9 deletions tests/Behat/features/publish-block-element.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Feature: Publish elements in the CMS
Given I add an extension "DNADesign\Elemental\Extensions\ElementalPageExtension" to the "Page" class
And a "page" "Blocks Page" with a "Block A" content element with "Some content" content
And the "page" "Blocks Page" has a "Block B" content element with "Some content II" content
And the "page" "Blocks Page" has a "SilverStripe\FrameworkTest\Elemental\Model\HasGridFieldElementalBlock" element titled "GridField Block"

Given the "group" "EDITOR" has permissions "Access to 'Pages' section"
And I am logged in as a member of "EDITOR" group
Expand All @@ -19,38 +20,51 @@ Feature: Publish elements in the CMS
When I see a list of blocks
Then I should see "Block A"
And I should see "Block B"
And I should see "GridField Block"

@modal
Scenario: I can publish a block
Scenario: I can publish an inline-editable block
Given I see a list of blocks
When I press the "View actions" button
When I press the "View actions" button for block 1
Then I should see the publish button for block 1
When I press the "Publish" button
And I wait 1 second
Then I should see a "Published 'Block A' successfully" success toast
# Behat's assertion is faster than React's rendering
# Behat's assertion is faster than React's rendering
When I wait 1 second
And I press the "View actions" button
And I press the "View actions" button for block 1
Then I should see the unpublish button for block 1
But I should not see the publish button for block 1

Scenario: Correct toast notification shows when saving or publishing block will show new title
Scenario: I can publish a non-inline-editable block with a gridfield
Given I see a list of blocks
When I press the "View actions" button for block 3
Then I should see the publish button for block 3
When I press the "Publish" button
And I wait 1 second
Then I should see a "Published 'GridField Block' successfully" success toast
# Behat's assertion is faster than React's rendering
When I wait 1 second
And I press the "View actions" button for block 3
Then I should see the unpublish button for block 3
But I should not see the publish button for block 3

Scenario: Correct toast notification shows when saving or publishing inline block will show new title
# Changing title, saving and then publishing
When I click on the caret button for block 1
And I fill in "New title" for "Title" for block 1
When I press the "View actions" button
When I press the "View actions" button for block 1
And I press the "Save" button
And I wait 1 second
Then I should see a "Saved 'New title' successfully" success toast
When I click on the ".toast__close" element
And I press the "View actions" button
And I press the "View actions" button for block 1
And I press the "Publish" button
And I wait 1 second
Then I should see a "Published 'New title' successfully" success toast

# Changing title and publishing straight away
When I fill in "Great title" for "Title" for block 1
And I press the "View actions" button
And I press the "View actions" button for block 1
And I press the "Publish" button
And I wait 1 second
Then I should see a "Published 'Great title' successfully" success toast

0 comments on commit 28461ef

Please sign in to comment.