Skip to content

Commit

Permalink
ENH Use getStatusFlags() instead of hardcoded statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Nov 21, 2024
1 parent 9402eb5 commit f815bb1
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion client/src/components/LinkField/LinkField.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ const LinkField = ({
title={linkData.title}
description={linkData.description}
versionState={linkData.versionState}
statusFlags={linkData.statusFlags}
typeTitle={type.title || ''}
typeIcon={type.icon}
onDelete={handleDelete}
Expand Down Expand Up @@ -511,7 +512,7 @@ const LinkField = ({
.then(async () => {
onChange(newLinkIDs);
actions.toasts.success(i18n._t('LinkField.SORT_SUCCESS', 'Updated link sort order'));
// Force a rerender so that links are retched so that versionState badges are up to date
// Force a rerender so that links are retched so that status flag badges are up to date
setForceFetch(forceFetch + 1);
})
.catch(() => {
Expand Down
6 changes: 4 additions & 2 deletions client/src/components/LinkPicker/LinkPicker.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@
width: 100%;

.badge {
color: #cf3f00;
background-color: #fff2ea;
padding: 2px 3px 2px 4px;

&:not(:last-child) {
margin-right: 5px;
}
}
}

Expand Down
30 changes: 17 additions & 13 deletions client/src/components/LinkPicker/LinkPickerTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,30 @@ const stopPropagation = (fn) => (e) => {
fn && fn();
}

const getVersionedBadge = (versionState) => {
let title = '';
let label = ''
if (versionState === versionStates.draft) {
title = i18n._t('LinkField.LINK_DRAFT_TITLE', 'Link has draft changes');
label = i18n._t('LinkField.LINK_DRAFT_LABEL', 'Draft');
} else if (versionState === versionStates.modified) {
title = i18n._t('LinkField.LINK_MODIFIED_TITLE', 'Link has unpublished changes');
label = i18n._t('LinkField.LINK_MODIFIED_LABEL', 'Modified');
} else {
const renderStatusFlagBadges = (statusFlags) => {
if (!statusFlags) {
return null;
}
const className = classnames('badge', `status-${versionState}`);
return <span className={className} title={title}>{label}</span>;
const badges = [];
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 badges;
};

const LinkPickerTitle = ({
id,
title,
description,
versionState,
statusFlags,
typeTitle,
typeIcon,
onDelete,
Expand Down Expand Up @@ -132,7 +135,7 @@ const LinkPickerTitle = ({
<div className="link-picker__link-detail">
<div className="link-picker__title">
<span className="link-picker__title-text">{title}</span>
{getVersionedBadge(versionState)}
{renderStatusFlagBadges(statusFlags)}
</div>
{typeTitle && (
<small className="link-picker__type">
Expand Down Expand Up @@ -175,6 +178,7 @@ LinkPickerTitle.propTypes = {
title: PropTypes.string,
description: PropTypes.string,
versionState: PropTypes.oneOf(Object.values(versionStates)),
statusFlags: PropTypes.object,
typeTitle: PropTypes.string.isRequired,
typeIcon: PropTypes.string.isRequired,
onDelete: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function makeProps(obj = {}) {
title: 'My title',
description: 'My description',
versionState: 'draft',
statusFlags: { draft: 'Draft' },
typeTitle: 'Phone',
typeIcon: 'font-icon-phone',
canDelete: true,
Expand Down
3 changes: 2 additions & 1 deletion src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public function getData(): array
'description' => $this->getDescription(),
'canDelete' => $this->canDelete(),
'versionState' => $this->getVersionedState(),
'statusFlags' => $this->getStatusFlags(),
'typeKey' => $typeKey,
'sort' => $this->Sort,
];
Expand All @@ -253,7 +254,7 @@ public function forTemplate(): string
{
// First look for a subclass of the email template e.g. EmailLink.ss which may be defined
// in a project. Fallback to using the generic Link.ss template which this module provides
return $this->renderWith([static::class, Link::class]);
return (string) $this->renderWith([static::class, Link::class]);
}

/**
Expand Down

0 comments on commit f815bb1

Please sign in to comment.