#
vincentlu
昨天 f7543a1cc6c89ea03c0d6a0591526baf10d7934b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import React, { useMemo } from "react";
import { Box, Card, CardContent, Stack, Typography, Divider } from '@mui/material';
import {
    useTranslate,
    useRecordContext,
} from 'react-admin';
 
const LanePanel = () => {
    const record = useRecordContext();
    if (!record) return null;
    const translate = useTranslate();
    const rawCodes = record.codes;
    const codeFontFamily = `'JetBrains Mono','Fira Code','SFMono-Regular','Roboto Mono',monospace`;
 
    const codes = useMemo(() => {
        if (!rawCodes) return [];
 
        if (Array.isArray(rawCodes)) {
            return rawCodes.filter((item) => !!item);
        }
 
        if (typeof rawCodes === 'string') {
            try {
                const parsed = JSON.parse(rawCodes);
                if (Array.isArray(parsed)) {
                    return parsed.filter((item) => !!item);
                }
            } catch (error) {
                // ignore json parse error and fallback below
            }
 
            return rawCodes
                .split(',')
                .map((item) => item.replace(/[\[\]"]/g, '').trim())
                .filter((item) => !!item);
        }
 
        return [];
    }, [rawCodes]);
 
    return (
        <Card
            sx={{
                width: 'min(960px, 92vw)',
                mx: 'auto',
                my: 0.5,
                borderRadius: 3,
                boxShadow: (theme) => theme.shadows[6],
                border: '1px solid',
                borderColor: 'divider',
                background: (theme) =>
                    theme.palette.mode === 'dark'
                        ? 'linear-gradient(135deg, rgba(255,255,255,0.04), rgba(255,255,255,0.01))'
                        : 'linear-gradient(135deg, rgba(15,23,42,0.02), rgba(15,23,42,0.06))',
            }}
        >
            <CardContent sx={{ p: { xs: 3, md: 4 } }}>
                <Stack spacing={3}>
                    <Box
                        display="flex"
                        justifyContent="space-between"
                        alignItems={{ xs: 'flex-start', sm: 'center' }}
                        flexDirection={{ xs: 'column', sm: 'row' }}
                        gap={1.5}
                    >
                        <Stack spacing={0.5}>
                            <Typography
                                variant="overline"
                                color="text.secondary"
                                sx={{ letterSpacing: 2, fontWeight: 600 }}
                            >
                                {translate('table.field.lane.codes')}
                            </Typography>
                            <Typography variant="body2" sx={{ fontWeight: 700, letterSpacing: 0.5 }}>
                                {translate('table.field.lane.hashCode')} · {record.hashCode}
                            </Typography>
                        </Stack>
                        <Box
                            sx={{
                                px: 2,
                                py: 0.75,
                                borderRadius: 999,
                                fontWeight: 600,
                                letterSpacing: 1,
                                bgcolor: 'primary.main',
                                color: 'primary.contrastText',
                                textTransform: 'uppercase',
                                boxShadow: (theme) => theme.shadows[3],
                            }}
                        >
                            {translate('common.field.count')}: {codes.length}
                        </Box>
                    </Box>
                    <Divider flexItem />
                    {codes.length > 0 ? (
                        <Box
                            sx={{
                                display: 'grid',
                                gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))',
                                gap: 1.5,
                                maxHeight: 420,
                                overflowY: 'auto',
                                p: 3,
                            }}
                        >
                            {codes.map((code, idx) => (
                                <Box
                                    key={`${code}-${idx}`}
                                    sx={{
                                        px: 2.25,
                                        py: 1.25,
                                        borderRadius: 2,
                                        border: '1px solid',
                                        borderColor: 'grey.200',
                                        background:
                                            'linear-gradient(120deg, rgba(148,163,184,0.18), rgba(148,163,184,0.05))',
                                        fontFamily: codeFontFamily,
                                        // fontWeight: 600,
                                        letterSpacing: 0.8,
                                        fontSize: '0.95rem',
                                        textAlign: 'center',
                                        color: 'text.primary',
                                        transition: 'all .25s ease',
                                        boxShadow: (theme) => theme.shadows[1],
                                        '&:hover': {
                                            transform: 'translateY(-4px) scale(1.01)',
                                            boxShadow: (theme) => theme.shadows[4],
                                            borderColor: 'primary.main',
                                            background:
                                                'linear-gradient(135deg, rgba(59,130,246,0.18), rgba(59,130,246,0.05))',
                                        },
                                    }}
                                >
                                    {code}
                                </Box>
                            ))}
                        </Box>
                    ) : (
                        <Typography variant="body2" color="text.secondary">
                            {translate('ra.navigation.no_results')}
                        </Typography>
                    )}
                </Stack>
            </CardContent>
        </Card>
    );
};
 
export default LanePanel;