Skip to content

Commit

Permalink
perf: view type automatic synchronization between edit and list for c…
Browse files Browse the repository at this point in the history
…omplex type
  • Loading branch information
tiny-craft committed Mar 26, 2024
1 parent 6686204 commit d1958a3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 19 deletions.
9 changes: 6 additions & 3 deletions frontend/src/components/content_value/ContentEntryEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import WindowClose from '@/components/icons/WindowClose.vue'
import Pin from '@/components/icons/Pin.vue'
import OffScreen from '@/components/icons/OffScreen.vue'
import ContentEditor from '@/components/content_value/ContentEditor.vue'
import { toString } from 'lodash'
import { isEmpty, toString } from 'lodash'
const props = defineProps({
keyPath: String,
show: {
type: Boolean,
},
Expand Down Expand Up @@ -58,8 +59,8 @@ const emit = defineEmits([
watchEffect(
() => {
if (props.show && props.value != null) {
onFormatChanged()
if (props.show && !isEmpty(props.keyPath)) {
onFormatChanged(props.decode, props.format)
} else {
viewAs.value = ''
}
Expand Down Expand Up @@ -127,6 +128,8 @@ const onFormatChanged = async (decode = null, format = null) => {
editingContent.value = viewAs.value = value
viewAs.decode = decode || retDecode
viewAs.format = format || retFormat
emit('update:decode', viewAs.decode)
emit('update:format', viewAs.format)
} finally {
loading.value = false
}
Expand Down
16 changes: 11 additions & 5 deletions frontend/src/components/content_value/ContentValueHash.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, h, reactive, ref } from 'vue'
import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui'
Expand Down Expand Up @@ -142,6 +142,8 @@ const startEdit = async (no, key, value) => {
currentEditRow.no = no
currentEditRow.key = key
currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
}
const saveEdit = async (field, value, decode, format) => {
Expand Down Expand Up @@ -183,8 +185,11 @@ const resetEdit = () => {
currentEditRow.no = 0
currentEditRow.key = ''
currentEditRow.value = null
currentEditRow.format = formatTypes.RAW
currentEditRow.decode = decodeTypes.NONE
if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
// currentEditRow.format = formatTypes.RAW
// currentEditRow.decode = decodeTypes.NONE
}
const actionColumn = {
Expand Down Expand Up @@ -397,11 +402,12 @@ defineExpose({
class="entry-editor-container flex-item-expand"
style="width: 100%">
<content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.key"
:field-label="$t('common.field')"
:format="currentEditRow.format"
:key-path="props.keyPath"
:show="inEdit"
:value="currentEditRow.value"
:value-label="$t('common.value')"
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/content_value/ContentValueList.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, h, reactive, ref } from 'vue'
import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui'
Expand Down Expand Up @@ -116,6 +116,8 @@ const valueColumn = computed(() => ({
const startEdit = async (no, value) => {
currentEditRow.no = no
currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
}
/**
Expand Down Expand Up @@ -160,6 +162,9 @@ const saveEdit = async (pos, value, decode, format) => {
const resetEdit = () => {
currentEditRow.no = 0
currentEditRow.value = null
if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
}
const actionColumn = {
Expand Down Expand Up @@ -370,12 +375,13 @@ defineExpose({
class="entry-editor-container flex-item-expand"
style="width: 100%">
<content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.no"
:field-label="$t('common.index')"
:field-readonly="true"
:format="currentEditRow.format"
:key-path="props.keyPath"
:show="inEdit"
:value="currentEditRow.value"
:value-label="$t('common.value')"
Expand Down
12 changes: 9 additions & 3 deletions frontend/src/components/content_value/ContentValueSet.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, h, reactive, ref } from 'vue'
import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui'
Expand Down Expand Up @@ -115,6 +115,8 @@ const valueColumn = computed(() => ({
const startEdit = async (no, value) => {
currentEditRow.no = no
currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
}
/**
Expand Down Expand Up @@ -157,6 +159,9 @@ const saveEdit = async (pos, value, decode, format) => {
const resetEdit = () => {
currentEditRow.no = 0
currentEditRow.value = null
if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
}
const actionColumn = {
Expand Down Expand Up @@ -367,12 +372,13 @@ defineExpose({
class="entry-editor-container flex-item-expand"
style="width: 100%">
<content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.no"
:field-label="$t('common.index')"
:field-readonly="true"
:format="currentEditRow.format"
:key-path="props.keyPath"
:show="inEdit"
:value="currentEditRow.value"
:value-label="$t('common.value')"
Expand Down
14 changes: 9 additions & 5 deletions frontend/src/components/content_value/ContentValueZSet.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, h, reactive, ref } from 'vue'
import { computed, h, nextTick, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import AddLink from '@/components/icons/AddLink.vue'
import { NButton, NIcon, useThemeVars } from 'naive-ui'
Expand Down Expand Up @@ -166,6 +166,8 @@ const startEdit = async (no, score, value) => {
currentEditRow.no = no
currentEditRow.score = score
currentEditRow.value = value
currentEditRow.decode = props.decode
currentEditRow.format = props.format
}
const saveEdit = async (field, value, decode, format) => {
Expand Down Expand Up @@ -204,8 +206,9 @@ const resetEdit = () => {
currentEditRow.no = 0
currentEditRow.score = 0
currentEditRow.value = null
currentEditRow.format = formatTypes.RAW
currentEditRow.decode = decodeTypes.NONE
if (currentEditRow.format !== props.format || currentEditRow.decode !== props.decode) {
nextTick(() => onFormatChanged(currentEditRow.decode, currentEditRow.format))
}
}
const actionColumn = {
Expand Down Expand Up @@ -403,11 +406,12 @@ defineExpose({
class="entry-editor-container flex-item-expand"
style="width: 100%">
<content-entry-editor
v-model:decode="currentEditRow.decode"
v-model:format="currentEditRow.format"
v-model:fullscreen="fullEdit"
:decode="currentEditRow.decode"
:field="currentEditRow.score"
:field-label="$t('common.score')"
:format="currentEditRow.format"
:key-path="props.keyPath"
:show="inEdit"
:value="currentEditRow.value"
:value-label="$t('common.value')"
Expand Down

0 comments on commit d1958a3

Please sign in to comment.