From 49574a208a915578383ca8bdd8ca83bbb3665af9 Mon Sep 17 00:00:00 2001 From: Stanislaw Adaszewski Date: Mon, 6 Apr 2020 22:57:58 +0200 Subject: [PATCH] Add wbProcessStateName for reuse. --- .../src/js/component/wb-collection-fields.js | 11 ++-------- .../src/js/component/wb-process-dashboard.js | 20 ++----------------- frontend/src/js/misc/wb-process-state-name.js | 18 +++++++++++++++++ 3 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 frontend/src/js/misc/wb-process-state-name.js diff --git a/frontend/src/js/component/wb-collection-fields.js b/frontend/src/js/component/wb-collection-fields.js index 8888f4a..0049f89 100644 --- a/frontend/src/js/component/wb-collection-fields.js +++ b/frontend/src/js/component/wb-collection-fields.js @@ -7,14 +7,7 @@ import urlForObject from 'url-for-object'; import wbFormatDate from 'wb-format-date'; import WBNameAndUuid from 'wb-name-and-uuid'; import WBAccordion from 'wb-accordion'; - -function formatSpecialValue(value) { - if (value === null) return (null); - if (value === undefined) return (undefined); - if (typeof(value) === 'boolean') return ({ String(value) }); - if (value === '') return '-'; - return String(value); -} +import wbFormatSpecialValue from 'wb-format-special-value'; class WBCollectionFields extends Component { componentDidMount() { @@ -43,7 +36,7 @@ class WBCollectionFields extends Component { throw Error('Item not found'); let rows = [ [ 'Name', item.name ], - [ 'Description', formatSpecialValue(item.description) ], + [ 'Description', wbFormatSpecialValue(item.description) ], [ 'Properties', (
{ JSON.stringify(item.properties, null, 2) }
diff --git a/frontend/src/js/component/wb-process-dashboard.js b/frontend/src/js/component/wb-process-dashboard.js index a251d95..c9b60b5 100644 --- a/frontend/src/js/component/wb-process-dashboard.js +++ b/frontend/src/js/component/wb-process-dashboard.js @@ -1,6 +1,7 @@ import { h, Component } from 'preact'; import WBTable from 'wb-table'; import makeArvadosRequest from 'make-arvados-request'; +import wbProcessStateName from 'wb-process-state-name'; function getAll(makeRequest) { let prom = makeRequest(0); @@ -20,23 +21,6 @@ function getAll(makeRequest) { return prom; } -function determineState(containerRequest) { - const cr = containerRequest; - const c = cr.container; - if (cr.state !== 'Uncommitted' && cr.priority === 0) - return 'Cancelled'; - if (cr.state === 'Uncommitted' || !c || c.state === 'Queued' || c.state === 'Locked') - return 'Pending'; - if (c.state === 'Running') - return 'Running'; - if (c.state === 'Complete' && c.exit_code === 0) - return 'Complete'; - if (c.state === 'Complete' && c.exit_code !== 0) - return 'Failed'; - if (c.state === 'Cancelled') - return 'Cancelled'; -} - class WBProcessDashboard extends Component { constructor(...args) { super(...args); @@ -85,7 +69,7 @@ class WBProcessDashboard extends Component { }); prom = prom.then(cl => { cl.map(a => (crlist.find(b => (b.container_uuid === a.uuid)).container = a)); - crlist.map(a => (a.wb_state = determineState(a))); + crlist.map(a => (a.wb_state = wbProcessStateName(a, a.container))); const stats = {}; for (let state in { 'Pending': 1, 'Running': 1, 'Complete': 1, 'Failed': 1, 'Cancelled': 1 }) { const f = crlist.filter(a => (a.wb_state === state)); diff --git a/frontend/src/js/misc/wb-process-state-name.js b/frontend/src/js/misc/wb-process-state-name.js new file mode 100644 index 0000000..876d529 --- /dev/null +++ b/frontend/src/js/misc/wb-process-state-name.js @@ -0,0 +1,18 @@ +function wbProcessStateName(containerRequest, container) { + const cr = containerRequest; + const c = container; + if (cr.state !== 'Uncommitted' && cr.priority === 0) + return 'Cancelled'; + if (cr.state === 'Uncommitted' || !c || c.state === 'Queued' || c.state === 'Locked') + return 'Pending'; + if (c.state === 'Running') + return 'Running'; + if (c.state === 'Complete' && c.exit_code === 0) + return 'Complete'; + if (c.state === 'Complete' && c.exit_code !== 0) + return 'Failed'; + if (c.state === 'Cancelled') + return 'Cancelled'; +} + +export default wbProcessStateName;