|
11 | 11 | * or submit itself to any jurisdiction.
|
12 | 12 | */
|
13 | 13 |
|
| 14 | +import { RunStatus } from '../../../../../library/runStatus.enum.js'; |
| 15 | +import { spinner } from '../../spinner.js'; |
14 | 16 | import { h } from '/js/src/index.js';
|
15 | 17 |
|
16 | 18 | /**
|
17 |
| - * Render a run mode switch |
18 |
| - * @param {number} runNumber - The run number |
19 |
| - * @param {RunStatus} status - The run status |
20 |
| - * @returns {HTMLElement} - The rendered run status panel |
| 19 | + * Creates and returns a run status panel element displaying the current run number, |
| 20 | + * its status, the last refresh timestamp, and the refresh rate. |
| 21 | + * @param {object} options Options for rendering the run status panel. |
| 22 | + * @param {number} options.runNumber The current run number to display. |
| 23 | + * @param {string} options.runStatus The status of the run (e.g., "running", "completed"). |
| 24 | + * @param {Date} options.lastRefresh Timestamp of the last refresh. |
| 25 | + * @param {number} options.refreshRate - Refresh rate in milliseconds. |
| 26 | + * @returns {vnode} The element representing the run status panel. |
21 | 27 | */
|
22 |
| -export const runStatusPanel = (runNumber, status) => |
23 |
| - status.match({ |
| 28 | +export const runStatusPanel = ({ runNumber, runStatus, lastRefresh, refreshRate = 15000 }) => { |
| 29 | + const runNumberPanel = h('span', { id: 'runNumberLabel' }, [ |
| 30 | + 'Run ', |
| 31 | + h('b', `#${runNumber}`), |
| 32 | + ]); |
| 33 | + const statusPanel = (runStatus) => |
| 34 | + runStatus |
| 35 | + ? h( |
| 36 | + `.badge.white.bg-${runStatus === RunStatus.ONGOING ? 'success' : 'gray-darker'}`, |
| 37 | + { id: 'runStatusBadge' }, |
| 38 | + runStatus, |
| 39 | + ) |
| 40 | + : h('span', spinner(1)); |
| 41 | + const formatDateTime = (dateStr) => |
| 42 | + new Date(dateStr).toLocaleString('en-GB'); // dd/mm/yyyy, hh:mm:ss |
| 43 | + |
| 44 | + const lastUpdatePanel = (runStatus) => [ |
| 45 | + h( |
| 46 | + 'span.highlight', |
| 47 | + { id: 'lastUpdate' }, |
| 48 | + `Last update: ${formatDateTime(lastRefresh)}`, |
| 49 | + ), |
| 50 | + runStatus === RunStatus.ONGOING && |
| 51 | + h( |
| 52 | + 'span', |
| 53 | + { id: 'refreshInfo' }, |
| 54 | + ` - As run is ONGOING, will refresh every ${refreshRate / 1000} seconds`, |
| 55 | + ), |
| 56 | + ]; |
| 57 | + |
| 58 | + return runStatus.match({ |
24 | 59 | Loading: () =>
|
25 | 60 | h('.flex-row.g1.items-center.justify-center', [
|
26 |
| - h('b', { id: 'runNumberLabel' }, `#${runNumber}`), |
27 |
| - h('.flex-row.g1', [ |
28 |
| - h('label', 'Status: '), |
29 |
| - h('b.color-gray', 'Loading...'), |
30 |
| - ]), |
| 61 | + runNumberPanel, |
| 62 | + statusPanel(null), |
31 | 63 | ]),
|
32 | 64 |
|
33 |
| - Success: (res) => |
34 |
| - h('.flex-row.g1.items-center.justify-center', { id: 'runStatusPanel' }, [ |
35 |
| - h('b', { id: 'runNumberLabel' }, `#${runNumber}`), |
36 |
| - h('.flex-row.g1', [ |
37 |
| - h('span', 'Status: '), |
38 |
| - h( |
39 |
| - `b.${ |
40 |
| - res?.runStatus === 'ONGOING' ? 'success' : 'gray' |
41 |
| - }`, |
42 |
| - { |
43 |
| - id: 'runStatus', |
44 |
| - }, |
45 |
| - res?.runStatus, |
46 |
| - ), |
| 65 | + Success: (res) => { |
| 66 | + const runStatus = res?.runStatus; |
| 67 | + const shouldShowTimestamp = runStatus === RunStatus.ONGOING || runStatus === RunStatus.ENDED; |
| 68 | + return h('.flex-column', [ |
| 69 | + h('.flex-row.g1.items-center.justify-center', { id: 'runStatusPanel' }, [ |
| 70 | + runNumberPanel, |
| 71 | + statusPanel(runStatus), |
47 | 72 | ]),
|
48 |
| - ]), |
| 73 | + shouldShowTimestamp && h( |
| 74 | + '.flex-row.g1.items-center.justify-center.f7.gray-darker.text-center', |
| 75 | + lastUpdatePanel(runStatus), |
| 76 | + ), |
| 77 | + ]); |
| 78 | + }, |
49 | 79 | Other: () => null,
|
50 | 80 | });
|
| 81 | +}; |
0 commit comments