Skip to content

Commit

Permalink
API Update API to reflect changes in silverstripe/framework (#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Nov 26, 2024
1 parent 26f8dde commit 59aea22
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 54 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

46 changes: 16 additions & 30 deletions client/src/components/ElementEditor/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,38 +114,24 @@ class Header extends Component {
);
}

renderStatusBadge() {
const {
element: { isLiveVersion, isPublished },
} = this.props;

// No indication required for published elements
if (isPublished && isLiveVersion) {
renderStatusFlagBadges() {
const statusFlags = this.props.element.statusFlags;
if (!statusFlags) {
return null;
}

let versionStateTitle = '';
let versionStateButtonTitle = '';
const stateClassNames = ['badge'];

if (!isPublished) {
versionStateTitle = i18n._t('ElementHeader.BADGE_DRAFT', 'Draft');
versionStateButtonTitle = i18n._t('ElementHeader.STATE_DRAFT', 'Item has not been published yet');
stateClassNames.push('status-addedtodraft');
} else if (!isLiveVersion) {
versionStateTitle = i18n._t('ElementHeader.BADGE_MODIFIED', 'Modified');
versionStateButtonTitle = i18n._t('ElementHeader.STATE_MODIFIED', 'Item has unpublished changes');
stateClassNames.push('status-modified');
const badges = [];
// eslint-disable-next-line no-restricted-syntax
for (let [cssClasses, data] of Object.entries(statusFlags)) {
cssClasses = `badge status-${cssClasses}`;
if (typeof data === 'string') {
data = { text: data };
}
if (!data.title) {
data.title = '';
}
badges.push(<span key={cssClasses} className={cssClasses} title={data.title}>{data.text}</span>);
}

return (
<span
className={classNames(stateClassNames)}
title={versionStateButtonTitle}
>
{versionStateTitle}
</span>
);
return badges;
}

render() {
Expand Down Expand Up @@ -209,7 +195,7 @@ class Header extends Component {
</Tooltip>}
</div>
<h3 className={titleClasses}>{title}</h3>
{this.renderStatusBadge()}
{this.renderStatusFlagBadges()}
</div>
{!simple && <div className="element-editor-header__actions">
<div role="none" onClick={(event) => event.stopPropagation()}>
Expand Down
2 changes: 0 additions & 2 deletions client/src/components/ElementEditor/Header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
max-width: calc(100% - 60px);

.badge {
color: $state-draft;
background-color: $state-modified-bg;
padding: 2px 3px 2px 4px;
margin-left: 0.5rem;
}
Expand Down
16 changes: 14 additions & 2 deletions client/src/components/ElementEditor/tests/Header-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,13 @@ test('Header should render a versioned draft badge when the element is not publi
element: {
id: 14,
isPublished: false,
liveVersion: false
liveVersion: false,
statusFlags: {
addedtodraft: {
text: 'Draft',
title: 'Item has not been published yet'
}
}
}
})}
/>);
Expand All @@ -242,7 +248,13 @@ test('Header should render a versioned modified badge when the element is modifi
element: {
id: 14,
isPublished: true,
isLiveVersion: false
isLiveVersion: false,
statusFlags: {
modified: {
text: 'Modified',
title: 'Item has unpublished changes'
}
}
}
})}
/>);
Expand Down
2 changes: 1 addition & 1 deletion docs/en/04_defining-you-own-elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class MyElement extends BaseElement

private static $plural_name = 'my elements';

private static $description = 'What my custom element does';
private static $class_description = 'What my custom element does';

public function getCMSFields()
{
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/ElementalAreaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public function apiReadElements(HTTPRequest $request): HTTPResponse
'canPublish' => $element->canPublish(),
'canUnpublish' => $element->canUnpublish(),
'canCreate' => $element->canCreate(),
'statusFlags' => $element->getStatusFlags(),
];
}
$this->extend('updateApiReadElementalArea', $data, $request);
Expand Down
11 changes: 1 addition & 10 deletions src/Models/BaseElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,7 @@ class BaseElement extends DataObject implements CMSPreviewable

/**
* Describe the purpose of this element
*
* @config
* @var string
* @deprecated 5.4.0 use class_description instead.
*/
private static $description = 'Base element class';

private static $class_description = 'Base element class';

/**
Expand Down Expand Up @@ -1122,10 +1116,7 @@ public function getIcon()
*/
public function getTypeNice()
{
$description = $this->config()->uninherited('description');
if ($description) {
$description = _t(__CLASS__ . '.Description', $description);
}
$description = $this->i18n_classDescription();
$markup = ($description) ? ' <span class="element__note"> &mdash; ' . $description . '</span>' : '';

return DBField::create_field(
Expand Down
5 changes: 0 additions & 5 deletions src/Models/ElementContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class ElementContent extends BaseElement

private static $plural_name = 'content blocks';

/**
* @deprecated 5.4.0 use class_description instead.
*/
private static $description = 'HTML text block';

private static $class_description = 'HTML text block';

/**
Expand Down
6 changes: 4 additions & 2 deletions tests/Behat/features/restore-archived-element.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ Feature: Restore to draft
And I click on the ".element-editor__actions-archive" element, confirming the dialog
And I go to "/admin/archive"
Then I click "Blocks" in the ".ui-tabs-nav" element
And I should see "MyBlock" in the "#Form_EditForm" element
Then I click "MyBlock" in the "#Form_EditForm" element
And I should see "MyBlock" in the "#Form_EditForm .col-Title" element
# Need to use "directly" here or it will think the badge is part of the text in the element
# which results in thinking it's not a match ("MyBlockArchived" !== "MyBlock")
Then I click "MyBlock" directly in the "#Form_EditForm .col-Title" element
When I press the "Restore to draft" button
Then I should see "Successfully restored the content block" in the "#Form_EditForm" element
And I go to "/admin/pages"
Expand Down
18 changes: 18 additions & 0 deletions tests/Controllers/ElementalAreaControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,12 @@ public function testApiRead(
'canPublish' => true,
'canUnpublish' => true,
'canCreate' => true,
'statusFlags' => [
'addedtodraft' => [
'text' => 'Draft',
'title' => 'Item has not been published yet',
],
],
],
[
'id' => 2,
Expand All @@ -721,6 +727,12 @@ public function testApiRead(
'canPublish' => true,
'canUnpublish' => true,
'canCreate' => true,
'statusFlags' => [
'addedtodraft' => [
'text' => 'Draft',
'title' => 'Item has not been published yet',
],
],
],
[
'id' => 3,
Expand All @@ -740,6 +752,12 @@ public function testApiRead(
'canPublish' => true,
'canUnpublish' => true,
'canCreate' => true,
'statusFlags' => [
'addedtodraft' => [
'text' => 'Draft',
'title' => 'Item has not been published yet',
],
],
],
];
}
Expand Down

0 comments on commit 59aea22

Please sign in to comment.