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

Simplify InputOrDisplay.vue component #12000

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we could have invoked the slot as a function via:

return slots.default();

The same would go for the two slots above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Phil, better to know what the error was, I found another case where we need to update the slots API. #12005

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
Loading