-
Notifications
You must be signed in to change notification settings - Fork 15
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
ENH Use getStatusFlags() instead of hardcoded statuses #351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,9 +198,11 @@ | |
width: 100%; | ||
|
||
.badge { | ||
color: #cf3f00; | ||
background-color: #fff2ea; | ||
padding: 2px 3px 2px 4px; | ||
|
||
&:not(:last-child) { | ||
margin-right: 5px; | ||
} | ||
Comment on lines
+203
to
+205
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs a gap between badges - this value matches the right margin on the title text |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How is this prop being passed in? There's no corresponding PHP change in this PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes there is. See the |
||
typeTitle, | ||
typeIcon, | ||
onDelete, | ||
|
@@ -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"> | ||
|
@@ -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, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
]; | ||
|
@@ -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]); | ||
Comment on lines
-256
to
+257
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated change - my IDE was upset that the return type was string but this returns |
||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rely on styling in admin for colours