Skip to content

Commit

Permalink
Auto translated status, add archived status and functionalise component
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Rainville committed Aug 29, 2019
1 parent 2d298d4 commit ef4b191
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion client/lang/src/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@
"Admin.VALIDATOR_MESSAGE_DATE": "{name} is not a proper date format.",
"Admin.VALIDATOR_MESSAGE_ALPHANUMERIC": "{name} is not an alphanumeric value.",
"Admin.VALIDATOR_MESSAGE_ALPHA": "{name} is not only letters.",
"Admin.VALIDATOR_MESSAGE_DEFAULT": "{name} is not a valid value."
"Admin.VALIDATOR_MESSAGE_DEFAULT": "{name} is not a valid value.",
"Admin.DRAFT": "Draft",
"Admin.MODIFIED": "Modified",
"Admin.LIVE": "Live",
"Admin.ARCHIVED": "Archived",
}
4 changes: 1 addition & 3 deletions client/src/components/VersionedBadge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ Badge component for displaying versioning states in a Bootstrap "badge" based st
```js
const props = {
status: 'draft',
message: 'Draft',
className: 'my-custom-class',
};
<VersionedBadge {...props} />
```

## Properties

* `status` (string): The status for the badge, takes versioning states e.g. `draft`, `modified`, `live`.
* `message` (string): The string to display in the badge. Usually would be "Draft", "Published", etc.
* `status` (string): The status for the badge, takes versioning states e.g. `draft`, `modified`, `live`, `archived`.
* `className` (string): Any extra classes to apply for the badge.
57 changes: 23 additions & 34 deletions client/src/components/VersionedBadge/VersionedBadge.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { PureComponent } from 'react';
import React from 'react';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import Badge from 'components/Badge/Badge';
import i18n from 'i18n';

/**
* List of valid versioned statuses for a Badge
Expand All @@ -10,44 +11,32 @@ import Badge from 'components/Badge/Badge';
export const statuses = [
'draft',
'modified',
'live'
'live',
'archived',
];

class VersionedBadge extends PureComponent {
render() {
const { status, className } = this.props;
if (!status) {
return null;
}

const compiledClassNames = classnames(
className,
'versioned-badge',
`versioned-badge--${status}`,
);

const props = {
...this.props,
className: compiledClassNames,
status: 'default',
inverted: false,
};

return (
<Badge {...props} />
);
}
}
/**
* Capitalise the first letter
* @param {string} str
* @returns {string}
*/
const toTitleCase = (str) => str.replace(/^\w/, c => c.toUpperCase());

const VersionedBadge = ({ status, className }) => {
const props = {
className: classnames(className, 'versioned-badge', `versioned-badge--${status}`),
message: i18n._t(`ADMIN.${status.toUpperCase()}`, toTitleCase(status)),
status: 'default',
};

return (
<Badge {...props} />
);
};

VersionedBadge.propTypes = {
message: PropTypes.node,
status: PropTypes.oneOf(statuses),
status: PropTypes.oneOf(statuses).isRequired,
className: PropTypes.string,
};

VersionedBadge.defaultProps = {
status: 'default',
className: '',
};

export default VersionedBadge;
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import VersionedBadge from 'components/VersionedBadge/VersionedBadge';
storiesOf('Admin/Badges', module)
.add('Versioned badge', () => (
<div>
<p>My Page Name <VersionedBadge message="Draft" status="draft" /></p>
<p>Contact Us <VersionedBadge message="Modified" status="modified" /></p>
<p>About Us <VersionedBadge message="Live" status="live" /></p>
<p>My Page Name <VersionedBadge status="draft" /></p>
<p>Contact Us <VersionedBadge status="modified" /></p>
<p>About Us <VersionedBadge status="live" /></p>
<p>Old Page <VersionedBadge status="archived" /></p>
</div>
));

0 comments on commit ef4b191

Please sign in to comment.