Chart komponenti Fields düzenlemesi
This commit is contained in:
parent
d9f51b1c71
commit
aea724a887
1 changed files with 23 additions and 39 deletions
|
|
@ -9,7 +9,6 @@ import { Helmet } from 'react-helmet'
|
|||
import { useParams, useSearchParams } from 'react-router-dom'
|
||||
import { GridDto } from '@/proxy/form/models'
|
||||
import { usePermission } from '@/utils/hooks/usePermission'
|
||||
import { toast, Notification } from '@/components/ui'
|
||||
import { ROUTES_ENUM } from '@/routes/route.constant'
|
||||
import { usePWA } from '@/utils/hooks/usePWA'
|
||||
import { FaSearch } from 'react-icons/fa'
|
||||
|
|
@ -18,8 +17,6 @@ import { ChartSeriesDto } from '@/proxy/admin/charts/models'
|
|||
import { SelectBoxOption } from '@/types/shared'
|
||||
import { useStoreState } from '@/store/store'
|
||||
import ChartDrawer from './ChartDrawer'
|
||||
import { getListFormFields } from '@/services/admin/list-form-field.service'
|
||||
import { groupBy } from 'lodash'
|
||||
import { ListFormJsonRowDto } from '@/proxy/admin/list-form/models'
|
||||
import { ListFormEditTabs } from '@/proxy/admin/list-form/options'
|
||||
import {
|
||||
|
|
@ -54,13 +51,34 @@ const Chart = (props: ChartProps) => {
|
|||
const [searchParams] = useSearchParams()
|
||||
const [chartOptions, setChartOptions] = useState<any>()
|
||||
const { createSelectDataSource } = useListFormCustomDataSource({} as any)
|
||||
const config = useStoreState((state) => state.abpConfig.config)
|
||||
|
||||
const params = useParams()
|
||||
const _listFormCode = props?.listFormCode ?? params?.listFormCode ?? ''
|
||||
|
||||
const [openDrawer, setOpenDrawer] = useState(false)
|
||||
const [fieldList, setFieldList] = useState<SelectBoxOption[]>([])
|
||||
|
||||
const fieldList = useMemo<SelectBoxOption[]>(() => {
|
||||
if (!gridDto?.columnFormats) {
|
||||
return []
|
||||
}
|
||||
|
||||
const fields = new Map<string, SelectBoxOption>()
|
||||
|
||||
gridDto.columnFormats.forEach((column) => {
|
||||
const fieldName = column.fieldName
|
||||
|
||||
if (!fieldName || fields.has(fieldName)) {
|
||||
return
|
||||
}
|
||||
|
||||
fields.set(fieldName, {
|
||||
value: fieldName,
|
||||
label: column.captionName ? translate('::' + column.captionName) : fieldName,
|
||||
})
|
||||
})
|
||||
|
||||
return Array.from(fields.values())
|
||||
}, [gridDto?.columnFormats, translate])
|
||||
|
||||
// Ana state - Chart bu state'e göre render edilir
|
||||
const [currentSeries, setCurrentSeries] = useState<ChartSeriesDto[]>([])
|
||||
|
|
@ -230,40 +248,6 @@ const Chart = (props: ChartProps) => {
|
|||
[gridDto, urlSearchParams, searchText],
|
||||
)
|
||||
|
||||
const getFields = useCallback(async () => {
|
||||
if (!props.listFormCode) return
|
||||
try {
|
||||
const resp = await getListFormFields({
|
||||
listFormCode: props.listFormCode,
|
||||
sorting: 'ListOrderNo',
|
||||
maxResultCount: 1000,
|
||||
})
|
||||
if (resp.data?.items) {
|
||||
const fieldNames = groupBy(resp?.data?.items, 'fieldName')
|
||||
setFieldList(
|
||||
Object.keys(fieldNames).map((fieldName) => {
|
||||
const firstItem = fieldNames[fieldName][0]
|
||||
const label = firstItem.captionName
|
||||
? translate('::' + firstItem.captionName)
|
||||
: fieldName
|
||||
return { value: fieldName, label }
|
||||
}),
|
||||
)
|
||||
}
|
||||
} catch (error: any) {
|
||||
toast.push(
|
||||
<Notification type="danger" duration={2000}>
|
||||
Alanlar getirilemedi {error.toString()}
|
||||
</Notification>,
|
||||
{ placement: 'top-end' },
|
||||
)
|
||||
}
|
||||
}, [props.listFormCode, translate])
|
||||
|
||||
useEffect(() => {
|
||||
if (props.listFormCode) getFields()
|
||||
}, [props.listFormCode, config])
|
||||
|
||||
const handlePreviewChange = useCallback((series: ChartSeriesDto[]) => {
|
||||
// Preview değişikliklerini anında chart'a yansıt
|
||||
setCurrentSeries(series)
|
||||
|
|
|
|||
Loading…
Reference in a new issue