From f8fa61fcd978b8d15239d96652c581b222444a54 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Sat, 12 Aug 2017 17:55:51 +1000 Subject: [PATCH] Implement maintenance badge for front end --- app/components/badge-maintenance.js | 33 +++++++++++++++++++ .../components/badge-maintenance.hbs | 7 ++++ mirage/fixtures/crates.js | 13 +++++++- tests/acceptance/search-test.js | 1 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 app/components/badge-maintenance.js create mode 100644 app/templates/components/badge-maintenance.hbs diff --git a/app/components/badge-maintenance.js b/app/components/badge-maintenance.js new file mode 100644 index 00000000000..ade8dcc6986 --- /dev/null +++ b/app/components/badge-maintenance.js @@ -0,0 +1,33 @@ +import Component from '@ember/component'; +import { computed } from '@ember/object'; +import { alias } from '@ember/object/computed'; + +export default Component.extend({ + tagName: 'span', + classNames: ['badge'], + escapedStatus: computed('badge', function() { + return this.get('badge.attributes.status').replace(/-/g, '--'); + }), + none: computed('badge', function() { + return this.get('badge.attributes.status') === 'none' + || !this.get('badge.attributes.status'); + }), + status: alias('badge.attributes.status'), + color: computed('badge', function() { + switch (this.get('badge.attributes.status')) { + case 'actively-developed': + return 'brightgreen'; + case 'passively-maintained': + return 'yellowgreen'; + case 'as-is': + return 'yellow'; + case 'experimental': + return 'blue'; + case 'looking-for-maintainer': + return 'orange'; + case 'deprecated': + return 'red'; + } + }), + text: 'Maintenance intention for this crate' +}); diff --git a/app/templates/components/badge-maintenance.hbs b/app/templates/components/badge-maintenance.hbs new file mode 100644 index 00000000000..c14c92d27d9 --- /dev/null +++ b/app/templates/components/badge-maintenance.hbs @@ -0,0 +1,7 @@ +{{#unless none}} + {{text}} +{{/unless}} diff --git a/mirage/fixtures/crates.js b/mirage/fixtures/crates.js index 0b55068e662..e6b27e2b864 100644 --- a/mirage/fixtures/crates.js +++ b/mirage/fixtures/crates.js @@ -1,6 +1,11 @@ /* eslint-disable quotes */ export default [{ - "badges": [], + "badges": [{ + "badge_type": "maintenance", + "attributes": { + "value": "actively-developed" + } + }], "categories": [], "created_at": "2014-12-08T02:08:06Z", "description": "A high-level, Rust idiomatic wrapper around nanomsg.", @@ -191,6 +196,12 @@ export default [{ "updated_at": "2015-11-11T00:10:43Z", "versions": null }, { + "badges": [{ + "badge_type": "maintenance", + "attributes": { + "status": "actively-developed" + } + }], "created_at": "2014-11-23T09:01:21Z", "description": "A Kinetic protocol library written in Rust", "documentation": "https://icorderi.github.io/kinetic-rust/doc/kinetic/", diff --git a/tests/acceptance/search-test.js b/tests/acceptance/search-test.js index 10066be8a04..0ae40213d5f 100644 --- a/tests/acceptance/search-test.js +++ b/tests/acceptance/search-test.js @@ -25,6 +25,7 @@ test('searching for "rust"', async function(assert) { hasText(assert, '#crates .row:first .desc .summary', 'A Kinetic protocol library written in Rust'); hasText(assert, '#crates .row:first .downloads', 'All-Time: 225'); + findWithAssert('#crates .row:first .desc .info img[alt="Maintenance intention for this crate"]'); }); test('pressing S key to focus the search bar', async function(assert) {