Skip to content

Commit

Permalink
Fix message chips for task outputs
Browse files Browse the repository at this point in the history
The chip text should be the output, the tooltip should be the message
  • Loading branch information
MetRonnie committed Aug 31, 2023
1 parent 3ea778d commit 88754c8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/services/mock/json/App.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"finishedTime": "2020-11-08T22:57:41Z",
"state": "succeeded",
"submitNum": 4,
"messages": ["started", "foo", "bar", "baz", "pub", "qux", "x", "y"],
"messages": ["started", "foo message", "bar message", "x", "baz message", "pub message", "qux message", "y"],
"taskProxy": {
"outputs": [
{"label": "foo", "message": "foo message"},
Expand All @@ -287,7 +287,7 @@
"finishedTime": "2020-11-08T22:57:25Z",
"state": "failed",
"submitNum": 3,
"messages": ["started", "foo", "failed/ERR"],
"messages": ["started", "foo message", "failed/ERR"],
"taskProxy": {
"outputs": [
{"label": "foo", "message": "foo message"}
Expand Down
28 changes: 9 additions & 19 deletions src/utils/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,20 @@ function latestJob (taskProxy) {
*/
function jobMessageOutputs (jobNode) {
const ret = []
let messageOutput

for (const message of jobNode.node.messages || []) {
if (TASK_OUTPUT_NAMES.includes(message)) {
continue
}
messageOutput = null
for (const output of jobNode.node.taskProxy?.outputs || []) {
if (message === output.label) {
messageOutput = output
break
}
}
if (messageOutput) {
// add an output to the list
ret.push(messageOutput)
} else {
// add a message to the list and make it look like an output
ret.push({
label: message,
message: `Task Message: ${message}`,
isMessage: true
})
}
const messageOutput = jobNode.node.taskProxy?.outputs?.find(
(output) => message === output.message
)
ret.push({
level: undefined, // TODO: https://github.com/cylc/cylc-ui/pull/1436
label: messageOutput?.label ?? message,
message: messageOutput?.message ?? `Task message: ${message}`,
isMessage: !messageOutput,
})
}
return ret
}
Expand Down
41 changes: 40 additions & 1 deletion tests/unit/utils/tasks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import TaskState from '@/model/TaskState.model'
import { dtMean, extractGroupState, latestJob, formatDuration } from '@/utils/tasks'
import { dtMean, extractGroupState, latestJob, formatDuration, jobMessageOutputs } from '@/utils/tasks'

describe('tasks', () => {
describe('extractGroupState', () => {
Expand All @@ -36,6 +36,7 @@ describe('tasks', () => {
expect(groupState).to.equal(val[0])
})
})

it('should return the correct state for the node groups when stopped', () => {
[
[
Expand All @@ -52,10 +53,12 @@ describe('tasks', () => {
expect(groupState).to.equal(val[0])
})
})

it('should return empty when no states provided', () => {
expect(extractGroupState([])).to.equal('')
})
})

describe.each([
{
taskProxy: null,
Expand Down Expand Up @@ -85,6 +88,7 @@ describe('tasks', () => {
expect(latestJob(taskProxy)).to.equal(expected)
})
})

describe('dtMean', () => {
it('should format seconds to nice isodatetime format', () => {
const tests = [
Expand Down Expand Up @@ -146,6 +150,7 @@ describe('tasks', () => {
})
})
})

describe('formatDuration', () => {
it('should format seconds to nice isodatetime format', () => {
expect(formatDuration(null)).to.equal(undefined)
Expand All @@ -168,4 +173,38 @@ describe('tasks', () => {
expect(formatDuration(42, true)).to.equal('00:00:42')
})
})

describe('jobMessageOutputs()', () => {
it('returns expected value for outputs vs ordinary messages', () => {
const jobNode = {
node: {
messages: [
'chilbolton',
'larkhill',
],
taskProxy: {
outputs: [{
label: 'my-output',
message: 'chilbolton',
}]
}
}
}

expect(jobMessageOutputs(jobNode)).toEqual([
{
level: undefined,
label: 'my-output',
message: 'chilbolton',
isMessage: false,
},
{
level: undefined,
label: 'larkhill',
message: 'Task message: larkhill',
isMessage: true,
},
])
})
})
})

0 comments on commit 88754c8

Please sign in to comment.