| | |
| | | import React, { useState, useRef, useEffect, useMemo, useCallback } from "react"; |
| | | import { useNavigate } from 'react-router-dom'; |
| | | import React, { useState, useCallback } from "react"; |
| | | import { |
| | | List, |
| | | DatagridConfigurable, |
| | | SearchInput, |
| | | TopToolbar, |
| | | SelectColumnsButton, |
| | | EditButton, |
| | | FilterButton, |
| | | CreateButton, |
| | | ExportButton, |
| | | BulkDeleteButton, |
| | | WrapperField, |
| | | useRecordContext, |
| | | useTranslate, |
| | | useNotify, |
| | | useListContext, |
| | | FunctionField, |
| | | TextField, |
| | | NumberField, |
| | |
| | | DateInput, |
| | | SelectInput, |
| | | NumberInput, |
| | | ReferenceInput, |
| | | ReferenceArrayInput, |
| | | AutocompleteInput, |
| | | DeleteButton, |
| | | EditButton, |
| | | } from 'react-admin'; |
| | | import { Box, Typography, Card, Stack } from '@mui/material'; |
| | | import { styled } from '@mui/material/styles'; |
| | |
| | | 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 { describeCronExpression } from "./cronUtils"; |
| | | import { DEFAULT_SCOPE_TYPE, SCOPE_FILTER_CHOICES, getScopeLabel } from "./guaranteeConstants"; |
| | | |
| | | const StyledDatagrid = styled(DatagridConfigurable)(({ theme }) => ({ |
| | | '& .css-1vooibu-MuiSvgIcon-root': { |
| | |
| | | |
| | | <TextInput source="uuid" label="table.field.guarantee.uuid" />, |
| | | <TextInput source="name" label="table.field.guarantee.name" />, |
| | | <TextInput source="scopeType" label="table.field.guarantee.scopeType" />, |
| | | <SelectInput |
| | | source="scopeType" |
| | | label="table.field.guarantee.scopeType" |
| | | choices={SCOPE_FILTER_CHOICES} |
| | | translateChoice |
| | | allowEmpty |
| | | resettable |
| | | />, |
| | | <TextInput source="scopeValue" label="table.field.guarantee.scopeValue" />, |
| | | <TextInput source="cronExpr" label="table.field.guarantee.cronExpr" />, |
| | | <NumberInput source="requiredCount" label="table.field.guarantee.requiredCount" />, |
| | |
| | | const [createDialog, setCreateDialog] = useState(false); |
| | | const [drawerVal, setDrawerVal] = useState(false); |
| | | |
| | | const renderScopeType = useCallback((record) => { |
| | | if (!record) { |
| | | return ''; |
| | | } |
| | | return getScopeLabel(record.scopeType, translate); |
| | | }, [translate]); |
| | | |
| | | const renderScopeValue = useCallback((record) => { |
| | | if (!record) { |
| | | return ''; |
| | | } |
| | | if (!record.scopeValue) { |
| | | return record.scopeType === DEFAULT_SCOPE_TYPE |
| | | ? translate('page.guarantee.scope.globalHelper') |
| | | : translate('common.enums.na'); |
| | | } |
| | | return record.scopeValue; |
| | | }, [translate]); |
| | | |
| | | const renderCron = useCallback((record) => { |
| | | if (!record || !record.cronExpr) { |
| | | return translate('common.enums.na'); |
| | | } |
| | | return describeCronExpression(record.cronExpr, translate); |
| | | }, [translate]); |
| | | |
| | | return ( |
| | | <Box display="flex"> |
| | | <List |
| | |
| | | theme.transitions.create(['all'], { |
| | | duration: theme.transitions.duration.enteringScreen, |
| | | }), |
| | | marginRight: !!drawerVal ? `${PAGE_DRAWER_WIDTH}px` : 0, |
| | | marginRight: drawerVal ? `${PAGE_DRAWER_WIDTH}px` : 0, |
| | | }} |
| | | title={"menu.guarantee"} |
| | | empty={<EmptyData onClick={() => { setCreateDialog(true) }} />} |
| | |
| | | <NumberField source="id" /> |
| | | <TextField source="uuid" label="table.field.guarantee.uuid" /> |
| | | <TextField source="name" label="table.field.guarantee.name" /> |
| | | <TextField source="scopeType" label="table.field.guarantee.scopeType" /> |
| | | <TextField source="scopeValue" label="table.field.guarantee.scopeValue" /> |
| | | <TextField source="cronExpr" label="table.field.guarantee.cronExpr" /> |
| | | <FunctionField label="table.field.guarantee.scopeType" render={renderScopeType} /> |
| | | <FunctionField label="table.field.guarantee.scopeValue" render={renderScopeValue} /> |
| | | <FunctionField label="table.field.guarantee.cronExpr" render={renderCron} /> |
| | | <NumberField source="requiredCount" label="table.field.guarantee.requiredCount" /> |
| | | <NumberField source="minSoc" label="table.field.guarantee.minSoc" /> |
| | | <NumberField source="leadTime" label="table.field.guarantee.leadTime" /> |