Browse Source

fix(gui-v2): use ReadonlyInj in date and time pickers since those are in editable state by default

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3169/head
Pranav C 2 years ago
parent
commit
e6611e577c
  1. 10
      packages/nc-gui-v2/components/cell/DatePicker.vue
  2. 9
      packages/nc-gui-v2/components/cell/DateTimePicker.vue
  3. 9
      packages/nc-gui-v2/components/cell/TimePicker.vue
  4. 10
      packages/nc-gui-v2/components/cell/YearPicker.vue
  5. 3
      packages/nc-gui-v2/components/smartsheet/Form.vue
  6. 2
      packages/nc-gui-v2/context/index.ts

10
packages/nc-gui-v2/components/cell/DatePicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts">
import dayjs from 'dayjs'
import { ColumnInj, EditModeInj, computed, inject, ref, watch } from '#imports'
import { ColumnInj, ReadonlyInj, computed, inject, ref, watch } from '#imports'
interface Props {
modelValue?: string | null
@ -12,7 +12,7 @@ const emit = defineEmits(['update:modelValue'])
const columnMeta = inject(ColumnInj, null)!
const editEnabled = inject(EditModeInj)!
const readOnly = inject(ReadonlyInj, false)
let isDateInvalid = $ref(false)
@ -55,7 +55,7 @@ watch(
{ flush: 'post' },
)
const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : editEnabled.value ? 'Select date' : ''))
const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : readOnly ? 'Select date' : ''))
</script>
<template>
@ -65,10 +65,10 @@ const placeholder = computed(() => (isDateInvalid ? 'Invalid date' : editEnabled
class="!w-full px-1"
:format="dateFormat"
:placeholder="placeholder"
:allow-clear="!editEnabled"
:allow-clear="!readOnly"
:input-read-only="true"
:dropdown-class-name="randomClass"
:open="editEnabled ? false : open"
:open="readOnly ? false : open"
@click="open = !open"
>
<template #suffixIcon></template>

9
packages/nc-gui-v2/components/cell/DateTimePicker.vue

@ -1,6 +1,5 @@
<script setup lang="ts">
import dayjs from 'dayjs'
import { EditModeInj } from '~/context'
interface Props {
modelValue: string | null | undefined
@ -12,7 +11,7 @@ const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject()
const editEnabled = inject(EditModeInj)
const readOnly = inject(ReadonlyInj, false)
let isDateInvalid = $ref(false)
@ -64,11 +63,11 @@ watch(
:bordered="false"
class="!w-full px-1"
format="YYYY-MM-DD HH:mm"
:placeholder="isDateInvalid ? 'Invalid date' : !editEnabled ? 'Select date and time' : ''"
:allow-clear="!editEnabled"
:placeholder="isDateInvalid ? 'Invalid date' : !readOnly ? 'Select date and time' : ''"
:allow-clear="!readOnly"
:input-read-only="true"
:dropdown-class-name="randomClass"
:open="editEnabled ? false : open"
:open="readOnly ? false : open"
:disabled="!editEnabled"
@click="open = !open"
@ok="open = !open"

9
packages/nc-gui-v2/components/cell/TimePicker.vue

@ -1,7 +1,6 @@
<script setup lang="ts">
import { onClickOutside } from '@vueuse/core'
import dayjs from 'dayjs'
import { EditModeInj } from '~/context'
interface Props {
modelValue?: string | null | undefined
@ -13,7 +12,7 @@ const emit = defineEmits(['update:modelValue'])
const { isMysql } = useProject()
const editEnabled = inject(EditModeInj)
const readOnly = inject(ReadonlyInj, false)
let isTimeInvalid = $ref(false)
@ -76,10 +75,10 @@ watch(
use12-hours
format="HH:mm"
class="!w-full px-1"
:placeholder="isTimeInvalid ? 'Invalid time' : !readOnlyMode ? 'Select time' : ''"
:allow-clear="!editEnabled"
:placeholder="isTimeInvalid ? 'Invalid time' : !readOnly ? 'Select time' : ''"
:allow-clear="!readOnly"
:input-read-only="true"
:open="editEnabled ? false : open"
:open="readOnly ? false : open"
:popup-class-name="randomClass"
@click="open = !open"
@ok="open = !open"

10
packages/nc-gui-v2/components/cell/YearPicker.vue

@ -1,6 +1,6 @@
<script setup lang="ts">
import dayjs from 'dayjs'
import { EditModeInj, computed, inject, onClickOutside, ref, watch } from '#imports'
import { computed, inject, onClickOutside, ref, watch } from '#imports'
interface Props {
modelValue?: number | string | null
@ -10,7 +10,7 @@ const { modelValue } = defineProps<Props>()
const emit = defineEmits(['update:modelValue'])
const editEnabled = inject(EditModeInj)!
const readOnly = inject(ReadonlyInj, false)
let isYearInvalid = $ref(false)
@ -53,7 +53,7 @@ watch(
{ flush: 'post' },
)
const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : editEnabled.value ? 'Select year' : ''))
const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : readOnly ? 'Select year' : ''))
</script>
<template>
@ -63,9 +63,9 @@ const placeholder = computed(() => (isYearInvalid ? 'Invalid year' : editEnabled
:bordered="false"
class="!w-full px-1"
:placeholder="placeholder"
:allow-clear="!editEnabled"
:allow-clear="!readOnly"
:input-read-only="true"
:open="editEnabled ? false : open"
:open="readOnly ? false : open"
:dropdown-class-name="randomClass"
@click="open = !open"
@change="open = !open"

3
packages/nc-gui-v2/components/smartsheet/Form.vue

@ -5,7 +5,6 @@ import { message } from 'ant-design-vue'
import type { Permission } from '~/composables/useUIPermission/rolePermissions'
import {
ActiveViewInj,
EditModeInj,
IsFormInj,
MetaInj,
computed,
@ -26,8 +25,6 @@ import {
provide(IsFormInj, ref(true))
provide(EditModeInj, ref(true))
// todo: generate hideCols based on default values
const hiddenCols = ['created_at', 'updated_at']

2
packages/nc-gui-v2/context/index.ts

@ -18,7 +18,7 @@ export const IsGridInj: InjectionKey<boolean> = Symbol('is-grid-injection')
export const IsLockedInj: InjectionKey<boolean> = Symbol('is-locked-injection')
export const CellValueInj: InjectionKey<Ref<any>> = Symbol('cell-value-injection')
export const ActiveViewInj: InjectionKey<Ref<ViewType>> = Symbol('active-view-injection')
export const ReadonlyInj: InjectionKey<any> = Symbol('readonly-injection')
export const ReadonlyInj: InjectionKey<boolean> = Symbol('readonly-injection')
export const ReloadViewDataHookInj: InjectionKey<EventHook<void>> = Symbol('reload-view-data-injection')
export const FieldsInj: InjectionKey<Ref<any[]>> = Symbol('fields-injection')
export const ViewListInj: InjectionKey<Ref<ViewType[]>> = Symbol('view-list-injection')

Loading…
Cancel
Save