editorOptions içerisinde dataSource bilgisi eklendi
This commit is contained in:
parent
74075aa68e
commit
b75158bc01
5 changed files with 70 additions and 57 deletions
|
|
@ -11,7 +11,6 @@ import { GridBoxEditorComponent } from './editors/GridBoxEditorComponent'
|
||||||
import { TagBoxEditorComponent } from './editors/TagBoxEditorComponent'
|
import { TagBoxEditorComponent } from './editors/TagBoxEditorComponent'
|
||||||
import { RowMode, SimpleItemWithColData } from './types'
|
import { RowMode, SimpleItemWithColData } from './types'
|
||||||
import { PlatformEditorTypes } from '@/proxy/form/models'
|
import { PlatformEditorTypes } from '@/proxy/form/models'
|
||||||
import { useLookupDataSource } from './useLookupDataSource'
|
|
||||||
|
|
||||||
const FormDevExpress = (props: {
|
const FormDevExpress = (props: {
|
||||||
listFormCode: string
|
listFormCode: string
|
||||||
|
|
@ -23,7 +22,6 @@ const FormDevExpress = (props: {
|
||||||
setFormData: Dispatch<any>
|
setFormData: Dispatch<any>
|
||||||
}) => {
|
}) => {
|
||||||
const { listFormCode, isSubForm, mode, refForm, formData, formItems, setFormData } = props
|
const { listFormCode, isSubForm, mode, refForm, formData, formItems, setFormData } = props
|
||||||
const { getLookupDataSource } = useLookupDataSource({ listFormCode, isSubForm })
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className={`${DX_CLASSNAMES} p-2`}>
|
<form className={`${DX_CLASSNAMES} p-2`}>
|
||||||
|
|
@ -51,6 +49,7 @@ const FormDevExpress = (props: {
|
||||||
caption={formGroupItem.caption}
|
caption={formGroupItem.caption}
|
||||||
>
|
>
|
||||||
{(formGroupItem.items as SimpleItemWithColData[])?.map((formItem, i) => {
|
{(formGroupItem.items as SimpleItemWithColData[])?.map((formItem, i) => {
|
||||||
|
console.log('formItem', formItem.colData)
|
||||||
return formItem.editorType2 === PlatformEditorTypes.dxTagBox ? (
|
return formItem.editorType2 === PlatformEditorTypes.dxTagBox ? (
|
||||||
<SimpleItemDx
|
<SimpleItemDx
|
||||||
key={'formItem-' + i}
|
key={'formItem-' + i}
|
||||||
|
|
@ -69,10 +68,6 @@ const FormDevExpress = (props: {
|
||||||
...formItem.editorOptions,
|
...formItem.editorOptions,
|
||||||
...(mode === 'view' ? { readOnly: true } : {}),
|
...(mode === 'view' ? { readOnly: true } : {}),
|
||||||
}}
|
}}
|
||||||
dataSource={getLookupDataSource(
|
|
||||||
formItem.colData?.editorOptions,
|
|
||||||
formItem.colData,
|
|
||||||
)}
|
|
||||||
></TagBoxEditorComponent>
|
></TagBoxEditorComponent>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -95,10 +90,6 @@ const FormDevExpress = (props: {
|
||||||
...formItem.editorOptions,
|
...formItem.editorOptions,
|
||||||
...(mode === 'view' ? { readOnly: true } : {}),
|
...(mode === 'view' ? { readOnly: true } : {}),
|
||||||
}}
|
}}
|
||||||
dataSource={getLookupDataSource(
|
|
||||||
formItem.colData?.editorOptions,
|
|
||||||
formItem.colData,
|
|
||||||
)}
|
|
||||||
></GridBoxEditorComponent>
|
></GridBoxEditorComponent>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -110,16 +101,6 @@ const FormDevExpress = (props: {
|
||||||
{...formItem}
|
{...formItem}
|
||||||
editorOptions={{
|
editorOptions={{
|
||||||
...formItem.editorOptions,
|
...formItem.editorOptions,
|
||||||
...(formItem.colData?.lookupDto?.dataSourceType
|
|
||||||
? {
|
|
||||||
dataSource: getLookupDataSource(
|
|
||||||
formItem.colData?.editorOptions,
|
|
||||||
formItem.colData,
|
|
||||||
),
|
|
||||||
valueExpr: formItem.colData?.lookupDto?.valueExpr,
|
|
||||||
displayExpr: formItem.colData?.lookupDto?.displayExpr,
|
|
||||||
}
|
|
||||||
: {}),
|
|
||||||
...(mode === 'view' ? { readOnly: true } : { autoFocus: i === 1 }),
|
...(mode === 'view' ? { readOnly: true } : { autoFocus: i === 1 }),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ const GridBoxEditorComponent = ({
|
||||||
onValueChanged,
|
onValueChanged,
|
||||||
col,
|
col,
|
||||||
editorOptions,
|
editorOptions,
|
||||||
dataSource
|
|
||||||
}: {
|
}: {
|
||||||
value: any
|
value: any
|
||||||
options?: GridBoxOptionsDto
|
options?: GridBoxOptionsDto
|
||||||
|
|
@ -19,7 +18,6 @@ const GridBoxEditorComponent = ({
|
||||||
onValueChanged: (e: any) => void
|
onValueChanged: (e: any) => void
|
||||||
col?: ColumnFormatDto
|
col?: ColumnFormatDto
|
||||||
editorOptions: any
|
editorOptions: any
|
||||||
dataSource: any
|
|
||||||
}): ReactElement => {
|
}): ReactElement => {
|
||||||
const gridRef = useRef<DataGrid>(null)
|
const gridRef = useRef<DataGrid>(null)
|
||||||
const val = Array.isArray(value) ? value : [value]
|
const val = Array.isArray(value) ? value : [value]
|
||||||
|
|
@ -34,7 +32,7 @@ const GridBoxEditorComponent = ({
|
||||||
<DropDownBox
|
<DropDownBox
|
||||||
{...editorOptions}
|
{...editorOptions}
|
||||||
value={val}
|
value={val}
|
||||||
dataSource={dataSource}
|
dataSource={editorOptions?.dataSource}
|
||||||
valueExpr={lookupDto?.valueExpr}
|
valueExpr={lookupDto?.valueExpr}
|
||||||
displayExpr={lookupDto?.displayExpr}
|
displayExpr={lookupDto?.displayExpr}
|
||||||
showClearButton={options?.showClearButton}
|
showClearButton={options?.showClearButton}
|
||||||
|
|
@ -52,7 +50,7 @@ const GridBoxEditorComponent = ({
|
||||||
<>
|
<>
|
||||||
<DataGrid
|
<DataGrid
|
||||||
ref={gridRef}
|
ref={gridRef}
|
||||||
dataSource={dataSource}
|
dataSource={editorOptions?.dataSource}
|
||||||
key={lookupDto?.valueExpr}
|
key={lookupDto?.valueExpr}
|
||||||
filterRow={{
|
filterRow={{
|
||||||
visible: options?.filterRowVisible,
|
visible: options?.filterRowVisible,
|
||||||
|
|
@ -78,7 +76,7 @@ const GridBoxEditorComponent = ({
|
||||||
//TODO:Bu kısım tekrar değerlendirilmeli
|
//TODO:Bu kısım tekrar değerlendirilmeli
|
||||||
onEditorPrepared={(event) => {
|
onEditorPrepared={(event) => {
|
||||||
const getListValues = async () => {
|
const getListValues = async () => {
|
||||||
const data = await dataSource?.load()
|
const data = await editorOptions?.dataSource?.load()
|
||||||
|
|
||||||
const listValues = data.map((a: any) => ({
|
const listValues = data.map((a: any) => ({
|
||||||
key: a.key,
|
key: a.key,
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ const TagBoxEditorComponent = ({
|
||||||
onValueChanged,
|
onValueChanged,
|
||||||
col,
|
col,
|
||||||
editorOptions,
|
editorOptions,
|
||||||
dataSource
|
|
||||||
}: {
|
}: {
|
||||||
value: any
|
value: any
|
||||||
setDefaultValue: boolean
|
setDefaultValue: boolean
|
||||||
|
|
@ -19,7 +18,6 @@ const TagBoxEditorComponent = ({
|
||||||
onValueChanged: (e: any) => void
|
onValueChanged: (e: any) => void
|
||||||
col?: ColumnFormatDto
|
col?: ColumnFormatDto
|
||||||
editorOptions: any
|
editorOptions: any
|
||||||
dataSource: any
|
|
||||||
}): ReactElement => {
|
}): ReactElement => {
|
||||||
const val = Array.isArray(value) ? value : [value]
|
const val = Array.isArray(value) ? value : [value]
|
||||||
const lookupDto = col?.lookupDto
|
const lookupDto = col?.lookupDto
|
||||||
|
|
@ -33,7 +31,7 @@ const TagBoxEditorComponent = ({
|
||||||
<TagBox
|
<TagBox
|
||||||
{...editorOptions}
|
{...editorOptions}
|
||||||
{...(setDefaultValue ? { defaultValue: val } : { value: val })}
|
{...(setDefaultValue ? { defaultValue: val } : { value: val })}
|
||||||
dataSource={dataSource}
|
dataSource={editorOptions?.dataSource}
|
||||||
valueExpr={lookupDto?.valueExpr}
|
valueExpr={lookupDto?.valueExpr}
|
||||||
displayExpr={lookupDto?.displayExpr}
|
displayExpr={lookupDto?.displayExpr}
|
||||||
showClearButton={options?.showClearButton}
|
showClearButton={options?.showClearButton}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import { PermissionResults, RowMode, SimpleItemWithColData } from './types'
|
||||||
import { EditingFormItemDto, GridDto, PlatformEditorTypes } from '@/proxy/form/models'
|
import { EditingFormItemDto, GridDto, PlatformEditorTypes } from '@/proxy/form/models'
|
||||||
import { getAccessDeniedPath } from '@/utils/routing'
|
import { getAccessDeniedPath } from '@/utils/routing'
|
||||||
import { ROUTES_ENUM } from '@/routes/route.constant'
|
import { ROUTES_ENUM } from '@/routes/route.constant'
|
||||||
|
import { useLookupDataSource } from '../form/useLookupDataSource'
|
||||||
|
|
||||||
const useGridData = (props: {
|
const useGridData = (props: {
|
||||||
mode: RowMode
|
mode: RowMode
|
||||||
|
|
@ -49,6 +50,7 @@ const useGridData = (props: {
|
||||||
isSubForm,
|
isSubForm,
|
||||||
})
|
})
|
||||||
const { createSelectDataSource } = useListFormCustomDataSource({})
|
const { createSelectDataSource } = useListFormCustomDataSource({})
|
||||||
|
const { getLookupDataSource } = useLookupDataSource({ listFormCode, isSubForm })
|
||||||
|
|
||||||
const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
@ -220,6 +222,8 @@ const useGridData = (props: {
|
||||||
})
|
})
|
||||||
.map((i: EditingFormItemDto) => {
|
.map((i: EditingFormItemDto) => {
|
||||||
let editorOptions = {}
|
let editorOptions = {}
|
||||||
|
const colData = gridDto.columnFormats.find((x) => x.fieldName === i.dataField)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
editorOptions = i.editorOptions && JSON.parse(i.editorOptions)
|
editorOptions = i.editorOptions && JSON.parse(i.editorOptions)
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
@ -243,8 +247,17 @@ const useGridData = (props: {
|
||||||
i.editorType2 == PlatformEditorTypes.dxGridBox ? 'dxDropDownBox' : i.editorType2,
|
i.editorType2 == PlatformEditorTypes.dxGridBox ? 'dxDropDownBox' : i.editorType2,
|
||||||
colSpan: i.colSpan,
|
colSpan: i.colSpan,
|
||||||
isRequired: i.isRequired,
|
isRequired: i.isRequired,
|
||||||
editorOptions,
|
editorOptions: {
|
||||||
colData: gridDto?.columnFormats.find((x) => x.fieldName === i.dataField),
|
...editorOptions,
|
||||||
|
...(colData?.lookupDto?.dataSourceType
|
||||||
|
? {
|
||||||
|
dataSource: getLookupDataSource(colData?.editorOptions, colData),
|
||||||
|
valueExpr: colData?.lookupDto?.valueExpr?.toLowerCase(),
|
||||||
|
displayExpr: colData?.lookupDto?.displayExpr?.toLowerCase(),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
colData,
|
||||||
tagBoxOptions: i.tagBoxOptions,
|
tagBoxOptions: i.tagBoxOptions,
|
||||||
gridBoxOptions: i.gridBoxOptions,
|
gridBoxOptions: i.gridBoxOptions,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import CustomStore from 'devextreme/data/custom_store'
|
||||||
import { PermissionResults, SimpleItemWithColData } from '../form/types'
|
import { PermissionResults, SimpleItemWithColData } from '../form/types'
|
||||||
import { usePermission } from '@/utils/hooks/usePermission'
|
import { usePermission } from '@/utils/hooks/usePermission'
|
||||||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
||||||
|
import { useLookupDataSource } from '../form/useLookupDataSource'
|
||||||
|
|
||||||
interface CardProps {
|
interface CardProps {
|
||||||
listFormCode: string
|
listFormCode: string
|
||||||
|
|
@ -34,6 +35,7 @@ const CardItem = ({
|
||||||
listFormCode,
|
listFormCode,
|
||||||
dataSource,
|
dataSource,
|
||||||
refreshData,
|
refreshData,
|
||||||
|
getCachedLookupDataSource, // 🔹 Card’dan gelen cache fonksiyonu
|
||||||
}: {
|
}: {
|
||||||
isSubForm?: boolean
|
isSubForm?: boolean
|
||||||
row: any
|
row: any
|
||||||
|
|
@ -41,6 +43,7 @@ const CardItem = ({
|
||||||
listFormCode: string
|
listFormCode: string
|
||||||
dataSource: CustomStore
|
dataSource: CustomStore
|
||||||
refreshData: () => void
|
refreshData: () => void
|
||||||
|
getCachedLookupDataSource: (editorOptions: any, colData: any) => any
|
||||||
}) => {
|
}) => {
|
||||||
const [formData, setFormData] = useState(row)
|
const [formData, setFormData] = useState(row)
|
||||||
const refForm = useRef<FormDx>(null)
|
const refForm = useRef<FormDx>(null)
|
||||||
|
|
@ -51,41 +54,33 @@ const CardItem = ({
|
||||||
const keyField = gridDto.gridOptions.keyFieldName
|
const keyField = gridDto.gridOptions.keyFieldName
|
||||||
const rowId = row[keyField!]
|
const rowId = row[keyField!]
|
||||||
|
|
||||||
|
// Form Items
|
||||||
const formItems: GroupItem[] = useMemo(() => {
|
const formItems: GroupItem[] = useMemo(() => {
|
||||||
if (!gridDto) return []
|
if (!gridDto) return []
|
||||||
|
|
||||||
return gridDto?.gridOptions.editingFormDto
|
return gridDto.gridOptions.editingFormDto
|
||||||
?.sort((a: any, b: any) => {
|
?.sort((a, b) => (a.order >= b.order ? 1 : -1))
|
||||||
return a.order >= b.order ? 1 : -1
|
.map((e) => {
|
||||||
})
|
|
||||||
.map((e: any) => {
|
|
||||||
return {
|
return {
|
||||||
itemType: e.itemType,
|
itemType: e.itemType,
|
||||||
colCount: e.colCount,
|
colCount: e.colCount,
|
||||||
colSpan: e.colSpan,
|
colSpan: e.colSpan,
|
||||||
caption: e.caption,
|
caption: e.caption,
|
||||||
items: e.items
|
items: e.items
|
||||||
?.sort((a: any, b: any) => {
|
?.sort((a, b) => (a.order >= b.order ? 1 : -1))
|
||||||
return a.order >= b.order ? 1 : -1
|
|
||||||
})
|
|
||||||
.map((i: EditingFormItemDto) => {
|
.map((i: EditingFormItemDto) => {
|
||||||
let editorOptions = {}
|
let editorOptions = {}
|
||||||
|
const colData = gridDto.columnFormats.find((x) => x.fieldName === i.dataField)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
editorOptions = i.editorOptions && JSON.parse(i.editorOptions)
|
editorOptions = i.editorOptions && JSON.parse(i.editorOptions)
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
const item: SimpleItemWithColData = {
|
const item: SimpleItemWithColData = {
|
||||||
canRead:
|
canRead: colData?.canRead ?? false,
|
||||||
gridDto.columnFormats.find((x: any) => x.fieldName === i.dataField)?.canRead ??
|
canUpdate: colData?.canUpdate ?? false,
|
||||||
false,
|
canCreate: colData?.canCreate ?? false,
|
||||||
canUpdate:
|
canExport: colData?.canExport ?? false,
|
||||||
gridDto.columnFormats.find((x: any) => x.fieldName === i.dataField)?.canUpdate ??
|
|
||||||
false,
|
|
||||||
canCreate:
|
|
||||||
gridDto.columnFormats.find((x: any) => x.fieldName === i.dataField)?.canCreate ??
|
|
||||||
false,
|
|
||||||
canExport:
|
|
||||||
gridDto.columnFormats.find((x: any) => x.fieldName === i.dataField)?.canExport ??
|
|
||||||
false,
|
|
||||||
dataField: i.dataField,
|
dataField: i.dataField,
|
||||||
name: i.dataField,
|
name: i.dataField,
|
||||||
editorType2: i.editorType2,
|
editorType2: i.editorType2,
|
||||||
|
|
@ -93,8 +88,17 @@ const CardItem = ({
|
||||||
i.editorType2 == PlatformEditorTypes.dxGridBox ? 'dxDropDownBox' : i.editorType2,
|
i.editorType2 == PlatformEditorTypes.dxGridBox ? 'dxDropDownBox' : i.editorType2,
|
||||||
colSpan: i.colSpan,
|
colSpan: i.colSpan,
|
||||||
isRequired: i.isRequired,
|
isRequired: i.isRequired,
|
||||||
editorOptions,
|
editorOptions: {
|
||||||
colData: gridDto.columnFormats.find((x) => x.fieldName === i.dataField),
|
...editorOptions,
|
||||||
|
...(colData?.lookupDto?.dataSourceType
|
||||||
|
? {
|
||||||
|
dataSource: getCachedLookupDataSource(colData?.editorOptions, colData),
|
||||||
|
valueExpr: colData?.lookupDto?.valueExpr?.toLowerCase(),
|
||||||
|
displayExpr: colData?.lookupDto?.displayExpr?.toLowerCase(),
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
},
|
||||||
|
colData,
|
||||||
tagBoxOptions: i.tagBoxOptions,
|
tagBoxOptions: i.tagBoxOptions,
|
||||||
gridBoxOptions: i.gridBoxOptions,
|
gridBoxOptions: i.gridBoxOptions,
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +113,7 @@ const CardItem = ({
|
||||||
}),
|
}),
|
||||||
} as GroupItem
|
} as GroupItem
|
||||||
})
|
})
|
||||||
}, [gridDto])
|
}, [gridDto, getCachedLookupDataSource])
|
||||||
|
|
||||||
const permissionResults: PermissionResults = {
|
const permissionResults: PermissionResults = {
|
||||||
c:
|
c:
|
||||||
|
|
@ -186,6 +190,23 @@ const Card = ({ listFormCode, searchParams }: CardProps) => {
|
||||||
const [pageSizeOptions, setPageSizeOptions] = useState<Option[]>([])
|
const [pageSizeOptions, setPageSizeOptions] = useState<Option[]>([])
|
||||||
const [dataSource, setDataSource] = useState<CustomStore>()
|
const [dataSource, setDataSource] = useState<CustomStore>()
|
||||||
|
|
||||||
|
// ✅ Lookup cache burada (Card seviyesinde, tüm CardItem’lar ortak kullanır)
|
||||||
|
const { getLookupDataSource } = useLookupDataSource({ listFormCode })
|
||||||
|
const lookupCache = useRef<Map<string, any>>(new Map())
|
||||||
|
|
||||||
|
const getCachedLookupDataSource = useCallback(
|
||||||
|
(editorOptions: any, colData: any) => {
|
||||||
|
const key = colData?.fieldName
|
||||||
|
if (!key) return null
|
||||||
|
|
||||||
|
if (!lookupCache.current.has(key)) {
|
||||||
|
lookupCache.current.set(key, getLookupDataSource(editorOptions, colData))
|
||||||
|
}
|
||||||
|
return lookupCache.current.get(key)
|
||||||
|
},
|
||||||
|
[getLookupDataSource]
|
||||||
|
)
|
||||||
|
|
||||||
const onPageSizeSelect = ({ value }: Option) => {
|
const onPageSizeSelect = ({ value }: Option) => {
|
||||||
setPageSize(value)
|
setPageSize(value)
|
||||||
setCurrentPage(1)
|
setCurrentPage(1)
|
||||||
|
|
@ -231,7 +252,8 @@ const Card = ({ listFormCode, searchParams }: CardProps) => {
|
||||||
if (!gridDto) return
|
if (!gridDto) return
|
||||||
|
|
||||||
const pagerOptions = gridDto.gridOptions.pagerOptionDto
|
const pagerOptions = gridDto.gridOptions.pagerOptionDto
|
||||||
const allowedSizes = pagerOptions?.allowedPageSizes
|
const allowedSizes =
|
||||||
|
pagerOptions?.allowedPageSizes
|
||||||
?.split(',')
|
?.split(',')
|
||||||
.map((s) => Number(s.trim()))
|
.map((s) => Number(s.trim()))
|
||||||
.filter((n) => !isNaN(n) && n > 0) || [10, 20, 50, 100]
|
.filter((n) => !isNaN(n) && n > 0) || [10, 20, 50, 100]
|
||||||
|
|
@ -271,6 +293,7 @@ const Card = ({ listFormCode, searchParams }: CardProps) => {
|
||||||
listFormCode={listFormCode}
|
listFormCode={listFormCode}
|
||||||
dataSource={dataSource}
|
dataSource={dataSource}
|
||||||
refreshData={loadData}
|
refreshData={loadData}
|
||||||
|
getCachedLookupDataSource={getCachedLookupDataSource} // 🔹 Prop olarak veriliyor
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue