Skip to content

Commit

Permalink
Simplify InputOrDisplay.vue component - fixes loading issues when use…
Browse files Browse the repository at this point in the history
…d in Harvester

Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Sep 23, 2024
1 parent d29392f commit afe4811
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions shell/components/InputOrDisplay.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script>
import { h, computed } from 'vue';
import { _VIEW } from '@shell/config/query-params';
export default {
Expand All @@ -18,31 +17,37 @@ export default {
default: 'edit'
}
},
setup(props, { slots }) {
const isView = computed(() => props.mode === _VIEW);
computed: {
isView() {
return this.mode === _VIEW;
},
const displayValue = computed(() => {
if (Array.isArray(props.value) && props.value.length === 0) {
displayValue() {
if (Array.isArray(this.value) && this.value.length === 0) {
return '';
} else {
return props.value;
}
});
return () => {
if (isView.value) {
return h('div', { class: 'label' }, [
h('div', { class: 'text-label' }, slots.name ? slots.name : props.name),
h('div', { class: 'value' }, slots.value ? slots.value : displayValue.value)
]);
} else {
return slots.default;
return this.value;
}
};
}
}
};
</script>

<template>
<div
v-if="isView"
class="label"
>
<div class="text-label">
{{ $slots.name || name }}
</div>
<div class="value">
{{ $slots.value || displayValue }}
</div>
</div>
<slot v-else />
</template>

<style lang="scss" scoped>
.label {
display: flex;
Expand Down

0 comments on commit afe4811

Please sign in to comment.