import React, { useState, useRef, useEffect, useMemo, useCallback } from "react"; 
 | 
import { useNavigate } from 'react-router-dom'; 
 | 
import { 
 | 
    List, 
 | 
    DatagridConfigurable, 
 | 
    SearchInput, 
 | 
    TopToolbar, 
 | 
    SelectColumnsButton, 
 | 
    EditButton, 
 | 
    FilterButton, 
 | 
    CreateButton, 
 | 
    ExportButton, 
 | 
    BulkDeleteButton, 
 | 
    WrapperField, 
 | 
    useRecordContext, 
 | 
    useTranslate, 
 | 
    useListContext, 
 | 
    useCreatePath, 
 | 
    TextField, 
 | 
    NumberField, 
 | 
    DateField, 
 | 
    BooleanField, 
 | 
    ReferenceField, 
 | 
    TextInput, 
 | 
    DateTimeInput, 
 | 
    DateInput, 
 | 
    SelectInput, 
 | 
    NumberInput, 
 | 
    DeleteButton, 
 | 
} from 'react-admin'; 
 | 
import { Box, Typography, Card, Stack } from '@mui/material'; 
 | 
import { styled } from '@mui/material/styles'; 
 | 
import ConfigCreate from "./ConfigCreate"; 
 | 
import ConfigPanel from "./ConfigPanel"; 
 | 
import EmptyData from "../components/EmptyData"; 
 | 
import MyCreateButton from "../components/MyCreateButton"; 
 | 
import MyExportButton from '../components/MyExportButton'; 
 | 
import PageDrawer from "../components/PageDrawer"; 
 | 
import MyField from "../components/MyField"; 
 | 
import { PAGE_DRAWER_WIDTH, OPERATE_MODE, DEFAULT_PAGE_SIZE } from '@/config/setting'; 
 | 
import * as Common from '@/utils/common' 
 | 
  
 | 
const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ 
 | 
    '& .css-1vooibu-MuiSvgIcon-root': { 
 | 
        height: '.9em' 
 | 
    }, 
 | 
    '& .RaDatagrid-row': { 
 | 
        cursor: 'auto' 
 | 
    }, 
 | 
    '& .column-name': { 
 | 
    }, 
 | 
    '& .opt': { 
 | 
        width: 200 
 | 
    }, 
 | 
})); 
 | 
  
 | 
const filters = [ 
 | 
    <SearchInput source="condition" alwaysOn />, 
 | 
    <DateInput label='common.time.after' source="timeStart" alwaysOn />, 
 | 
    <DateInput label='common.time.before' source="timeEnd" alwaysOn />, 
 | 
    <TextInput source="uuid" label="table.field.config.uuid" />, 
 | 
    <TextInput source="name" label="table.field.config.name" />, 
 | 
    <TextInput source="flag" label="table.field.config.flag" />, 
 | 
    <SelectInput source="type" label="table.field.config.type" 
 | 
        choices={[ 
 | 
            { id: 1, name: 'boolean' }, 
 | 
            { id: 2, name: 'number' }, 
 | 
            { id: 3, name: 'string' }, 
 | 
            { id: 4, name: 'json' }, 
 | 
            { id: 5, name: 'date' }, 
 | 
        ]} 
 | 
    />, 
 | 
    <TextInput source="val" label="table.field.config.val" />, 
 | 
    <TextInput source="content" label="table.field.config.content" />, 
 | 
  
 | 
    <TextInput label="common.field.memo" source="memo" />, 
 | 
    <SelectInput 
 | 
        label="common.field.status" 
 | 
        source="status" 
 | 
        choices={[ 
 | 
            { id: '1', name: 'common.enums.statusTrue' }, 
 | 
            { id: '0', name: 'common.enums.statusFalse' }, 
 | 
        ]} 
 | 
        resettable 
 | 
    />, 
 | 
] 
 | 
  
 | 
const ConfigList = () => { 
 | 
    const translate = useTranslate(); 
 | 
  
 | 
    const [createDialog, setCreateDialog] = useState(false); 
 | 
    const [drawerVal, setDrawerVal] = useState(false); 
 | 
  
 | 
    return ( 
 | 
        <Box display="flex"> 
 | 
            <List 
 | 
                sx={{ 
 | 
                    flexGrow: 1, 
 | 
                    transition: (theme) => 
 | 
                        theme.transitions.create(['all'], { 
 | 
                            duration: theme.transitions.duration.enteringScreen, 
 | 
                        }), 
 | 
                    marginRight: !!drawerVal ? `${PAGE_DRAWER_WIDTH}px` : 0, 
 | 
                }} 
 | 
                title={"menu.config"} 
 | 
                empty={<EmptyData onClick={() => { setCreateDialog(true) }} />} 
 | 
                filters={filters} 
 | 
                sort={{ field: "create_time", order: "desc" }} 
 | 
                actions={( 
 | 
                    <TopToolbar> 
 | 
                        <FilterButton /> 
 | 
                        <MyCreateButton onClick={() => { setCreateDialog(true) }} /> 
 | 
                        <SelectColumnsButton preferenceKey='config' /> 
 | 
                        {/* <ExportButton /> */} 
 | 
                        <MyExportButton /> 
 | 
                    </TopToolbar> 
 | 
                )} 
 | 
                perPage={DEFAULT_PAGE_SIZE} 
 | 
            > 
 | 
                <StyledDatagrid 
 | 
                    preferenceKey='config' 
 | 
                    bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />} 
 | 
                    rowClick={(id, resource, record) => false} 
 | 
                    expand={() => <ConfigPanel />} 
 | 
                    expandSingle={true} 
 | 
                    omit={['id', 'createTime', 'memo']} 
 | 
                > 
 | 
                    <NumberField source="id" /> 
 | 
                    <TextField source="uuid" label="table.field.config.uuid" /> 
 | 
                    <MyField source="name" label="table.field.config.name" 
 | 
                        onClick={(event, record, val) => { 
 | 
                            event.stopPropagation(); 
 | 
                            setDrawerVal(!!drawerVal && drawerVal === val ? null : val); 
 | 
                        }} 
 | 
                    /> 
 | 
                    <TextField source="flag" label="table.field.config.flag" /> 
 | 
                    <TextField source="type$" label="table.field.config.type" sortable={false} /> 
 | 
                    <TextField source="val" label="table.field.config.val" /> 
 | 
  
 | 
                    <DateField source="updateTime" label="common.field.updateTime" showTime /> 
 | 
                    <DateField source="createTime" label="common.field.createTime" showTime /> 
 | 
                    <BooleanField source="statusBool" label="common.field.status" sortable={false} /> 
 | 
                    <TextField source="memo" label="common.field.memo" sortable={false} /> 
 | 
                    <WrapperField cellClassName="opt" label="common.field.opt"> 
 | 
                        <EditButton sx={{ padding: '1px', fontSize: '.75rem' }} /> 
 | 
                        <DeleteButton sx={{ padding: '1px', fontSize: '.75rem' }} mutationMode={OPERATE_MODE} /> 
 | 
                    </WrapperField> 
 | 
                </StyledDatagrid> 
 | 
            </List> 
 | 
            <ConfigCreate 
 | 
                open={createDialog} 
 | 
                setOpen={setCreateDialog} 
 | 
            /> 
 | 
            <PageDrawer 
 | 
                title='Config Detail' 
 | 
                drawerVal={drawerVal} 
 | 
                setDrawerVal={setDrawerVal} 
 | 
            > 
 | 
            </PageDrawer> 
 | 
        </Box> 
 | 
    ) 
 | 
} 
 | 
  
 | 
export default ConfigList; 
 |