State sistemi manuel olarak tetiklenecek hale getirildi.
This commit is contained in:
parent
6517fac26c
commit
809bfb7129
5 changed files with 231 additions and 131 deletions
|
|
@ -7,7 +7,6 @@ using Erp.Platform.Enums;
|
||||||
using Erp.Platform.ListForms.Customization;
|
using Erp.Platform.ListForms.Customization;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Domain.Entities;
|
using Volo.Abp.Domain.Entities;
|
||||||
using Volo.Abp.Domain.Repositories;
|
using Volo.Abp.Domain.Repositories;
|
||||||
|
|
|
||||||
|
|
@ -764,22 +764,23 @@ public class ListFormSeeder_Hr : IDataSeedContributor, ITransientDependency
|
||||||
DataSourceType = UiLookupDataSourceTypeEnum.StaticData,
|
DataSourceType = UiLookupDataSourceTypeEnum.StaticData,
|
||||||
DisplayExpr = "name",
|
DisplayExpr = "name",
|
||||||
ValueExpr = "key",
|
ValueExpr = "key",
|
||||||
LookupQuery = JsonSerializer.Serialize(new LookupDataDto[] {
|
LookupQuery = JsonSerializer.Serialize(new LookupDataDto[]
|
||||||
new () { Key= "â", Name= "â Yıldız" },
|
{
|
||||||
new () { Key= "ğŸ†", Name= "🆠Kupa" },
|
new() { Key = "⭐", Name = "⭐ Yıldız" },
|
||||||
new () { Key= "🥇", Name= "🥇 Altın Madalya" },
|
new() { Key = "🏆", Name = "🏆 Kupa" },
|
||||||
new () { Key= "🥈", Name= "🥈 Gümüş Madalya" },
|
new() { Key = "🥇", Name = "🥇 Altın Madalya" },
|
||||||
new () { Key= "🥉", Name= "🥉 Bronz Madalya" },
|
new() { Key = "🥈", Name = "🥈 Gümüş Madalya" },
|
||||||
new () { Key= "👑", Name= "👑 Taç" },
|
new() { Key = "🥉", Name = "🥉 Bronz Madalya" },
|
||||||
new () { Key= "ğŸ’", Name= "💠Elmas" },
|
new() { Key = "👑", Name = "👑 Taç" },
|
||||||
new () { Key= "💡", Name= "💡 Ampul" },
|
new() { Key = "💎", Name = "💎 Elmas" },
|
||||||
new () { Key= "🔥", Name= "🔥 Ateş" },
|
new() { Key = "💡", Name = "💡 Ampul" },
|
||||||
new () { Key= "âš¡", Name= "âš¡ Şimşek" },
|
new() { Key = "🔥", Name = "🔥 Ateş" },
|
||||||
new () { Key= "ğŸ¯", Name= "🯠Hedef" },
|
new() { Key = "⚡", Name = "⚡ Şimşek" },
|
||||||
new () { Key= "📈", Name= "📈 Grafik" },
|
new() { Key = "🎯", Name = "🎯 Hedef" },
|
||||||
new () { Key= "🚀", Name= "🚀 Roket" },
|
new() { Key = "📈", Name = "📈 Grafik" },
|
||||||
new () { Key= "💪", Name= "💪 Güç" },
|
new() { Key = "🚀", Name = "🚀 Roket" },
|
||||||
new () { Key= "â¤ï¸", Name= "â¤ï¸ Kalp" }
|
new() { Key = "💪", Name = "💪 Güç" },
|
||||||
|
new() { Key = "❤️", Name = "❤️ Kalp" }
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
ColumnCustomizationJson = DefaultColumnCustomizationJson,
|
ColumnCustomizationJson = DefaultColumnCustomizationJson,
|
||||||
|
|
|
||||||
|
|
@ -409,10 +409,11 @@ const Grid = (props: GridProps) => {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// Cascade parent fields mapping'i memoize et - popup açılışını hızlandırır
|
// Cascade parent fields mapping'i memoize et - popup açılışını hızlandırır
|
||||||
const cascadeFieldsMap = useMemo(() => {
|
// Ayrıca parent -> child ilişkisi için reverse map oluştur (performans için)
|
||||||
if (!gridDto) return new Map()
|
const { cascadeFieldsMap, parentToChildrenMap } = useMemo(() => {
|
||||||
|
if (!gridDto) return { cascadeFieldsMap: new Map(), parentToChildrenMap: new Map() }
|
||||||
|
|
||||||
const map = new Map<
|
const cascadeMap = new Map<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
parentFields: string[]
|
parentFields: string[]
|
||||||
|
|
@ -420,16 +421,31 @@ const Grid = (props: GridProps) => {
|
||||||
}
|
}
|
||||||
>()
|
>()
|
||||||
|
|
||||||
|
const parentChildMap = new Map<string, Set<string>>()
|
||||||
|
|
||||||
gridDto.columnFormats.forEach((col) => {
|
gridDto.columnFormats.forEach((col) => {
|
||||||
if (col.lookupDto?.cascadeParentFields && col.fieldName) {
|
if (col.lookupDto?.cascadeParentFields && col.fieldName) {
|
||||||
map.set(col.fieldName, {
|
const parentFields = col.lookupDto.cascadeParentFields.split(',').map((f: string) => f.trim())
|
||||||
parentFields: col.lookupDto.cascadeParentFields.split(',').map((f: string) => f.trim()),
|
const childFields = col.lookupDto.cascadeEmptyFields?.split(',').map((f: string) => f.trim())
|
||||||
childFields: col.lookupDto.cascadeEmptyFields?.split(',').map((f: string) => f.trim()),
|
|
||||||
|
cascadeMap.set(col.fieldName, {
|
||||||
|
parentFields,
|
||||||
|
childFields,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Her parent field için, hangi childları etkilediğini kaydet
|
||||||
|
parentFields.forEach((parentField) => {
|
||||||
|
if (!parentChildMap.has(parentField)) {
|
||||||
|
parentChildMap.set(parentField, new Set())
|
||||||
|
}
|
||||||
|
if (col.fieldName) {
|
||||||
|
parentChildMap.get(parentField)!.add(col.fieldName)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return map
|
return { cascadeFieldsMap: cascadeMap, parentToChildrenMap: parentChildMap }
|
||||||
}, [gridDto])
|
}, [gridDto])
|
||||||
|
|
||||||
const onEditorPreparing = useCallback(
|
const onEditorPreparing = useCallback(
|
||||||
|
|
@ -439,50 +455,48 @@ const Grid = (props: GridProps) => {
|
||||||
.flatMap((group) => group.items || [])
|
.flatMap((group) => group.items || [])
|
||||||
.find((i) => i.dataField === editor.dataField)
|
.find((i) => i.dataField === editor.dataField)
|
||||||
|
|
||||||
// Cascade disabled mantığı
|
// Cascade mantığı
|
||||||
const cascadeInfo = cascadeFieldsMap.get(editor.dataField)
|
const cascadeInfo = cascadeFieldsMap.get(editor.dataField)
|
||||||
if (cascadeInfo) {
|
if (cascadeInfo) {
|
||||||
const parentFields = cascadeInfo.parentFields
|
const parentFields = cascadeInfo.parentFields
|
||||||
|
const childFields = cascadeInfo.childFields
|
||||||
|
const affectedChildren = parentToChildrenMap.get(editor.dataField!)
|
||||||
const prevHandler = editor.editorOptions.onValueChanged
|
const prevHandler = editor.editorOptions.onValueChanged
|
||||||
|
|
||||||
editor.editorOptions.onValueChanged = (e: any) => {
|
editor.editorOptions.onValueChanged = (e: any) => {
|
||||||
if (prevHandler) prevHandler(e)
|
prevHandler?.(e)
|
||||||
|
|
||||||
// Parent field değiştiğinde tüm cascade childları kontrol et
|
|
||||||
const grid = editor.component
|
const grid = editor.component
|
||||||
const rowKey = grid.option('editing.editRowKey')
|
const rowKey = grid.option('editing.editRowKey')
|
||||||
const rowIndex = grid.getRowIndexByKey(rowKey)
|
const rowIndex = grid.getRowIndexByKey(rowKey)
|
||||||
const rowData = grid.getVisibleRows().find((r) => r.key === rowKey)?.data || {}
|
|
||||||
|
|
||||||
// Bu field bir parent ise, child fieldleri temizle
|
// Parent field değiştiğinde child fieldleri temizle
|
||||||
if (cascadeInfo.childFields) {
|
if (childFields && rowIndex >= 0) {
|
||||||
cascadeInfo.childFields.forEach((childField: string) => {
|
childFields.forEach((childField: string) => {
|
||||||
if (rowIndex >= 0) {
|
grid.cellValue(rowIndex, childField, null)
|
||||||
grid.cellValue(rowIndex, childField, null)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tüm cascade fieldlerin disabled durumlarını güncelle - sadece değişen field için
|
// Sadece bu parent'tan etkilenen childların disabled durumunu güncelle
|
||||||
const popup = grid.option('editing.popup')
|
if (affectedChildren?.size) {
|
||||||
if (popup) {
|
|
||||||
const formInstance = grid.option('editing.form') as any
|
const formInstance = grid.option('editing.form') as any
|
||||||
if (formInstance && formInstance.getEditor) {
|
if (formInstance?.getEditor) {
|
||||||
// Sadece bu field'den etkilenen childları güncelle
|
const visibleRows = grid.getVisibleRows()
|
||||||
cascadeFieldsMap.forEach((info, fieldName) => {
|
const rowData = visibleRows.find((r) => r.key === rowKey)?.data
|
||||||
if (info.parentFields.includes(editor.dataField!)) {
|
|
||||||
const shouldDisable = info.parentFields.some((pf: string) => !rowData[pf])
|
if (rowData) {
|
||||||
try {
|
affectedChildren.forEach((childFieldName: string) => {
|
||||||
const editorInstance = formInstance.getEditor(fieldName)
|
const childInfo = cascadeFieldsMap.get(childFieldName)
|
||||||
if (editorInstance) {
|
if (childInfo) {
|
||||||
editorInstance.option('disabled', shouldDisable)
|
const shouldDisable = childInfo.parentFields.some(
|
||||||
}
|
(pf: string) => !rowData[pf],
|
||||||
} catch (err) {
|
)
|
||||||
console.debug('Cascade disabled update skipped for', fieldName, err)
|
try {
|
||||||
|
formInstance.getEditor(childFieldName)?.option('disabled', shouldDisable)
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -490,10 +504,10 @@ const Grid = (props: GridProps) => {
|
||||||
// İlk açılışta disabled durumunu kontrol et
|
// İlk açılışta disabled durumunu kontrol et
|
||||||
const grid = editor.component
|
const grid = editor.component
|
||||||
const rowKey = grid.option('editing.editRowKey')
|
const rowKey = grid.option('editing.editRowKey')
|
||||||
const rowData = grid.getVisibleRows().find((r) => r.key === rowKey)?.data || {}
|
const visibleRows = grid.getVisibleRows()
|
||||||
const shouldDisable = parentFields.some((pf: string) => !rowData[pf])
|
const rowData = visibleRows.find((r) => r.key === rowKey)?.data
|
||||||
|
|
||||||
if (shouldDisable) {
|
if (rowData && parentFields.some((pf: string) => !rowData[pf])) {
|
||||||
editor.editorOptions.disabled = true
|
editor.editorOptions.disabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -800,43 +814,34 @@ const Grid = (props: GridProps) => {
|
||||||
refListFormCode.current = listFormCode
|
refListFormCode.current = listFormCode
|
||||||
}, [listFormCode])
|
}, [listFormCode])
|
||||||
|
|
||||||
// StateStoring fonksiyonlarını ref'e kaydet - her render'da yeniden oluşturulmasın
|
// Component mount olduğunda state'i bir kez yükle
|
||||||
const customSaveStateRef = useRef(customSaveState)
|
|
||||||
const customLoadStateRef = useRef(customLoadState)
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
customSaveStateRef.current = customSaveState
|
if (!gridDto || !gridRef?.current || !gridDataSource || !columnData) return
|
||||||
customLoadStateRef.current = customLoadState
|
|
||||||
}, [customSaveState, customLoadState])
|
|
||||||
|
|
||||||
// StateStoring'i sadece gridDto değiştiğinde ayarla
|
const instance = gridRef?.current?.instance()
|
||||||
|
if (instance) {
|
||||||
|
customLoadState().then((state) => {
|
||||||
|
if (state) {
|
||||||
|
instance.state(state)
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error('State load error:', err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [gridDto, gridDataSource, columnData])
|
||||||
|
|
||||||
|
// StateStoring'i devre dışı bırak - manuel kaydetme kullanılacak
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!gridDto || !gridRef?.current) return
|
if (!gridDto || !gridRef?.current) return
|
||||||
|
|
||||||
const instance = gridRef?.current?.instance()
|
const instance = gridRef?.current?.instance()
|
||||||
if (instance) {
|
if (instance) {
|
||||||
const stateStoring: IStateStoringProps = {
|
// Otomatik state kaydetme/yükleme kapalı
|
||||||
enabled: gridDto?.gridOptions.stateStoringDto?.enabled,
|
instance.option('stateStoring', {
|
||||||
type: gridDto?.gridOptions.stateStoringDto?.type,
|
enabled: false,
|
||||||
savingTimeout: gridDto?.gridOptions.stateStoringDto?.savingTimeout,
|
})
|
||||||
storageKey: gridDto?.gridOptions.stateStoringDto?.storageKey,
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
gridDto?.gridOptions.stateStoringDto?.enabled &&
|
|
||||||
gridDto?.gridOptions.stateStoringDto?.type === 'custom'
|
|
||||||
) {
|
|
||||||
// Ref'i kullan, direkt fonksiyon yerine
|
|
||||||
stateStoring.customSave = (state: any) => customSaveStateRef.current(state)
|
|
||||||
stateStoring.customLoad = () => customLoadStateRef.current()
|
|
||||||
}
|
|
||||||
instance.option('stateStoring', stateStoring)
|
|
||||||
|
|
||||||
// State'i yükle - dataSource ve columns hazır olduğunda
|
|
||||||
if (gridDataSource && columnData) {
|
|
||||||
instance.state(undefined) // undefined = reload from storage
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [gridDto, gridDataSource, columnData]) // dataSource ve columns hazır olduğunda state yükle
|
}, [gridDto])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refListFormCode.current = listFormCode
|
refListFormCode.current = listFormCode
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import {
|
||||||
import { useFilters } from './useFilters'
|
import { useFilters } from './useFilters'
|
||||||
import WidgetGroup from '@/components/common/WidgetGroup'
|
import WidgetGroup from '@/components/common/WidgetGroup'
|
||||||
import { Button, Notification, toast } from '@/components/ui'
|
import { Button, Notification, toast } from '@/components/ui'
|
||||||
import { FaCog, FaTimes, FaUndo } from 'react-icons/fa'
|
import { FaCog, FaSave, FaTimes, FaUndo } from 'react-icons/fa'
|
||||||
import { usePermission } from '@/utils/hooks/usePermission'
|
import { usePermission } from '@/utils/hooks/usePermission'
|
||||||
import { ROUTES_ENUM } from '@/routes/route.constant'
|
import { ROUTES_ENUM } from '@/routes/route.constant'
|
||||||
import { usePWA } from '@/utils/hooks/usePWA'
|
import { usePWA } from '@/utils/hooks/usePWA'
|
||||||
|
|
@ -74,6 +74,11 @@ const Pivot = (props: PivotProps) => {
|
||||||
const [gridDataSource, setGridDataSource] = useState<CustomStore<any, any>>()
|
const [gridDataSource, setGridDataSource] = useState<CustomStore<any, any>>()
|
||||||
const [columnData, setColumnData] = useState<GridColumnData[]>()
|
const [columnData, setColumnData] = useState<GridColumnData[]>()
|
||||||
|
|
||||||
|
// StateStoring için storageKey'i memoize et
|
||||||
|
const storageKey = useMemo(() => {
|
||||||
|
return gridDto?.gridOptions.stateStoringDto?.storageKey ?? ''
|
||||||
|
}, [gridDto?.gridOptions.stateStoringDto?.storageKey])
|
||||||
|
|
||||||
const { filterToolbarData, ...filterData } = useFilters({
|
const { filterToolbarData, ...filterData } = useFilters({
|
||||||
gridDto,
|
gridDto,
|
||||||
gridRef,
|
gridRef,
|
||||||
|
|
@ -159,19 +164,32 @@ const Pivot = (props: PivotProps) => {
|
||||||
const resetPivotGridState = useCallback(async () => {
|
const resetPivotGridState = useCallback(async () => {
|
||||||
const grid = gridRef.current?.instance()
|
const grid = gridRef.current?.instance()
|
||||||
if (grid) {
|
if (grid) {
|
||||||
// kullaniciya ait kayitli grid state i sil customizationData boşalt silinsin.
|
// State'i veritabanından sil
|
||||||
await postListFormCustomization({
|
await postListFormCustomization({
|
||||||
listFormCode: listFormCode,
|
listFormCode: listFormCode,
|
||||||
customizationType: ListFormCustomizationTypeEnum.GridState,
|
customizationType: ListFormCustomizationTypeEnum.GridState,
|
||||||
filterName: `pivot-${gridRef.current?.instance()?.option('stateStoring')?.storageKey ?? ''}`,
|
filterName: `pivot-${storageKey}`,
|
||||||
customizationData: '',
|
customizationData: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
await props.refreshGridDto()
|
// DataSource'u resetle
|
||||||
|
const ds = grid.getDataSource()
|
||||||
|
if (ds && typeof ds.state === 'function') {
|
||||||
|
ds.state(null) // State'i temizle
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filtreleri temizle
|
||||||
clearPivotFilters()
|
clearPivotFilters()
|
||||||
moveAllFieldsToFilterArea()
|
setGridPanelColor('transparent')
|
||||||
|
|
||||||
|
toast.push(
|
||||||
|
<Notification type="success" duration={2000}>
|
||||||
|
{translate('::ListForms.ListForm.GridStateReset')}
|
||||||
|
</Notification>,
|
||||||
|
{ placement: 'top-end' },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}, [listFormCode, props, clearPivotFilters, moveAllFieldsToFilterArea])
|
}, [listFormCode, storageKey, clearPivotFilters, translate])
|
||||||
|
|
||||||
const onExporting = useCallback(async (e: PivotGridTypes.ExportingEvent) => {
|
const onExporting = useCallback(async (e: PivotGridTypes.ExportingEvent) => {
|
||||||
e.cancel = true
|
e.cancel = true
|
||||||
|
|
@ -217,13 +235,13 @@ const Pivot = (props: PivotProps) => {
|
||||||
return postListFormCustomization({
|
return postListFormCustomization({
|
||||||
listFormCode: listFormCode,
|
listFormCode: listFormCode,
|
||||||
customizationType: ListFormCustomizationTypeEnum.GridState,
|
customizationType: ListFormCustomizationTypeEnum.GridState,
|
||||||
filterName: `pivot-${gridRef.current?.instance()?.option('stateStoring')?.storageKey ?? ''}`,
|
filterName: `pivot-${storageKey}`,
|
||||||
customizationData: JSON.stringify(state),
|
customizationData: JSON.stringify(state),
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
setGridPanelColor(statedGridPanelColor)
|
setGridPanelColor(statedGridPanelColor)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[listFormCode],
|
[listFormCode, storageKey],
|
||||||
)
|
)
|
||||||
|
|
||||||
const customLoadState = useCallback(
|
const customLoadState = useCallback(
|
||||||
|
|
@ -231,25 +249,18 @@ const Pivot = (props: PivotProps) => {
|
||||||
return getListFormCustomization(
|
return getListFormCustomization(
|
||||||
listFormCode,
|
listFormCode,
|
||||||
ListFormCustomizationTypeEnum.GridState,
|
ListFormCustomizationTypeEnum.GridState,
|
||||||
`pivot-${gridRef.current?.instance()?.option('stateStoring')?.storageKey ?? ''}`,
|
`pivot-${storageKey}`,
|
||||||
).then((response: any) => {
|
).then((response: any) => {
|
||||||
setGridPanelColor(statedGridPanelColor)
|
|
||||||
if (response.data?.length > 0) {
|
if (response.data?.length > 0) {
|
||||||
|
setGridPanelColor(statedGridPanelColor)
|
||||||
return JSON.parse(response.data[0].customizationData)
|
return JSON.parse(response.data[0].customizationData)
|
||||||
}
|
}
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
[listFormCode],
|
[listFormCode, storageKey],
|
||||||
)
|
)
|
||||||
|
|
||||||
const customSaveStateRef = useRef(customSaveState)
|
|
||||||
const customLoadStateRef = useRef(customLoadState)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
customSaveStateRef.current = customSaveState
|
|
||||||
customLoadStateRef.current = customLoadState
|
|
||||||
}, [customSaveState, customLoadState])
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
refListFormCode.current = listFormCode
|
refListFormCode.current = listFormCode
|
||||||
}, [listFormCode])
|
}, [listFormCode])
|
||||||
|
|
@ -307,7 +318,19 @@ const Pivot = (props: PivotProps) => {
|
||||||
}
|
}
|
||||||
}, [memoizedDataSource])
|
}, [memoizedDataSource])
|
||||||
|
|
||||||
// Pivot dataSource ve fields'i set et + StateStoring ayarla
|
// StateStoring'i devre dışı bırak - manuel kaydetme kullanılacak
|
||||||
|
useEffect(() => {
|
||||||
|
if (!gridDto || !gridRef?.current) return
|
||||||
|
|
||||||
|
const instance = gridRef?.current?.instance()
|
||||||
|
if (instance) {
|
||||||
|
instance.option('stateStoring', {
|
||||||
|
enabled: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [gridDto])
|
||||||
|
|
||||||
|
// Pivot dataSource ve fields'i set et
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!columnData || !gridDataSource || !gridRef?.current || !gridDto) {
|
if (!columnData || !gridDataSource || !gridRef?.current || !gridDto) {
|
||||||
return
|
return
|
||||||
|
|
@ -316,23 +339,7 @@ const Pivot = (props: PivotProps) => {
|
||||||
const instance = gridRef?.current?.instance()
|
const instance = gridRef?.current?.instance()
|
||||||
if (!instance) return
|
if (!instance) return
|
||||||
|
|
||||||
// 1. StateStoring'i ÖNCE ayarla
|
// Default fields'i hazırla
|
||||||
const stateStoring: any = {
|
|
||||||
enabled: gridDto?.gridOptions.stateStoringDto?.enabled,
|
|
||||||
type: gridDto?.gridOptions.stateStoringDto?.type,
|
|
||||||
savingTimeout: gridDto?.gridOptions.stateStoringDto?.savingTimeout,
|
|
||||||
storageKey: gridDto?.gridOptions.stateStoringDto?.storageKey,
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
gridDto?.gridOptions.stateStoringDto?.enabled &&
|
|
||||||
gridDto?.gridOptions.stateStoringDto?.type === 'custom'
|
|
||||||
) {
|
|
||||||
stateStoring.customSave = (state: any) => customSaveStateRef.current(state)
|
|
||||||
stateStoring.customLoad = () => customLoadStateRef.current()
|
|
||||||
}
|
|
||||||
instance.option('stateStoring', stateStoring)
|
|
||||||
|
|
||||||
// 2. Default fields'i hazırla
|
|
||||||
const defaultFields: any = columnData?.map((b) => {
|
const defaultFields: any = columnData?.map((b) => {
|
||||||
return {
|
return {
|
||||||
dataField: b.dataField,
|
dataField: b.dataField,
|
||||||
|
|
@ -350,7 +357,7 @@ const Pivot = (props: PivotProps) => {
|
||||||
} as Field
|
} as Field
|
||||||
})
|
})
|
||||||
|
|
||||||
// 3. DataSource'u ayarla - fields olmadan
|
// DataSource'u ayarla
|
||||||
const dataSource: PivotGridTypes.Properties['dataSource'] = {
|
const dataSource: PivotGridTypes.Properties['dataSource'] = {
|
||||||
remoteOperations: true,
|
remoteOperations: true,
|
||||||
store: gridDataSource,
|
store: gridDataSource,
|
||||||
|
|
@ -358,16 +365,27 @@ const Pivot = (props: PivotProps) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.option('dataSource', dataSource)
|
instance.option('dataSource', dataSource)
|
||||||
|
|
||||||
// 4. DataSource set edildikten SONRA state'i yükle - state fields'i override edecek
|
|
||||||
setTimeout(() => {
|
|
||||||
const ds = instance.getDataSource()
|
|
||||||
if (ds && typeof ds.state === 'function') {
|
|
||||||
ds.state(null) // Bu saved state'teki fields'i kullanacak
|
|
||||||
}
|
|
||||||
}, 50)
|
|
||||||
}, [columnData, gridDataSource, gridDto])
|
}, [columnData, gridDataSource, gridDto])
|
||||||
|
|
||||||
|
// Component mount olduğunda state'i bir kez yükle
|
||||||
|
useEffect(() => {
|
||||||
|
if (!gridDto || !gridRef?.current || !columnData || !gridDataSource) return
|
||||||
|
|
||||||
|
const instance = gridRef?.current?.instance()
|
||||||
|
if (instance) {
|
||||||
|
customLoadState().then((state) => {
|
||||||
|
if (state) {
|
||||||
|
const ds = instance.getDataSource()
|
||||||
|
if (ds && typeof ds.state === 'function') {
|
||||||
|
ds.state(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error('Pivot state load error:', err)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}, [gridDto, columnData, gridDataSource, customLoadState])
|
||||||
|
|
||||||
// Chart binding - sadece bir kez
|
// Chart binding - sadece bir kez
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!gridRef?.current || !chartRef?.current) return
|
if (!gridRef?.current || !chartRef?.current) return
|
||||||
|
|
@ -409,6 +427,39 @@ const Pivot = (props: PivotProps) => {
|
||||||
<FaTimes className="w-3 h-3" /> {translate('::ListForms.ListForm.RemoveFilter')}
|
<FaTimes className="w-3 h-3" /> {translate('::ListForms.ListForm.RemoveFilter')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
variant={'default'}
|
||||||
|
className="text-sm flex items-center gap-1"
|
||||||
|
onClick={() => {
|
||||||
|
const instance = gridRef.current?.instance()
|
||||||
|
if (instance) {
|
||||||
|
const ds = instance.getDataSource()
|
||||||
|
if (ds && typeof ds.state === 'function') {
|
||||||
|
const currentState = ds.state()
|
||||||
|
customSaveState(currentState).then(() => {
|
||||||
|
toast.push(
|
||||||
|
<Notification type="success" duration={2000}>
|
||||||
|
{translate('::ListForms.ListForm.GridStateSaved')}
|
||||||
|
</Notification>,
|
||||||
|
{ placement: 'top-end' },
|
||||||
|
)
|
||||||
|
}).catch(() => {
|
||||||
|
toast.push(
|
||||||
|
<Notification type="danger" duration={2500}>
|
||||||
|
{translate('::ListForms.ListForm.GridStateSaveError')}
|
||||||
|
</Notification>,
|
||||||
|
{ placement: 'top-end' },
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
title={translate('::ListForms.ListForm.SaveGridState')}
|
||||||
|
>
|
||||||
|
<FaSave className="w-3 h-3" /> {translate('::ListForms.ListForm.SaveGridState')}
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
size="xs"
|
size="xs"
|
||||||
variant={'default'}
|
variant={'default'}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import {
|
||||||
ListFormCustomizationForUserDto,
|
ListFormCustomizationForUserDto,
|
||||||
ListFormCustomizationTypeEnum,
|
ListFormCustomizationTypeEnum,
|
||||||
} from '@/proxy/form/models'
|
} from '@/proxy/form/models'
|
||||||
import { getListFormCustomization } from '@/services/list-form-customization.service'
|
import { getListFormCustomization, postListFormCustomization } from '@/services/list-form-customization.service'
|
||||||
import { useLocalization } from '@/utils/hooks/useLocalization'
|
import { useLocalization } from '@/utils/hooks/useLocalization'
|
||||||
import { DataGridRef } from 'devextreme-react/data-grid'
|
import { DataGridRef } from 'devextreme-react/data-grid'
|
||||||
import { PivotGridRef } from 'devextreme-react/pivot-grid'
|
import { PivotGridRef } from 'devextreme-react/pivot-grid'
|
||||||
|
|
@ -173,6 +173,7 @@ const useFilters = ({
|
||||||
const [isImportModalOpen, setIsImportModalOpen] = useState(false)
|
const [isImportModalOpen, setIsImportModalOpen] = useState(false)
|
||||||
|
|
||||||
const filteredGridPanelColor = 'rgba(10, 200, 10, 0.5)' // kullanici tanimli filtre ile filtrelenmis gridin paneline ait renk
|
const filteredGridPanelColor = 'rgba(10, 200, 10, 0.5)' // kullanici tanimli filtre ile filtrelenmis gridin paneline ait renk
|
||||||
|
const statedGridPanelColor = 'rgba(50, 200, 200, 0.5)' // kullanici tanimli gridState ile islem gormus gridin paneline ait renk
|
||||||
|
|
||||||
const grdOpt = gridDto?.gridOptions
|
const grdOpt = gridDto?.gridOptions
|
||||||
const config = useStoreState((state) => state.abpConfig.config)
|
const config = useStoreState((state) => state.abpConfig.config)
|
||||||
|
|
@ -239,6 +240,12 @@ const useFilters = ({
|
||||||
|
|
||||||
//Kullanicinin gridstate kaydi yapmasina izin verilmis ise gridState menu elemanlarini ekle
|
//Kullanicinin gridstate kaydi yapmasina izin verilmis ise gridState menu elemanlarini ekle
|
||||||
if (grdOpt?.stateStoringDto?.enabled) {
|
if (grdOpt?.stateStoringDto?.enabled) {
|
||||||
|
menus.push({
|
||||||
|
text: translate('::ListForms.ListForm.SaveGridState'),
|
||||||
|
id: 'saveGridState',
|
||||||
|
icon: 'save',
|
||||||
|
})
|
||||||
|
|
||||||
menus.push({
|
menus.push({
|
||||||
text: translate('::ListForms.ListForm.ResetGridState'),
|
text: translate('::ListForms.ListForm.ResetGridState'),
|
||||||
id: 'resetGridState',
|
id: 'resetGridState',
|
||||||
|
|
@ -310,6 +317,43 @@ const useFilters = ({
|
||||||
setGridPanelColor('transparent')
|
setGridPanelColor('transparent')
|
||||||
|
|
||||||
setToolbarItemValue(grid, 'selectCustomFilters', '')
|
setToolbarItemValue(grid, 'selectCustomFilters', '')
|
||||||
|
} else if (itemData.id === 'saveGridState') {
|
||||||
|
// Grid'in mevcut state'ini kaydet
|
||||||
|
const grid = gridRef.current?.instance()
|
||||||
|
if (!grid) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentState = grid.state()
|
||||||
|
const storageKey = gridDto?.gridOptions.stateStoringDto?.storageKey ?? ''
|
||||||
|
|
||||||
|
postListFormCustomization({
|
||||||
|
listFormCode: listFormCode,
|
||||||
|
customizationType: ListFormCustomizationTypeEnum.GridState,
|
||||||
|
filterName: `list-${storageKey}`,
|
||||||
|
customizationData: JSON.stringify(currentState),
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
setGridPanelColor(statedGridPanelColor)
|
||||||
|
toast.push(
|
||||||
|
<Notification type="success" duration={2000}>
|
||||||
|
{translate('::ListForms.ListForm.GridStateSaved')}
|
||||||
|
</Notification>,
|
||||||
|
{
|
||||||
|
placement: 'top-end',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.push(
|
||||||
|
<Notification type="danger" duration={2500}>
|
||||||
|
{translate('::ListForms.ListForm.GridStateSaveError')}
|
||||||
|
</Notification>,
|
||||||
|
{
|
||||||
|
placement: 'top-end',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
})
|
||||||
} else if (itemData.id === 'resetGridState') {
|
} else if (itemData.id === 'resetGridState') {
|
||||||
// state ye kaydedilen grid ayarlarini siler ve gridi resetler
|
// state ye kaydedilen grid ayarlarini siler ve gridi resetler
|
||||||
const grid = gridRef.current?.instance()
|
const grid = gridRef.current?.instance()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue