ListForm SubFormDialog güncellemeleri
This commit is contained in:
parent
84b9f65107
commit
96cd6dfd80
3 changed files with 174 additions and 25 deletions
|
|
@ -1,7 +1,15 @@
|
||||||
import { ListFormJsonRowDto } from '../../proxy/admin/list-form/models'
|
import { ListFormJsonRowDto } from '../../proxy/admin/list-form/models'
|
||||||
|
import { PagedAndSortedResultRequestDto, PagedResultDto } from '../../proxy'
|
||||||
import { FieldsDefaultValueDto, GridOptionsEditDto } from '../../proxy/form/models'
|
import { FieldsDefaultValueDto, GridOptionsEditDto } from '../../proxy/form/models'
|
||||||
import apiService from '../api.service'
|
import apiService from '../api.service'
|
||||||
|
|
||||||
|
export const getListForms = (input: PagedAndSortedResultRequestDto) =>
|
||||||
|
apiService.fetchData<PagedResultDto<GridOptionsEditDto>>({
|
||||||
|
method: 'GET',
|
||||||
|
url: `/api/admin/list-forms`,
|
||||||
|
params: input,
|
||||||
|
})
|
||||||
|
|
||||||
export const getListFormByCode = (listFormCode: string) =>
|
export const getListFormByCode = (listFormCode: string) =>
|
||||||
apiService.fetchData<GridOptionsEditDto>({
|
apiService.fetchData<GridOptionsEditDto>({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
|
||||||
|
|
@ -10,21 +10,24 @@ import {
|
||||||
} from '@/components/ui'
|
} from '@/components/ui'
|
||||||
import { ListFormJsonRowDto } from '@/proxy/admin/list-form/models'
|
import { ListFormJsonRowDto } from '@/proxy/admin/list-form/models'
|
||||||
import { SelectBoxOption } from '@/types/shared'
|
import { SelectBoxOption } from '@/types/shared'
|
||||||
import { useStoreActions } from '@/store'
|
import { useStoreActions, useStoreState } from '@/store'
|
||||||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
||||||
import { Field, FieldArray, FieldProps, Form, Formik } from 'formik'
|
import { Field, FieldArray, FieldProps, Form, Formik } from 'formik'
|
||||||
import { Dispatch, SetStateAction } from 'react'
|
import { Dispatch, SetStateAction, useEffect, useState } from 'react'
|
||||||
import { FaCalendarPlus, FaCalendarMinus } from 'react-icons/fa'
|
import { FaCalendarPlus, FaCalendarMinus } from 'react-icons/fa'
|
||||||
import { boolean, object, string } from 'yup'
|
import { boolean, object, string } from 'yup'
|
||||||
import { dbSourceTypeOptions, tabTypeOptions } from '../options'
|
import { dbSourceTypeOptions, tabTypeOptions } from '../options'
|
||||||
import { JsonRowDialogData } from './types'
|
import { JsonRowDialogData } from './types'
|
||||||
import {
|
import {
|
||||||
deleteListFormJsonRow,
|
deleteListFormJsonRow,
|
||||||
|
getListForms,
|
||||||
getListFormJsonRow,
|
getListFormJsonRow,
|
||||||
postListFormJsonRow,
|
postListFormJsonRow,
|
||||||
putListFormJsonRow,
|
putListFormJsonRow,
|
||||||
} from '@/services/admin/list-form.service'
|
} from '@/services/admin/list-form.service'
|
||||||
import { SubFormDto, SubFormRelationDto } from '@/proxy/form/models'
|
import { SubFormDto, SubFormRelationDto } from '@/proxy/form/models'
|
||||||
|
import { ColumnFormatEditDto } from '@/proxy/admin/list-form-field/models'
|
||||||
|
import { getListFormFields } from '@/services/admin/list-form-field.service'
|
||||||
|
|
||||||
const schema = object().shape({
|
const schema = object().shape({
|
||||||
tabTitle: string().required(),
|
tabTitle: string().required(),
|
||||||
|
|
@ -45,7 +48,87 @@ function JsonRowOpDialogSubForm({
|
||||||
setData: Dispatch<SetStateAction<JsonRowDialogData | undefined>>
|
setData: Dispatch<SetStateAction<JsonRowDialogData | undefined>>
|
||||||
}) {
|
}) {
|
||||||
const { setJsonValue } = useStoreActions((a) => a.admin.lists)
|
const { setJsonValue } = useStoreActions((a) => a.admin.lists)
|
||||||
|
const listFormValues = useStoreState((s) => s.admin.lists.values)
|
||||||
const { translate } = useLocalization()
|
const { translate } = useLocalization()
|
||||||
|
const [listFormOptions, setListFormOptions] = useState<SelectBoxOption[]>([])
|
||||||
|
const [parentFields, setParentFields] = useState<ColumnFormatEditDto[]>([])
|
||||||
|
const [childFields, setChildFields] = useState<ColumnFormatEditDto[]>([])
|
||||||
|
const [isLoadingListForms, setIsLoadingListForms] = useState(false)
|
||||||
|
const [isLoadingChildFields, setIsLoadingChildFields] = useState(false)
|
||||||
|
|
||||||
|
const parentFieldOptions = parentFields.map((field) => ({
|
||||||
|
value: field.fieldName,
|
||||||
|
label: `${field.fieldName} (${dbSourceTypeOptions.find((option) => option.value === field.sourceDbType)?.label ?? field.sourceDbType})`,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const childFieldOptions = childFields.map((field) => ({
|
||||||
|
value: field.fieldName,
|
||||||
|
label: field.fieldName,
|
||||||
|
}))
|
||||||
|
|
||||||
|
const loadChildFields = async (listFormCode?: string) => {
|
||||||
|
if (!listFormCode) {
|
||||||
|
setChildFields([])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoadingChildFields(true)
|
||||||
|
try {
|
||||||
|
const resp = await getListFormFields({
|
||||||
|
listFormCode,
|
||||||
|
sorting: 'ListOrderNo',
|
||||||
|
maxResultCount: 1000,
|
||||||
|
})
|
||||||
|
setChildFields(resp.data?.items ?? [])
|
||||||
|
} catch {
|
||||||
|
setChildFields([])
|
||||||
|
} finally {
|
||||||
|
setIsLoadingChildFields(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isOpen || !listFormValues?.listFormCode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadData = async () => {
|
||||||
|
setIsLoadingListForms(true)
|
||||||
|
try {
|
||||||
|
const [listFormsResp, parentFieldsResp] = await Promise.all([
|
||||||
|
getListForms({ sorting: 'ListFormCode', maxResultCount: 1000 }),
|
||||||
|
getListFormFields({
|
||||||
|
listFormCode: listFormValues.listFormCode!,
|
||||||
|
sorting: 'ListOrderNo',
|
||||||
|
maxResultCount: 1000,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
|
||||||
|
setListFormOptions(
|
||||||
|
(listFormsResp.data?.items ?? [])
|
||||||
|
.filter((item) => item.listFormCode)
|
||||||
|
.map((item) => ({
|
||||||
|
value: item.listFormCode,
|
||||||
|
label: `${item.listFormCode}${item.title ? ` - ${translate(`::${item.title}`)}` : ''}`,
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
setParentFields(parentFieldsResp.data?.items ?? [])
|
||||||
|
} catch {
|
||||||
|
setListFormOptions([])
|
||||||
|
setParentFields([])
|
||||||
|
} finally {
|
||||||
|
setIsLoadingListForms(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadData()
|
||||||
|
}, [isOpen, listFormValues?.listFormCode])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isOpen) {
|
||||||
|
loadChildFields(data?.subFormValues?.code)
|
||||||
|
}
|
||||||
|
}, [isOpen, data?.subFormValues?.code])
|
||||||
|
|
||||||
const handleClose = async (e?: any) => {
|
const handleClose = async (e?: any) => {
|
||||||
if (e) {
|
if (e) {
|
||||||
|
|
@ -142,6 +225,32 @@ function JsonRowOpDialogSubForm({
|
||||||
/>
|
/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
|
<FormItem
|
||||||
|
label="Code"
|
||||||
|
invalid={errors.code && touched.code}
|
||||||
|
errorMessage={errors.code}
|
||||||
|
>
|
||||||
|
<Field type="text" autoComplete="off" name="code" placeholder="Code">
|
||||||
|
{({ field, form }: FieldProps<SelectBoxOption>) => (
|
||||||
|
<Select
|
||||||
|
field={field}
|
||||||
|
form={form}
|
||||||
|
isClearable={true}
|
||||||
|
isLoading={isLoadingListForms}
|
||||||
|
options={listFormOptions}
|
||||||
|
value={listFormOptions.find(
|
||||||
|
(option) => option.value === values.code,
|
||||||
|
)}
|
||||||
|
onChange={(option) => {
|
||||||
|
form.setFieldValue(field.name, option?.value ?? '')
|
||||||
|
form.setFieldValue('relation', [])
|
||||||
|
loadChildFields(option?.value)
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
|
</FormItem>
|
||||||
|
|
||||||
<FormItem
|
<FormItem
|
||||||
label="Tab Type"
|
label="Tab Type"
|
||||||
invalid={errors.tabType && touched.tabType}
|
invalid={errors.tabType && touched.tabType}
|
||||||
|
|
@ -163,20 +272,6 @@ function JsonRowOpDialogSubForm({
|
||||||
</Field>
|
</Field>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
<FormItem
|
|
||||||
label="Code"
|
|
||||||
invalid={errors.code && touched.code}
|
|
||||||
errorMessage={errors.code}
|
|
||||||
>
|
|
||||||
<Field
|
|
||||||
type="text"
|
|
||||||
autoComplete="off"
|
|
||||||
name="code"
|
|
||||||
placeholder="Code"
|
|
||||||
component={Input}
|
|
||||||
/>
|
|
||||||
</FormItem>
|
|
||||||
|
|
||||||
<FormItem
|
<FormItem
|
||||||
label="isRefresh"
|
label="isRefresh"
|
||||||
invalid={errors.isRefresh && touched.isRefresh}
|
invalid={errors.isRefresh && touched.isRefresh}
|
||||||
|
|
@ -204,9 +299,31 @@ function JsonRowOpDialogSubForm({
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
name={`relation.${index}.parentFieldName`}
|
name={`relation.${index}.parentFieldName`}
|
||||||
component={Input}
|
|
||||||
placeholder={translate('::ListForms.ListFormEdit.SubFormsRelation.ParentFieldName')}
|
placeholder={translate('::ListForms.ListFormEdit.SubFormsRelation.ParentFieldName')}
|
||||||
|
>
|
||||||
|
{({ field, form }: FieldProps<SelectBoxOption>) => (
|
||||||
|
<Select
|
||||||
|
field={field}
|
||||||
|
form={form}
|
||||||
|
isClearable={true}
|
||||||
|
options={parentFieldOptions}
|
||||||
|
value={parentFieldOptions.find(
|
||||||
|
(option) => option.value === item?.parentFieldName,
|
||||||
|
)}
|
||||||
|
onChange={(option) => {
|
||||||
|
const selectedField = parentFields.find(
|
||||||
|
(parentField) => parentField.fieldName === option?.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
form.setFieldValue(field.name, option?.value ?? '')
|
||||||
|
form.setFieldValue(
|
||||||
|
`relation.${index}.dbType`,
|
||||||
|
selectedField?.sourceDbType ?? '',
|
||||||
|
)
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-4/12 ml-2">
|
<div className="w-4/12 ml-2">
|
||||||
|
|
@ -214,9 +331,24 @@ function JsonRowOpDialogSubForm({
|
||||||
type="text"
|
type="text"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
name={`relation.${index}.childFieldName`}
|
name={`relation.${index}.childFieldName`}
|
||||||
component={Input}
|
|
||||||
placeholder={translate('::ListForms.ListFormEdit.SubFormsRelation.ChildFieldName')}
|
placeholder={translate('::ListForms.ListFormEdit.SubFormsRelation.ChildFieldName')}
|
||||||
|
>
|
||||||
|
{({ field, form }: FieldProps<SelectBoxOption>) => (
|
||||||
|
<Select
|
||||||
|
field={field}
|
||||||
|
form={form}
|
||||||
|
isClearable={true}
|
||||||
|
isLoading={isLoadingChildFields}
|
||||||
|
options={childFieldOptions}
|
||||||
|
value={childFieldOptions.find(
|
||||||
|
(option) => option.value === item?.childFieldName,
|
||||||
|
)}
|
||||||
|
onChange={(option) =>
|
||||||
|
form.setFieldValue(field.name, option?.value ?? '')
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="w-3/12 ml-2">
|
<div className="w-3/12 ml-2">
|
||||||
|
|
@ -231,6 +363,7 @@ function JsonRowOpDialogSubForm({
|
||||||
field={field}
|
field={field}
|
||||||
form={form}
|
form={form}
|
||||||
isClearable={true}
|
isClearable={true}
|
||||||
|
isDisabled={true}
|
||||||
options={dbSourceTypeOptions}
|
options={dbSourceTypeOptions}
|
||||||
value={dbSourceTypeOptions?.find(
|
value={dbSourceTypeOptions?.find(
|
||||||
(option: any) =>
|
(option: any) =>
|
||||||
|
|
@ -264,7 +397,11 @@ function JsonRowOpDialogSubForm({
|
||||||
title="Add"
|
title="Add"
|
||||||
icon={<FaCalendarPlus />}
|
icon={<FaCalendarPlus />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
arrayHelpers.insert(index + 1, '')
|
arrayHelpers.insert(index + 1, {
|
||||||
|
parentFieldName: '',
|
||||||
|
childFieldName: '',
|
||||||
|
dbType: '',
|
||||||
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -279,7 +416,11 @@ function JsonRowOpDialogSubForm({
|
||||||
title="Add"
|
title="Add"
|
||||||
icon={<FaCalendarPlus />}
|
icon={<FaCalendarPlus />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
arrayHelpers.push('')
|
arrayHelpers.push({
|
||||||
|
parentFieldName: '',
|
||||||
|
childFieldName: '',
|
||||||
|
dbType: '',
|
||||||
|
})
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ function JsonRowOpDialogWidget({
|
||||||
<div className="flex-1 overflow-y-auto p-1">
|
<div className="flex-1 overflow-y-auto p-1">
|
||||||
<div className="grid grid-cols-5 gap-4">
|
<div className="grid grid-cols-5 gap-4">
|
||||||
<FormItem
|
<FormItem
|
||||||
label="Column Gap (Sütun Boşluğu)"
|
label="Column Gap"
|
||||||
invalid={errors.colGap && touched.colGap}
|
invalid={errors.colGap && touched.colGap}
|
||||||
errorMessage={errors.colGap}
|
errorMessage={errors.colGap}
|
||||||
>
|
>
|
||||||
|
|
@ -156,7 +156,7 @@ function JsonRowOpDialogWidget({
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
|
||||||
<FormItem
|
<FormItem
|
||||||
label="Column Span (Sütun Genişliği)"
|
label="Column Span"
|
||||||
invalid={errors.colSpan && touched.colSpan}
|
invalid={errors.colSpan && touched.colSpan}
|
||||||
errorMessage={errors.colSpan}
|
errorMessage={errors.colSpan}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue