refactor: change event is not needed in grid row fields

This commit is contained in:
Shariq Ansari 2024-12-29 13:43:54 +05:30
parent 8471cbd044
commit ecd10fb73b
3 changed files with 24 additions and 93 deletions

View File

@ -90,7 +90,7 @@ const data = createDocumentResource({
createToast({ createToast({
title: 'Data Updated', title: 'Data Updated',
icon: 'check', icon: 'check',
iconClasses: 'text-green-600', iconClasses: 'text-ink-green-3',
}) })
}, },
onError: (err) => { onError: (err) => {
@ -117,24 +117,9 @@ function parseTabs(_tabs) {
tab.sections.forEach((section) => { tab.sections.forEach((section) => {
section.fields.forEach((field) => { section.fields.forEach((field) => {
if (field.type === 'Table') { if (field.type === 'Table') {
let name = props.meta[field.name].df.fieldname field.fields = props.meta[field.name].fields
let fields = props.meta[field.name].fields .filter((field) => field.in_list_view)
let _fields = fields.map((field) => { .map((field) => getFieldObj(field))
return {
...getFieldObj(field),
onChange: (value, index) => {
data.doc[name][index][field.fieldname] = value
},
}
})
field.fields = [
{
no_tabs: true,
sections: [{ columns: 3, hideLabel: true, fields: _fields }],
},
]
field.gridFields = _fields.filter((field) => field.in_list_view)
} }
}) })
}) })

View File

@ -28,9 +28,9 @@
:style="{ gridTemplateColumns: gridTemplateColumns }" :style="{ gridTemplateColumns: gridTemplateColumns }"
> >
<div <div
v-if="gridFields?.length" v-if="fields?.length"
class="border-r border-outline-gray-2 p-2 truncate" class="border-r border-outline-gray-2 p-2 truncate"
v-for="field in gridFields" v-for="field in fields"
:key="field.name" :key="field.name"
:title="field.label" :title="field.label"
> >
@ -65,21 +65,17 @@
:style="{ gridTemplateColumns: gridTemplateColumns }" :style="{ gridTemplateColumns: gridTemplateColumns }"
> >
<div <div
v-if="gridFields?.length" v-if="fields?.length"
class="border-r border-outline-gray-modals h-full" class="border-r border-outline-gray-modals h-full"
v-for="field in gridFields" v-for="field in fields"
:key="field.name" :key="field.name"
> >
<Link <Link
v-if="field.type === 'Link'" v-if="field.type === 'Link'"
class="text-sm text-ink-gray-8" class="text-sm text-ink-gray-8"
:value="row[field.name]" v-model="row[field.name]"
:doctype="field.options" :doctype="field.options"
:filters="field.filters" :filters="field.filters"
@change="
(data: String) =>
field.onChange && field.onChange(data, index)
"
/> />
<div <div
v-else-if="field.type === 'Check'" v-else-if="field.type === 'Check'"
@ -88,39 +84,23 @@
<Checkbox <Checkbox
class="cursor-pointer duration-300" class="cursor-pointer duration-300"
v-model="row[field.name]" v-model="row[field.name]"
@change="
(e: Event) =>
field.onChange &&
field.onChange(
(e.target as HTMLInputElement).checked,
index,
)
"
/> />
</div> </div>
<DatePicker <DatePicker
v-else-if="field.type === 'Date'" v-else-if="field.type === 'Date'"
:value="row[field.name]" v-model="row[field.name]"
icon-left="" icon-left=""
variant="outline" variant="outline"
:formatter="(date) => getFormat(date, '', true)" :formatter="(date) => getFormat(date, '', true)"
input-class="border-none text-sm text-ink-gray-8" input-class="border-none text-sm text-ink-gray-8"
@change="
(data: String) =>
field.onChange && field.onChange(data, index)
"
/> />
<DateTimePicker <DateTimePicker
v-else-if="field.type === 'Datetime'" v-else-if="field.type === 'Datetime'"
:value="row[field.name]" v-model="row[field.name]"
icon-left="" icon-left=""
variant="outline" variant="outline"
:formatter="(date) => getFormat(date, '', true, true)" :formatter="(date) => getFormat(date, '', true, true)"
input-class="border-none text-sm text-ink-gray-8" input-class="border-none text-sm text-ink-gray-8"
@change="
(data: String) =>
field.onChange && field.onChange(data, index)
"
/> />
<FormControl <FormControl
v-else-if=" v-else-if="
@ -129,62 +109,30 @@
) )
" "
type="textarea" type="textarea"
v-model="row[field.name]"
variant="outline" variant="outline"
@change=" v-model="row[field.name]"
(e: Event) =>
field.onChange &&
field.onChange(
(e.target as HTMLInputElement).value,
index,
)
"
/> />
<FormControl <FormControl
v-else-if="['Int'].includes(field.type)" v-else-if="['Int'].includes(field.type)"
type="number" type="number"
v-model="row[field.name]"
variant="outline" variant="outline"
@change=" v-model="row[field.name]"
(e: Event) =>
field.onChange &&
field.onChange(
(e.target as HTMLInputElement).value,
index,
)
"
/> />
<FormControl <FormControl
v-else-if="field.type === 'Select'" v-else-if="field.type === 'Select'"
class="text-sm text-ink-gray-8" class="text-sm text-ink-gray-8"
v-model="row[field.name]"
type="select" type="select"
:options="field.options"
variant="outline" variant="outline"
@change=" v-model="row[field.name]"
(e: Event) => :options="field.options"
field.onChange &&
field.onChange(
(e.target as HTMLInputElement).value,
index,
)
"
/> />
<FormControl <FormControl
v-else v-else
class="text-sm text-ink-gray-8" class="text-sm text-ink-gray-8"
v-model="row[field.name]"
type="text" type="text"
:options="field.options"
variant="outline" variant="outline"
@change=" v-model="row[field.name]"
(e: Event) => :options="field.options"
field.onChange &&
field.onChange(
(e.target as HTMLInputElement).value,
index,
)
"
/> />
</div> </div>
</div> </div>
@ -218,7 +166,7 @@
</div> </div>
</div> </div>
<div v-if="gridFields?.length" class="mt-2 flex flex-row gap-2"> <div v-if="fields?.length" class="mt-2 flex flex-row gap-2">
<Button <Button
v-if="showDeleteBtn" v-if="showDeleteBtn"
:label="__('Delete')" :label="__('Delete')"
@ -249,7 +197,6 @@ import { ref, reactive, computed, PropType } from 'vue'
const props = defineProps<{ const props = defineProps<{
label?: string label?: string
gridFields: GridColumn[]
fields: GridColumn[] fields: GridColumn[]
doctype: string doctype: string
}>() }>()
@ -264,11 +211,9 @@ const selectedRows = reactive(new Set<string>())
const showGridRowFieldsModal = ref(false) const showGridRowFieldsModal = ref(false)
const gridTemplateColumns = computed(() => { const gridTemplateColumns = computed(() => {
if (!props.gridFields?.length) return '1fr' if (!props.fields?.length) return '1fr'
// for the checkbox & sr no. columns // for the checkbox & sr no. columns
return props.gridFields return props.fields.map((col) => `minmax(0, ${col.width || 2}fr)`).join(' ')
.map((col) => `minmax(0, ${col.width || 2}fr)`)
.join(' ')
}) })
const allRowsSelected = computed(() => { const allRowsSelected = computed(() => {
@ -296,7 +241,7 @@ const toggleSelectRow = (row: GridRow) => {
const addRow = () => { const addRow = () => {
const newRow = {} as GridRow const newRow = {} as GridRow
props.gridFields?.forEach((field) => { props.fields?.forEach((field) => {
if (field.type === 'Check') newRow[field.name] = false if (field.type === 'Check') newRow[field.name] = false
else newRow[field.name] = '' else newRow[field.name] = ''
}) })

View File

@ -80,7 +80,6 @@
v-else-if="field.type === 'Table'" v-else-if="field.type === 'Table'"
v-model="data[field.name]" v-model="data[field.name]"
:fields="field.fields" :fields="field.fields"
:gridFields="field.gridFields"
:doctype="field.options" :doctype="field.options"
/> />
<FormControl <FormControl
@ -185,7 +184,9 @@
/> />
<FormControl <FormControl
v-else-if=" v-else-if="
['Small Text', 'Text', 'Long Text', 'Code'].includes(field.type) ['Small Text', 'Text', 'Long Text', 'Code'].includes(
field.type,
)
" "
type="textarea" type="textarea"
:placeholder="getPlaceholder(field)" :placeholder="getPlaceholder(field)"