Skip to content

Commit

Permalink
Display warnings on components (#9108)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMauderer committed Feb 21, 2024
1 parent 9daca28 commit 6c4c791
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 26 deletions.
34 changes: 31 additions & 3 deletions app/gui2/src/components/GraphEditor/GraphNode.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { nodeEditBindings } from '@/bindings'
import CircularMenu from '@/components/CircularMenu.vue'
import GraphNodeError from '@/components/GraphEditor/GraphNodeError.vue'
import GraphNodeError from '@/components/GraphEditor/GraphNodeMessage.vue'
import GraphVisualization from '@/components/GraphEditor/GraphVisualization.vue'
import NodeWidgetTree from '@/components/GraphEditor/NodeWidgetTree.vue'
import SvgIcon from '@/components/SvgIcon.vue'
Expand Down Expand Up @@ -107,6 +107,15 @@ const error = computed(() => {
}
})
const warning = computed(() => {
const externalId = graph.db.idToExternal(nodeId.value)
if (!externalId) return
const info = projectStore.computedValueRegistry.db.get(externalId)
const warning = info?.payload.type === 'Value' ? info.payload.warnings?.value : undefined
if (!warning) return
return '⚠ Warning: ' + warning!
})
const isSelected = computed(() => nodeSelection?.isSelected(nodeId.value) ?? false)
watch(isSelected, (selected) => {
if (!selected) {
Expand Down Expand Up @@ -331,6 +340,8 @@ watchEffect(() => {
}
})
const nodeHovered = ref(false)
function portGroupStyle(port: PortData) {
const [start, end] = port.clipRange
return {
Expand Down Expand Up @@ -368,6 +379,8 @@ function openFullMenu() {
['executionState-' + executionState]: true,
}"
:data-node-id="nodeId"
@pointerenter="nodeHovered = true"
@pointerleave="nodeHovered = false"
>
<div class="selection" v-on="dragPointer.events"></div>
<div class="binding" @pointerdown.stop>
Expand Down Expand Up @@ -409,7 +422,14 @@ function openFullMenu() {
<NodeWidgetTree :ast="displayedExpression" :nodeId="nodeId" />
</div>
</div>
<GraphNodeError v-if="error" class="error" :error="error" />
<GraphNodeError v-if="error" class="message" :message="error" type="error" />
<GraphNodeError
v-if="warning && (nodeHovered || isSelected)"
class="message warning"
:class="menuVisible === MenuState.Off ? '' : 'messageWithMenu'"
:message="warning"
type="warning"
/>
<svg class="bgPaths" :style="bgStyleVariables">
<rect class="bgFill" />
<template v-for="port of outputPorts" :key="port.portId">
Expand Down Expand Up @@ -631,9 +651,17 @@ function openFullMenu() {
z-index: 1;
}
.error {
.message {
position: absolute;
top: 100%;
margin-top: 4px;
}
.messageWithMenu {
left: 40px;
}
.warning {
top: 35px;
}
</style>
23 changes: 0 additions & 23 deletions app/gui2/src/components/GraphEditor/GraphNodeError.vue

This file was deleted.

44 changes: 44 additions & 0 deletions app/gui2/src/components/GraphEditor/GraphNodeMessage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<script setup lang="ts">
/// types of messages
export type GraphNodeMessageType = 'error' | 'warning'
const props = defineProps<{ message: string; type: GraphNodeMessageType }>()
function styleClassForType(type: GraphNodeMessageType) {
switch (type) {
case 'error':
return 'GraphNodeError'
case 'warning':
return 'GraphNodeWarning'
default:
return ''
}
}
</script>

<template>
<div class="GraphNodeMessage" :class="styleClassForType(props.type)" v-text="props.message"></div>
</template>

<style scoped>
.GraphNodeMessage {
display: flex;
height: 24px;
padding: 1px 8px;
align-items: flex-start;
gap: 10px;
font-weight: 800;
white-space: nowrap;
border-radius: var(--radius-full);
color: var(--color-text-inversed);
line-height: 20px;
}
.GraphNodeWarning {
background-color: #faa212;
}
.GraphNodeError {
background-color: #e85252;
}
</style>

0 comments on commit 6c4c791

Please sign in to comment.