Skip to content

Commit

Permalink
fix(client):improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
konata33 committed Feb 6, 2024
1 parent a055bfe commit d1a9d7c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const props = withDefaults(defineProps<{
depth: number
showAddIfNeeded?: boolean
disableEdit?: boolean
disableDelete?: boolean
rootId: string
}>(), {
showAddIfNeeded: true,
Expand Down Expand Up @@ -119,7 +120,7 @@ function quickEditNum(v: number | string, offset: 1 | -1) {
</template>
</template>
<!-- delete prop, only appear if depth > 0 -->
<VueButton v-if="!props.disableEdit && depth > 0 && props.rootId !== 'getters'" v-bind="iconButtonProps" :class="buttonClass" @click.stop="quickEdit(rawValue, true)">
<VueButton v-if="!props.disableEdit && !props.disableDelete && depth > 0" v-bind="iconButtonProps" :class="buttonClass" @click.stop="quickEdit(rawValue, true)">
<template #icon>
<VueIcon icon="i-material-symbols-delete-rounded" />
</template>
Expand Down
4 changes: 4 additions & 0 deletions packages/client/src/components/inspector/InspectorState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ const props = withDefaults(defineProps<{
nodeId: string
inspectorId: string
disableEdit?: boolean
disableDelete?: boolean
}>(), {
disableEdit: false,
})
const undeletableIds = ['getters']
const { isExpanded, toggleCollapse } = useCollapse('inspector-state', props.id)
// expand the root node by default
!isExpanded.value && toggleCollapse()
Expand All @@ -21,6 +24,7 @@ createStateEditorContext({
nodeId: props.nodeId!,
inspectorId: props.inspectorId!,
disableEdit: props.disableEdit,
disableDelete: undeletableIds.includes(props.id),
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const { isHovering } = useHover(() => containerRef.value)
<span v-html="normalizedValue" />
</span>
<Actions
:hovering="isHovering" :disable-edit="state.disableEdit" :root-id="rootId"
:hovering="isHovering" :disable-edit="state.disableEdit" :root-id="rootId" :disable-delete="state.disableDelete"
:data="data" :depth="depth" @enable-edit-input="toggleEditing"
@add-new-prop="addNewProp"
/>
Expand All @@ -201,7 +201,7 @@ const { isHovering } = useHover(() => containerRef.value)
</span>
<Actions
:show-add-if-needed="!draftingNewProp.enable" :root-id="rootId"
:hovering="isHovering" :data="data" :disable-edit="state.disableEdit"
:hovering="isHovering" :data="data" :disable-edit="state.disableEdit" :disable-delete="state.disableDelete"
:depth="depth" @enable-edit-input="toggleEditing" @add-new-prop="addNewProp"
/>
</template>
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/composables/inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface StateEditorContext {
nodeId: string
inspectorId: string
disableEdit: boolean
disableDelete: boolean
}
const StateEditorSymbolKey: InjectionKey<Ref<StateEditorContext>> = Symbol('StateEditorSymbol')

Expand Down

0 comments on commit d1a9d7c

Please sign in to comment.