Browse Source

fix: RowHeighInj for sharing row height between components

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5015/head
mertmit 2 years ago
parent
commit
b9f9d956bf
  1. 24
      packages/nc-gui/components/cell/TextArea.vue
  2. 37
      packages/nc-gui/components/smartsheet/Grid.vue
  3. 25
      packages/nc-gui/components/virtual-cell/QrCode.vue
  4. 36
      packages/nc-gui/components/virtual-cell/barcode/Barcode.vue
  5. 1
      packages/nc-gui/context/index.ts

24
packages/nc-gui/components/cell/TextArea.vue

@ -1,7 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { GridType } from 'nocodb-sdk'
import type { VNodeRef } from '@vue/runtime-core' import type { VNodeRef } from '@vue/runtime-core'
import { ActiveViewInj, EditModeInj, inject, useVModel } from '#imports' import { EditModeInj, RowHeightInj, inject, useVModel } from '#imports'
const props = defineProps<{ const props = defineProps<{
modelValue?: string | number modelValue?: string | number
@ -11,30 +10,13 @@ const emits = defineEmits(['update:modelValue'])
const editEnabled = inject(EditModeInj) const editEnabled = inject(EditModeInj)
const { showNull } = useGlobal() const rowHeight = inject(RowHeightInj)
const view = inject(ActiveViewInj, ref()) const { showNull } = useGlobal()
const vModel = useVModel(props, 'modelValue', emits, { defaultValue: '' }) const vModel = useVModel(props, 'modelValue', emits, { defaultValue: '' })
const focus: VNodeRef = (el) => (el as HTMLTextAreaElement)?.focus() const focus: VNodeRef = (el) => (el as HTMLTextAreaElement)?.focus()
const rowHeight = computed(() => {
if ((view.value?.view as GridType)?.row_height !== undefined) {
switch ((view.value?.view as GridType)?.row_height) {
case 0:
return 1
case 1:
return 2
case 2:
return 4
case 3:
return 6
default:
return 1
}
}
})
</script> </script>
<template> <template>

37
packages/nc-gui/components/smartsheet/Grid.vue

@ -17,6 +17,7 @@ import {
ReadonlyInj, ReadonlyInj,
ReloadRowDataHookInj, ReloadRowDataHookInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
RowHeightInj,
SmartsheetStoreEvents, SmartsheetStoreEvents,
computed, computed,
createEventHook, createEventHook,
@ -362,6 +363,23 @@ function scrollToCell(row?: number | null, col?: number | null) {
} }
} }
const rowHeight = computed(() => {
if ((view.value?.view as GridType)?.row_height !== undefined) {
switch ((view.value?.view as GridType)?.row_height) {
case 0:
return 1
case 1:
return 2
case 2:
return 4
case 3:
return 6
default:
return 1
}
}
})
onMounted(loadGridViewColumns) onMounted(loadGridViewColumns)
provide(IsFormInj, ref(false)) provide(IsFormInj, ref(false))
@ -374,6 +392,8 @@ provide(PaginationDataInj, paginationData)
provide(ChangePageInj, changePage) provide(ChangePageInj, changePage)
provide(RowHeightInj, rowHeight)
const disableUrlOverlay = ref(false) const disableUrlOverlay = ref(false)
provide(CellUrlDisableOverlayInj, disableUrlOverlay) provide(CellUrlDisableOverlayInj, disableUrlOverlay)
@ -672,23 +692,6 @@ const closeAddColumnDropdown = () => {
columnOrder.value = null columnOrder.value = null
addColumnDropdown.value = false addColumnDropdown.value = false
} }
const rowHeight = computed(() => {
if ((view.value?.view as GridType)?.row_height !== undefined) {
switch ((view.value?.view as GridType)?.row_height) {
case 0:
return 1
case 1:
return 2
case 2:
return 4
case 3:
return 6
default:
return 1
}
}
})
</script> </script>
<template> <template>

25
packages/nc-gui/components/virtual-cell/QrCode.vue

@ -1,12 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import { useQRCode } from '@vueuse/integrations/useQRCode' import { useQRCode } from '@vueuse/integrations/useQRCode'
import type { GridType } from 'nocodb-sdk' import { RowHeightInj } from '#imports'
import { ActiveViewInj } from '#imports'
const maxNumberOfAllowedCharsForQrValue = 2000 const maxNumberOfAllowedCharsForQrValue = 2000
const view = inject(ActiveViewInj, ref())
const cellValue = inject(CellValueInj) const cellValue = inject(CellValueInj)
const qrValue = computed(() => String(cellValue?.value)) const qrValue = computed(() => String(cellValue?.value))
@ -15,22 +12,7 @@ const tooManyCharsForQrCode = computed(() => qrValue?.value.length > maxNumberOf
const showQrCode = computed(() => qrValue?.value?.length > 0 && !tooManyCharsForQrCode.value) const showQrCode = computed(() => qrValue?.value?.length > 0 && !tooManyCharsForQrCode.value)
const rowHeight = computed(() => { const rowHeight = inject(RowHeightInj)
if ((view.value?.view as GridType)?.row_height !== undefined) {
switch ((view.value?.view as GridType)?.row_height) {
case 0:
return 1
case 1:
return 2
case 2:
return 4
case 3:
return 6
default:
return 1
}
}
})
const qrCode = useQRCode(qrValue, { const qrCode = useQRCode(qrValue, {
width: 150, width: 150,
@ -69,13 +51,14 @@ const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = us
{{ $t('labels.qrCodeValueTooLong') }} {{ $t('labels.qrCodeValueTooLong') }}
</div> </div>
<img <img
v-if="showQrCode" v-if="showQrCode && rowHeight"
class="mx-auto" class="mx-auto"
:style="{ height: rowHeight ? `${rowHeight * 1.4}rem` : `1.4rem` }" :style="{ height: rowHeight ? `${rowHeight * 1.4}rem` : `1.4rem` }"
:src="qrCode" :src="qrCode"
alt="QR Code" alt="QR Code"
@click="showQrModal" @click="showQrModal"
/> />
<img v-else-if="showQrCode" class="mx-auto" :src="qrCode" alt="QR Code" @click="showQrModal" />
<div v-if="showEditNonEditableFieldWarning" class="text-left text-wrap mt-2 text-[#e65100] text-xs"> <div v-if="showEditNonEditableFieldWarning" class="text-left text-wrap mt-2 text-[#e65100] text-xs">
{{ $t('msg.warning.nonEditableFields.computedFieldUnableToClear') }} {{ $t('msg.warning.nonEditableFields.computedFieldUnableToClear') }}
</div> </div>

36
packages/nc-gui/components/virtual-cell/barcode/Barcode.vue

@ -1,13 +1,10 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ComputedRef } from 'vue' import type { ComputedRef } from 'vue'
import type { GridType } from 'nocodb-sdk'
import JsBarcodeWrapper from './JsBarcodeWrapper.vue' import JsBarcodeWrapper from './JsBarcodeWrapper.vue'
import { ActiveViewInj } from '#imports' import { RowHeightInj } from '#imports'
const maxNumberOfAllowedCharsForBarcodeValue = 100 const maxNumberOfAllowedCharsForBarcodeValue = 100
const view = inject(ActiveViewInj, ref())
const cellValue = inject(CellValueInj) const cellValue = inject(CellValueInj)
const column = inject(ColumnInj) const column = inject(ColumnInj)
@ -35,22 +32,7 @@ const showBarcode = computed(() => barcodeValue?.value.length > 0 && !tooManyCha
const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = useShowNotEditableWarning() const { showEditNonEditableFieldWarning, showClearNonEditableFieldWarning } = useShowNotEditableWarning()
const rowHeight = computed(() => { const rowHeight = inject(RowHeightInj)
if ((view.value?.view as GridType)?.row_height !== undefined) {
switch ((view.value?.view as GridType)?.row_height) {
case 0:
return 1
case 1:
return 2
case 2:
return 4
case 3:
return 6
default:
return 1
}
}
})
</script> </script>
<template> <template>
@ -65,7 +47,7 @@ const rowHeight = computed(() => {
<JsBarcodeWrapper v-if="showBarcode" :barcode-value="barcodeValue" :barcode-format="barcodeMeta.barcodeFormat" /> <JsBarcodeWrapper v-if="showBarcode" :barcode-value="barcodeValue" :barcode-format="barcodeMeta.barcodeFormat" />
</a-modal> </a-modal>
<JsBarcodeWrapper <JsBarcodeWrapper
v-if="showBarcode" v-if="showBarcode && rowHeight"
:barcode-value="barcodeValue" :barcode-value="barcodeValue"
:barcode-format="barcodeMeta.barcodeFormat" :barcode-format="barcodeMeta.barcodeFormat"
:custom-style="{ height: rowHeight ? `${rowHeight * 1.4}rem` : `1.4rem` }" :custom-style="{ height: rowHeight ? `${rowHeight * 1.4}rem` : `1.4rem` }"
@ -77,6 +59,18 @@ const rowHeight = computed(() => {
</div> </div>
</template> </template>
</JsBarcodeWrapper> </JsBarcodeWrapper>
<JsBarcodeWrapper
v-else-if="showBarcode"
:barcode-value="barcodeValue"
:barcode-format="barcodeMeta.barcodeFormat"
@on-click-barcode="showBarcodeModal"
>
<template #barcodeRenderError>
<div class="text-left text-wrap mt-2 text-[#e65100] text-xs" data-testid="barcode-invalid-input-message">
{{ $t('msg.warning.barcode.renderError') }}
</div>
</template>
</JsBarcodeWrapper>
<div v-if="tooManyCharsForBarcode" class="text-left text-wrap mt-2 text-[#e65100] text-xs"> <div v-if="tooManyCharsForBarcode" class="text-left text-wrap mt-2 text-[#e65100] text-xs">
{{ $t('labels.barcodeValueTooLong') }} {{ $t('labels.barcodeValueTooLong') }}

1
packages/nc-gui/context/index.ts

@ -21,6 +21,7 @@ export const IsLockedInj: InjectionKey<Ref<boolean>> = Symbol('is-locked-injecti
export const CellValueInj: InjectionKey<Ref<any>> = Symbol('cell-value-injection') export const CellValueInj: InjectionKey<Ref<any>> = Symbol('cell-value-injection')
export const ActiveViewInj: InjectionKey<Ref<ViewType>> = Symbol('active-view-injection') export const ActiveViewInj: InjectionKey<Ref<ViewType>> = Symbol('active-view-injection')
export const ReadonlyInj: InjectionKey<Ref<boolean>> = Symbol('readonly-injection') export const ReadonlyInj: InjectionKey<Ref<boolean>> = Symbol('readonly-injection')
export const RowHeightInj: InjectionKey<ComputedRef<1 | 2 | 4 | 6 | undefined>> = Symbol('row-height-injection')
/** when bool is passed, it indicates if a loading spinner should be visible while reloading */ /** when bool is passed, it indicates if a loading spinner should be visible while reloading */
export const ReloadViewDataHookInj: InjectionKey<EventHook<boolean | void>> = Symbol('reload-view-data-injection') export const ReloadViewDataHookInj: InjectionKey<EventHook<boolean | void>> = Symbol('reload-view-data-injection')
export const ReloadViewMetaHookInj: InjectionKey<EventHook<boolean | void>> = Symbol('reload-view-meta-injection') export const ReloadViewMetaHookInj: InjectionKey<EventHook<boolean | void>> = Symbol('reload-view-meta-injection')

Loading…
Cancel
Save