Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature color cylc message bubbles #1436

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
48 changes: 48 additions & 0 deletions cypress/component/viewMessageChip.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (C) NIWA & British Crown (Met Office) & Contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import MessageChip from '@/components/cylc/MessageChip.vue'

describe('View MessageChip Component', () => {
const mountMessageChip = (props) => {
cy.vmount(
MessageChip,
{
props
}
).as('wrapper')
// add the classes Vuetify requires
cy.addVuetifyStyles(cy)
}

it('checks messageChip colors', () => {
// mount the toolbar with a couple of controls
mountMessageChip(
{
level: 'this is a debug message',
message: 'Task Message :this is a debug message',
isMessage: true
}
)

// are the messages the correct colours?
cy
.get('.v-chip')
.should('have.class', 'bg-blue')
.contains('this is a debug message')
})
})
56 changes: 56 additions & 0 deletions src/components/cylc/MessageChip.vue
MetRonnie marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!--
Copyright (C) NIWA & British Crown (Met Office) & Contributors.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div>
<v-tooltip :activator="null">
<template v-slot:activator="{ props }">
<v-chip
v-bind="props"
:class="chipClass"
class="ml-2 message-output"
size="small"
>
{{ level }}
</v-chip>
</template>
<span>{{ message }}</span>
</v-tooltip>
</div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
level: String,
message: String,
isMessage: Boolean
})

const classMap = new Map([

Check warning on line 44 in src/components/cylc/MessageChip.vue

View check run for this annotation

Codecov / codecov/patch

src/components/cylc/MessageChip.vue#L44

Added line #L44 was not covered by tests
['DEBUG', ''],
['INFO', 'bg-grey'],
['WARNING', 'bg-warning'],
['ERROR', 'bg-error'],
['CRITICAL', 'bg-black font-weight-bold'],
])

const chipClass = computed(() => (

Check warning on line 52 in src/components/cylc/MessageChip.vue

View check run for this annotation

Codecov / codecov/patch

src/components/cylc/MessageChip.vue#L52

Added line #L52 was not covered by tests
classMap.get(props.level) ?? (props.isMessage ? 'bg-grey-lighten-5' : 'bg-grey')
))

</script>
26 changes: 10 additions & 16 deletions src/components/cylc/tree/TreeItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,29 +115,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
prefix).
@see https://github.com/cylc/cylc-ui/pull/530#issuecomment-781076619
-->
<v-tooltip
<MessageChip
v-for="(customOutput, index) of [...jobMessageOutputs].slice(0, 5)"
:key="`output-chip-${index}`"
:activator="null"
>
<template v-slot:activator="{ props }">
<v-chip
v-bind="props"
:class="customOutput.isMessage ? 'bg-light-grey text-black' : 'bg-grey text-white'"
class="ml-2 message-output"
size="small"
>
{{ customOutput.label }}
</v-chip>
</template>
<span>{{ customOutput.message }}</span>
</v-tooltip>
:level="customOutput.level"
:message="customOutput.message"
:isMessage="customOutput.isMessage"
location="bottom">
</MessageChip>
<v-chip
v-if="jobMessageOutputs.length > 5"
class="ml-2 bg-grey text-white"
size="small"
link
@click="toggleExpandCollapse"
data-cy="chip-overflow"
>
+{{ jobMessageOutputs.length - 5 }}
</v-chip>
Expand Down Expand Up @@ -229,6 +221,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { mdiChevronRight } from '@mdi/js'
import Task from '@/components/cylc/Task.vue'
import Job from '@/components/cylc/Job.vue'
import MessageChip from '@/components/cylc/MessageChip.vue'
import { WorkflowState } from '@/model/WorkflowState.model'
import {
formatDuration,
Expand Down Expand Up @@ -261,7 +254,8 @@ export default {

components: {
Task,
Job
Job,
MessageChip
},

props: {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
const ret = []
let messageOutput

for (const message of jobNode.node.messages || []) {
for (const messageString of jobNode.node.messages || []) {
const [level, message] = messageString.split(':')

Check warning on line 75 in src/utils/tasks.js

View check run for this annotation

Codecov / codecov/patch

src/utils/tasks.js#L75

Added line #L75 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately as Oliver pointed out to me, we can't use String.split() as there could be multiple colons after the first severity level one. We'll have to use a regex here, I think something like

/^(?:(DEBUG|INFO|WARNING|ERROR|CRITICAL):)?(.*)/

if (TASK_OUTPUT_NAMES.includes(message)) {
continue
}
Expand All @@ -88,6 +89,7 @@
} else {
// add a message to the list and make it look like an output
ret.push({
level,
label: message,
message: `Task Message: ${message}`,
isMessage: true
Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/specs/tree.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,16 @@ describe('Tree view', () => {
.should('be.visible')

// the first job should have 5 outputs (the maximum number we display)
.first()
.first().as('firstJobNode')
.find('.message-output')
.should('have.length', 5)

// the remainder should be referenced in an overflow counter +2
.parent()
.get('@firstJobNode')
.find('[data-cy=chip-overflow]')
.contains('+2')
.parent()
.parent()
.parent()
.parent()
.parents('.treeitem')
.first()

// expand the job details node
.find('.node-expand-collapse-button')
Expand Down
Loading