#
vincentlu
2025-05-13 ebd2f4397a92c6a5096de1b86d59154363344720
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
import React, { useState, useRef, useEffect } from 'react';
import { useTranslate } from "react-admin";
import { Box, Typography, Tabs, Tab, Stack, useTheme, Divider } from '@mui/material';
import ShelfMain from './ShelfMain';
import JsonShow from '../../JsonShow';
import { getLocGroup } from '../../http';
 
const ShelfInsight = (props) => {
    const { sprite, setTitle } = props;
    const theme = useTheme();
    const translate = useTranslate();
 
    const [activeTab, setActiveTab] = useState(0);
    const [curShelfInfo, setCurShelfInfo] = useState(null);
    const [curLocNo, setCurLocNo] = useState(null);
 
    const fetchShelfInfo = (row, bay) => {
        getLocGroup(row, bay, (response) => {
            setCurShelfInfo(response);
            const defaultLocNo = response[0]?.locNo;
            setCurLocNo(defaultLocNo);
        });
    }
 
    useEffect(() => {
        if (sprite) {
            const { row, bay } = sprite.data;
            if (row && bay) {
                fetchShelfInfo(row, bay);
            }
        }
 
        return () => {
            setCurLocNo(null);
            setCurShelfInfo(null);
        }
    }, [sprite]);
 
    useEffect(() => {
        if (curLocNo) {
            setTitle(translate('page.map.devices.shelf') + ' - ' + curLocNo);
        }
 
        return () => {
            setTitle(null);
        }
    }, [curLocNo])
 
    const handleTabChange = (event, newValue) => {
        setActiveTab(newValue);
    };
 
    return (
        <Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
            <Tabs
                value={activeTab}
                onChange={handleTabChange}
                centered
                sx={{ mb: 0 }}
            >
                <Tab label={translate('page.map.insight.title')} />
                <Tab label={'JSON'} />
            </Tabs>
 
            <Divider />
 
            <Box flex={1} pt={2}>
                {activeTab === 0 && (
                    <ShelfMain
                        row={sprite?.data?.row}
                        bay={sprite?.data?.bay}
                        curLocNo={curLocNo}
                        curShelfInfo={curShelfInfo}
                        setCurLocNo={setCurLocNo}
                    />
                )}
                {activeTab === 1 && (
                    <JsonShow
                        data={curShelfInfo || sprite?.data}
                        height={550}
                    />
                )}
            </Box>
        </Box>
    )
}
 
export default ShelfInsight;