import React, { useState, useRef, useEffect, useMemo } from "react";
|
import { Box, Card, CardContent, Grid, Typography, Tooltip } from '@mui/material';
|
import {
|
useTranslate,
|
useRecordContext,
|
} from 'react-admin';
|
import PanelTypography from "../components/PanelTypography";
|
import * as Common from '@/utils/common'
|
import { describeCronExpression } from "./cronUtils";
|
import { DEFAULT_SCOPE_TYPE, getScopeLabel } from "./guaranteeConstants";
|
|
const GuaranteePanel = () => {
|
const record = useRecordContext();
|
if (!record) return null;
|
const translate = useTranslate();
|
const scopeTypeLabel = getScopeLabel(record.scopeType, translate);
|
const scopeValueLabel = record.scopeValue
|
? record.scopeValue
|
: record.scopeType === DEFAULT_SCOPE_TYPE
|
? translate('page.guarantee.scope.globalHelper')
|
: translate('common.enums.na');
|
const cronDesc = record.cronExpr
|
? `${describeCronExpression(record.cronExpr, translate)} (${record.cronExpr})`
|
: translate('common.enums.na');
|
|
return (
|
<>
|
<Card sx={{ width: { xs: 300, sm: 500, md: 600, lg: 800 }, margin: 'auto' }}>
|
<CardContent>
|
<Grid container spacing={2}>
|
<Grid item xs={12} sx={{ display: 'flex', justifyContent: 'space-between' }}>
|
<Typography variant="h6" gutterBottom align="left" sx={{
|
maxWidth: { xs: '100px', sm: '180px', md: '260px', lg: '360px' },
|
whiteSpace: 'nowrap',
|
overflow: 'hidden',
|
textOverflow: 'ellipsis',
|
}}>
|
{Common.camelToPascalWithSpaces(translate('table.field.guarantee.name'))}: {record.name}
|
</Typography>
|
{/* inherit, primary, secondary, textPrimary, textSecondary, error */}
|
<Typography variant="h6" gutterBottom align="right" >
|
ID: {record.id}
|
</Typography>
|
</Grid>
|
</Grid>
|
<Grid container spacing={2}>
|
<Grid item xs={12} container alignContent="flex-end">
|
<Typography variant="caption" color="textSecondary" sx={{ wordWrap: 'break-word', wordBreak: 'break-all' }}>
|
{Common.camelToPascalWithSpaces(translate('common.field.memo'))}:{record.memo}
|
</Typography>
|
</Grid>
|
</Grid>
|
<Box height={20}> </Box>
|
<Grid container spacing={2}>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.uuid"
|
property={record.uuid}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.name"
|
property={record.name}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.scopeType"
|
property={scopeTypeLabel}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.scopeValue"
|
property={scopeValueLabel}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.cronExpr"
|
property={cronDesc}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.requiredCount"
|
property={record.requiredCount}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.minSoc"
|
property={record.minSoc}
|
/>
|
</Grid>
|
<Grid item xs={6}>
|
<PanelTypography
|
title="table.field.guarantee.leadTime"
|
property={record.leadTime}
|
/>
|
</Grid>
|
|
</Grid>
|
</CardContent>
|
</Card >
|
</>
|
);
|
};
|
|
export default GuaranteePanel;
|