Browse Source

fix(nc-gui): pr review changes

pull/7729/head
Ramesh Mane 9 months ago
parent
commit
fdd9c2be68
  1. 10
      packages/nc-gui/components/cell/MultiSelect.vue
  2. 8
      packages/nc-gui/components/cell/SingleSelect.vue
  3. 41
      packages/nc-gui/components/cell/User.vue
  4. 8
      packages/nc-gui/components/general/ImageCropper.vue
  5. 9
      packages/nc-gui/components/smartsheet/Form.vue
  6. 18
      packages/nc-gui/components/smartsheet/form/LimitOptions.vue
  7. 2
      packages/nc-gui/utils/parseUtils.ts

10
packages/nc-gui/components/cell/MultiSelect.vue

@ -100,7 +100,7 @@ const options = computed<(SelectOptionType & { value?: string })[]>(() => {
const limitOptionsById = const limitOptionsById =
((parseProp(column.value.meta)?.limitOptions || []).reduce( ((parseProp(column.value.meta)?.limitOptions || []).reduce(
(o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => { (o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => {
if (f?.order !== undefined && order < f.order) { if (order < (f?.order ?? 0)) {
order = f.order order = f.order
} }
return { return {
@ -118,18 +118,18 @@ const options = computed<(SelectOptionType & { value?: string })[]>(() => {
(parseProp(column.value.meta)?.limitOptions || []).length (parseProp(column.value.meta)?.limitOptions || []).length
) { ) {
return opts return opts
?.filter((o: SelectOptionType) => { .filter((o: SelectOptionType) => {
if (limitOptionsById[o.id!]?.show !== undefined) { if (limitOptionsById[o.id!]?.show !== undefined) {
return limitOptionsById[o.id!]?.show return limitOptionsById[o.id!]?.show
} }
return false return false
}) })
?.map((o) => ({ .map((o) => ({
...o, ...o,
value: o.title, value: o.title,
order: o.id && limitOptionsById[o.id] ? limitOptionsById[o.id]?.order : order++, order: o.id && limitOptionsById[o.id] ? limitOptionsById[o.id]?.order : order++,
})) }))
?.sort((a, b) => a.order - b.order) .sort((a, b) => a.order - b.order)
} else { } else {
return opts.map((o: SelectOptionType) => ({ ...o, value: o.title })) return opts.map((o: SelectOptionType) => ({ ...o, value: o.title }))
} }
@ -390,7 +390,7 @@ const onFocus = () => {
<template> <template>
<div <div
class="nc-cell-field nc-multi-select h-full w-full flex items-center" class="nc-cell-field nc-multi-select h-full w-full flex items-center"
:class="{ 'read-only': readOnly, readOnly, 'max-w-full': isForm }" :class="{ 'read-only': readOnly, 'max-w-full': isForm }"
@click="toggleMenu" @click="toggleMenu"
> >
<div v-if="!isEditColumn && isForm && parseProp(column.meta)?.isList" class="w-full max-w-full"> <div v-if="!isEditColumn && isForm && parseProp(column.meta)?.isList" class="w-full max-w-full">

8
packages/nc-gui/components/cell/SingleSelect.vue

@ -94,7 +94,7 @@ const options = computed<(SelectOptionType & { value: string })[]>(() => {
const limitOptionsById = const limitOptionsById =
((parseProp(column.value.meta)?.limitOptions || []).reduce( ((parseProp(column.value.meta)?.limitOptions || []).reduce(
(o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => { (o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => {
if (f?.order !== undefined && order < f.order) { if (order < (f?.order ?? 0)) {
order = f.order order = f.order
} }
return { return {
@ -112,18 +112,18 @@ const options = computed<(SelectOptionType & { value: string })[]>(() => {
(parseProp(column.value.meta)?.limitOptions || []).length (parseProp(column.value.meta)?.limitOptions || []).length
) { ) {
return opts return opts
?.filter((o: any) => { .filter((o: SelectOptionType & { value: string }) => {
if (limitOptionsById[o.id]?.show !== undefined) { if (limitOptionsById[o.id]?.show !== undefined) {
return limitOptionsById[o.id]?.show return limitOptionsById[o.id]?.show
} }
return false return false
}) })
?.map((o: any) => ({ .map((o: any) => ({
...o, ...o,
value: o.title, value: o.title,
order: o.id && limitOptionsById[o.id] ? limitOptionsById[o.id]?.order : order++, order: o.id && limitOptionsById[o.id] ? limitOptionsById[o.id]?.order : order++,
})) }))
?.sort((a, b) => a.order - b.order) .sort((a, b) => a.order - b.order)
} else { } else {
return opts.map((o: any) => ({ ...o, value: o.title })) return opts.map((o: any) => ({ ...o, value: o.title }))
} }

41
packages/nc-gui/components/cell/User.vue

@ -83,7 +83,7 @@ const options = computed<UserFieldRecordType[]>(() => {
const limitOptionsById = const limitOptionsById =
((parseProp(column.value.meta)?.limitOptions || []).reduce( ((parseProp(column.value.meta)?.limitOptions || []).reduce(
(o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => { (o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => {
if (f?.order !== undefined && order < f.order) { if (order < (f?.order ?? 0)) {
order = f.order order = f.order
} }
return { return {
@ -103,34 +103,33 @@ const options = computed<UserFieldRecordType[]>(() => {
(parseProp(column.value.meta)?.limitOptions || []).length (parseProp(column.value.meta)?.limitOptions || []).length
) { ) {
collaborators.push( collaborators.push(
...( ...(baseUsers.value || [])
baseUsers.value .filter((user) => {
.filter((user) => { if (limitOptionsById[user.id]?.show !== undefined) {
if (limitOptionsById[user.id]?.show !== undefined) { return limitOptionsById[user.id]?.show
return limitOptionsById[user.id]?.show }
} return false
return false })
}) .map((user: any) => ({
?.map((user: any) => ({ id: user.id,
id: user.id, email: user.email,
email: user.email, display_name: user.display_name,
display_name: user.display_name, deleted: user.deleted,
deleted: user.deleted, order: user.id && limitOptionsById[user.id] ? limitOptionsById[user.id]?.order ?? user.order : order++,
order: user.id && limitOptionsById[user.id] ? limitOptionsById[user.id]?.order ?? user.order : order++, }))
})) || [] .sort((a, b) => a.order - b.order),
).sort((a, b) => a.order - b.order),
) )
} else { } else {
collaborators.push( collaborators.push(
...( ...(baseUsers.value || [])
baseUsers.value?.map((user: any) => ({ .map((user: any) => ({
id: user.id, id: user.id,
email: user.email, email: user.email,
display_name: user.display_name, display_name: user.display_name,
deleted: user.deleted, deleted: user.deleted,
order: order++, order: order++,
})) || [] }))
).sort((a, b) => a.order - b.order), .sort((a, b) => a.order - b.order),
) )
} }
return collaborators return collaborators

8
packages/nc-gui/components/general/ImageCropper.vue

@ -103,13 +103,7 @@ watch(showCropper, () => {
class="nc-cropper relative" class="nc-cropper relative"
:src="imageConfig.src" :src="imageConfig.src"
:auto-zoom="true" :auto-zoom="true"
:stencil-props=" :stencil-props="cropperConfig?.aspectRatio ? { aspectRatio: cropperConfig.aspectRatio } : {}"
cropperConfig?.aspectRatio
? {
aspectRatio: cropperConfig.aspectRatio,
}
: {}
"
/> />
<div v-if="previewImage.src" class="result_preview"> <div v-if="previewImage.src" class="result_preview">
<img :src="previewImage.src" alt="Preview Image" /> <img :src="previewImage.src" alt="Preview Image" />

9
packages/nc-gui/components/smartsheet/Form.vue

@ -170,6 +170,7 @@ const { betaFeatureToggleState } = useBetaFeatureToggle()
const { open, onChange: onChangeFile } = useFileDialog({ const { open, onChange: onChangeFile } = useFileDialog({
accept: 'image/*', accept: 'image/*',
multiple: false, multiple: false,
reset: true,
}) })
const visibleColumns = computed(() => localColumns.value.filter((f) => f.show).sort((a, b) => a.order - b.order)) const visibleColumns = computed(() => localColumns.value.filter((f) => f.show).sort((a, b) => a.order - b.order))
@ -695,7 +696,7 @@ useEventListener(
></GeneralImageCropper> ></GeneralImageCropper>
<!-- cover image --> <!-- cover image -->
<div class="group relative max-w-[max(33%,688px)] mx-auto"> <div class="group relative max-w-[max(33%,688px)] mx-auto">
<GeneralFormBanner :banner-image-url="formViewData.banner_image_url"/> <GeneralFormBanner :banner-image-url="formViewData.banner_image_url" />
<div class="absolute bottom-0 right-0 hidden group-hover:block"> <div class="absolute bottom-0 right-0 hidden group-hover:block">
<div class="flex items-center space-x-1 m-2"> <div class="flex items-center space-x-1 m-2">
<NcButton <NcButton
@ -750,8 +751,8 @@ useEventListener(
<!-- Form logo --> <!-- Form logo -->
<div class="mb-4"> <div class="mb-4">
<div <div
class="nc-form-logo-wrapper mx-6 group relative rounded-xl inline-block h-56px overflow-hidden" class="nc-form-logo-wrapper mx-6 group relative rounded-xl inline-block h-56px max-w-189px overflow-hidden"
:class="formViewData.logo_url ? 'hover:(w-full bg-gray-100) max-w-189px' : 'w-full bg-gray-100 max-w-148px'" :class="formViewData.logo_url ? 'hover:(w-full bg-gray-100)' : 'bg-gray-100'"
style="transition: all 0.3s ease-in" style="transition: all 0.3s ease-in"
> >
<LazyCellAttachmentImage <LazyCellAttachmentImage
@ -761,7 +762,7 @@ useEventListener(
/> />
<div <div
class="items-center space-x-1 flex-nowrap m-3" class="items-center space-x-1 flex-nowrap m-3"
:class="'hidden absolute top-0 left-0 group-hover:flex'" :class="formViewData.logo_url ? 'hidden absolute top-0 left-0 group-hover:flex' : 'flex'"
> >
<NcButton <NcButton
v-if="isEditable" v-if="isEditable"

18
packages/nc-gui/components/smartsheet/form/LimitOptions.vue

@ -32,7 +32,7 @@ const vModel = computed({
let order = 1 let order = 1
const limitOptionsById = const limitOptionsById =
(props.modelValue || []).reduce((o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => { (props.modelValue || []).reduce((o: Record<string, FormFieldsLimitOptionsType>, f: FormFieldsLimitOptionsType) => {
if (f?.order !== undefined && order < f.order) { if (order < (f?.order ?? 0)) {
order = f.order order = f.order
} }
return { return {
@ -43,12 +43,12 @@ const vModel = computed({
if (UITypes.User === column.value.uidt) { if (UITypes.User === column.value.uidt) {
const collaborators = ((baseUsers.value || []) as UserFieldRecordType[]) const collaborators = ((baseUsers.value || []) as UserFieldRecordType[])
?.filter((user) => !user?.deleted) .filter((user) => !user?.deleted)
?.map((user: any) => ({ .map((user: any) => ({
id: user.id, id: user.id,
email: user.email, email: user.email,
display_name: user.display_name, display_name: user.display_name,
order: user.id && limitOptionsById[user.id] ? limitOptionsById[user.id]?.order ?? c.order : order++, order: user.id && limitOptionsById[user.id] ? limitOptionsById[user.id]?.order ?? user.order : order++,
show: user.id && limitOptionsById[user.id] ? limitOptionsById[user.id]?.show : !(props.modelValue || []).length, show: user.id && limitOptionsById[user.id] ? limitOptionsById[user.id]?.show : !(props.modelValue || []).length,
})) }))
.sort((a, b) => a.order - b.order) .sort((a, b) => a.order - b.order)
@ -99,16 +99,6 @@ async function onMove(_event: { moved: { newIndex: number; oldIndex: number; ele
moved: { newIndex = 0, oldIndex = 0, element }, moved: { newIndex = 0, oldIndex = 0, element },
} = _event } = _event
if (!vModel.value.length || vModel.value.length === 1) {
element.order = 1
} else if (vModel.value.length - 1 === newIndex) {
element.order = (vModel.value[newIndex - 1]?.order || 0) + 1
} else if (newIndex === 0) {
element.order = (vModel.value[1]?.order || 0) / 2
} else {
element.order = ((vModel.value[newIndex - 1]?.order || 0) + (vModel.value[newIndex + 1].order || 0)) / 2
}
let nextOrder: number let nextOrder: number
// set new order value based on the new order of the items // set new order value based on the new order of the items

2
packages/nc-gui/utils/parseUtils.ts

@ -1,7 +1,7 @@
export function parseProp(v: any): any { export function parseProp(v: any): any {
if (!v) return {} if (!v) return {}
try { try {
return typeof v === 'string' ? JSON.parse(v) : v return typeof v === 'string' ? JSON.parse(v) ?? {} : v
} catch { } catch {
return {} return {}
} }

Loading…
Cancel
Save