-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathWarningIcon.vue
More file actions
144 lines (125 loc) · 3.34 KB
/
WarningIcon.vue
File metadata and controls
144 lines (125 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!--
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/>.
-->
<!--
WarningIcon - A dismiss-able warning icon
states:
* no warnings: grey + translucent
* new warnings: yellow
* warnings dismissed: grey
-->
<template>
<span
class="c-warn d-inline-flex"
:class="{'active': workflow.node.warningActive}"
>
<v-tooltip
:activator="null"
location="bottom"
:disabled="!workflow.node.logRecords?.length"
:open-delay="400"
>
<template
v-slot:activator="{ props }"
>
<!-- NOTE: the click.prevent suppresses router navigation -->
<svg
viewBox="0 0 100 100"
v-bind="props"
@click="deactivate"
@click.prevent
style="
cursor: pointer;
"
:style="[workflow.node.logRecords?.length ? {opacity: 1} : {opacity: 0.3}]"
>
<path
:d="$options.path"
:stroke-width="$options.strokeWidth"
v-bind:class="{'active': workflow.node.warningActive}"
/>
</svg>
</template>
Recent warnings (click to dismiss):
<table>
<tr
v-for="(event, index) in (workflow.node.logRecords || []).slice().reverse()"
:key="index"
>
<td style="padding-right: 0.5em; vertical-align: top;">
<EventChip :level="event.level" />
</td><td>
<span class="truncated-message">{{ event.message }}</span>
</td>
</tr>
</table>
</v-tooltip>
</span>
</template>
<script>
import EventChip from '@/components/cylc/EventChip.vue'
import { store } from '@/store/index'
/* stuff we want to do once, when the component is loaded, rather than
* every time it is used. */
// stroke
const sw = 10 // stroke width
const hsw = sw / 2 // half stroke width
// bounding box
const x1 = 2
const x2 = 98
const y1 = 8
const y2 = 92
// path commands
const PATH = pathJoin([
['M', x1 + sw, y1 + hsw],
['L', x2 - sw, y1 + hsw],
['L', ((x2 - x1) / 2) + x1, y2 - sw],
['L', x1 + sw, y1 + hsw],
['Z', '', '']
])
function nodeJoin (item) {
return `${item[0]}${item.slice(1).join(' ')}`
}
function pathJoin (list) {
return list.reduce((ret, item, ind) => {
if (ind === 1) {
ret = nodeJoin(ret)
}
return `${ret} ${nodeJoin(item)}`
})
}
export default {
name: 'WarningIcon',
components: {
EventChip,
},
props: {
workflow: {
required: true,
}
},
methods: {
deactivate () {
store.commit('workflows/UPDATE', { id: this.workflow.id, warningActive: false })
},
},
strokeWidth: sw,
path: PATH,
}
</script>
<style lang="scss" scoped>
@use "/src/styles/util";
.truncated-message {
@include util.line-clamp(2);
}
</style>