| | |
| | | import React, { useState, useRef, useEffect, useMemo, useCallback } from "react"; |
| | | import { useNavigate } from 'react-router-dom'; |
| | | import React, { useState } from "react"; |
| | | import { |
| | | List, |
| | | DatagridConfigurable, |
| | | SearchInput, |
| | | TopToolbar, |
| | | SelectColumnsButton, |
| | | EditButton, |
| | | FilterButton, |
| | | CreateButton, |
| | | ExportButton, |
| | | BulkDeleteButton, |
| | | WrapperField, |
| | | useRecordContext, |
| | | useTranslate, |
| | | useNotify, |
| | | useListContext, |
| | | FunctionField, |
| | | TextField, |
| | | NumberField, |
| | | DateField, |
| | | BooleanField, |
| | | ReferenceField, |
| | | TextInput, |
| | | DateTimeInput, |
| | | DateInput, |
| | | SelectInput, |
| | | NumberInput, |
| | | ReferenceInput, |
| | | ReferenceArrayInput, |
| | | AutocompleteInput, |
| | | DeleteButton, |
| | | } from 'react-admin'; |
| | | import { Box, Typography, Card, Stack } from '@mui/material'; |
| | | import { Box, Chip } from '@mui/material'; |
| | | import { styled } from '@mui/material/styles'; |
| | | import IntegrationRecordCreate from "./IntegrationRecordCreate"; |
| | | import IntegrationRecordPanel from "./IntegrationRecordPanel"; |
| | | import IntegrationRecordDetail from "./IntegrationRecordDetail"; |
| | | import EmptyDataLoader from "../components/EmptyDataLoader"; |
| | | 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'; |
| | | import { PAGE_DRAWER_WIDTH, DEFAULT_PAGE_SIZE } from '@/config/setting'; |
| | | import { format } from 'date-fns'; |
| | | import rowSx from './rowSx'; |
| | | |
| | | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ |
| | | '& .css-1vooibu-MuiSvgIcon-root': { |
| | |
| | | '& .RaDatagrid-row': { |
| | | cursor: 'auto' |
| | | }, |
| | | '& .column-name': { |
| | | '& .column-url': { |
| | | maxWidth: '16em', |
| | | overflow: 'hidden', |
| | | textOverflow: 'ellipsis', |
| | | whiteSpace: 'nowrap', |
| | | }, |
| | | '& .column-request': { |
| | | maxWidth: '18em', |
| | | overflow: 'hidden', |
| | | textOverflow: 'ellipsis', |
| | | whiteSpace: 'nowrap', |
| | | }, |
| | | '& .column-response': { |
| | | maxWidth: '18em', |
| | | overflow: 'hidden', |
| | | textOverflow: 'ellipsis', |
| | | whiteSpace: 'nowrap', |
| | | }, |
| | | '& .column-costMs': { |
| | | maxWidth: '9em', |
| | | }, |
| | | '& .opt': { |
| | | width: 200 |
| | | }, |
| | | '& .RaDatagrid-thead': { |
| | | borderLeftColor: 'transparent', |
| | | borderLeftWidth: 5, |
| | | borderLeftStyle: 'solid', |
| | | }, |
| | | })); |
| | | |
| | |
| | | ] |
| | | |
| | | const IntegrationRecordList = () => { |
| | | const translate = useTranslate(); |
| | | |
| | | const [createDialog, setCreateDialog] = useState(false); |
| | | const [drawerVal, setDrawerVal] = useState(false); |
| | | |
| | |
| | | actions={( |
| | | <TopToolbar> |
| | | <FilterButton /> |
| | | <MyCreateButton onClick={() => { setCreateDialog(true) }} /> |
| | | <SelectColumnsButton preferenceKey='integrationRecord' /> |
| | | <MyExportButton /> |
| | | </TopToolbar> |
| | |
| | | > |
| | | <StyledDatagrid |
| | | preferenceKey='integrationRecord' |
| | | bulkActionButtons={() => <BulkDeleteButton mutationMode={OPERATE_MODE} />} |
| | | rowClick={(id, resource, record) => false} |
| | | expand={() => <IntegrationRecordPanel />} |
| | | expandSingle={true} |
| | | omit={['id', 'createTime', 'createBy', 'memo']} |
| | | bulkActionButtons={false} |
| | | rowClick={(id, resource, record) => { |
| | | setDrawerVal(!!drawerVal && drawerVal === record ? null : record); |
| | | return false; |
| | | }} |
| | | omit={['id', 'uuid', 'appkey', 'direction', 'timestamp', 'updateTime', 'memo']} |
| | | rowSx={rowSx(drawerVal || null)} |
| | | > |
| | | <NumberField source="id" /> |
| | | <TextField source="uuid" label="table.field.integrationRecord.uuid" /> |
| | |
| | | <TextField source="url" label="table.field.integrationRecord.url" /> |
| | | <TextField source="appkey" label="table.field.integrationRecord.appkey" /> |
| | | <TextField source="caller" label="table.field.integrationRecord.caller" /> |
| | | <TextField source="direction$" label="table.field.integrationRecord.direction" sortable={false} /> |
| | | <TextField source="timestamp" label="table.field.integrationRecord.timestamp" /> |
| | | <TextField source="direction" label="table.field.integrationRecord.direction" sortable={false} /> |
| | | <FormattedTimestampField source="timestamp" label="table.field.integrationRecord.timestamp" /> |
| | | <TextField source="clientIp" label="table.field.integrationRecord.clientIp" /> |
| | | <TextField source="request" label="table.field.integrationRecord.request" /> |
| | | <TextField source="response" label="table.field.integrationRecord.response" /> |
| | | <TextField source="request" label="table.field.integrationRecord.request" sortable={false} hidden={!!drawerVal} /> |
| | | <TextField source="response" label="table.field.integrationRecord.response" sortable={false} hidden={!!drawerVal} /> |
| | | <ResultField source="result" label="table.field.integrationRecord.result" /> |
| | | <TextField source="err" label="table.field.integrationRecord.err" /> |
| | | <TextField source="result$" label="table.field.integrationRecord.result" sortable={false} /> |
| | | <NumberField source="costMs" label="table.field.integrationRecord.costMs" /> |
| | | <NumberField source="costMs" label="table.field.integrationRecord.costMs" sx={{ fontWeight: 'bold' }} /> |
| | | |
| | | <ReferenceField source="updateBy" label="common.field.updateBy" reference="user" link={false} sortable={false}> |
| | | <TextField source="nickname" /> |
| | | </ReferenceField> |
| | | <DateField source="updateTime" label="common.field.updateTime" showTime /> |
| | | <ReferenceField source="createBy" label="common.field.createBy" reference="user" link={false} sortable={false}> |
| | | <TextField source="nickname" /> |
| | | </ReferenceField> |
| | | <DateField source="createTime" label="common.field.createTime" showTime /> |
| | | <BooleanField source="statusBool" label="common.field.status" sortable={false} /> |
| | | {/* <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> |
| | | <IntegrationRecordCreate |
| | |
| | | drawerVal={drawerVal} |
| | | setDrawerVal={setDrawerVal} |
| | | > |
| | | <IntegrationRecordDetail integration={drawerVal} /> |
| | | </PageDrawer> |
| | | </Box> |
| | | ) |
| | | } |
| | | |
| | | const FormattedTimestampField = ({ source }) => { |
| | | const record = useRecordContext(); |
| | | if (!record) return null; |
| | | const val = record[source]; |
| | | if (!val) return null; |
| | | const formattedDate = format(new Date(Number(val)), 'yyyy-MM-dd HH:mm:ss'); |
| | | return <span>{formattedDate}</span>; |
| | | }; |
| | | |
| | | const ResultField = ({ source }) => { |
| | | const record = useRecordContext(); |
| | | const val = record?.[source]; |
| | | return ( |
| | | <> |
| | | {val === 1 ? ( |
| | | <Chip label="success" color="success" variant="outlined" size="small" /> |
| | | ) : ( |
| | | <Chip label="error" color="error" variant="outlined" size="small" /> |
| | | )} |
| | | </> |
| | | ); |
| | | }; |
| | | |
| | | export default IntegrationRecordList; |