|
1 | 1 | import { useCallback, useEffect, useRef, useState } from "react";
|
2 |
| -import { |
3 |
| - Box, |
4 |
| - Button, |
5 |
| - Stack, |
6 |
| - Typography, |
7 |
| - CircularProgress, |
8 |
| - IconButton, |
9 |
| - Tooltip, |
10 |
| -} from "@mui/material"; |
| 2 | +import { Box, Stack, CircularProgress } from "@mui/material"; |
11 | 3 | import {
|
12 | 4 | DataEditor,
|
13 | 5 | GridCellKind,
|
14 | 6 | GridColumnIcon,
|
15 | 7 | } from "@glideapps/glide-data-grid";
|
16 |
| -import ArrowBackIcon from "@mui/icons-material/ArrowBack"; |
17 |
| -import { useNavigate } from "react-router-dom"; |
18 | 8 | import { SheetColumnMenu, SheetColumnMenuButton } from "./SheetColumnMenu";
|
19 | 9 | import { axios } from "../../data/axios";
|
20 | 10 | import { Ws } from "../../data/ws";
|
21 | 11 | import { enqueueSnackbar } from "notistack";
|
22 |
| -import SaveIcon from "@mui/icons-material/Save"; |
23 |
| -import PlayArrowIcon from "@mui/icons-material/PlayArrow"; |
24 |
| -import PauseIcon from "@mui/icons-material/Pause"; |
25 |
| -import DownloadIcon from "@mui/icons-material/Download"; |
| 12 | +import SheetHeader from "./SheetHeader"; |
26 | 13 |
|
27 | 14 | import "@glideapps/glide-data-grid/dist/index.css";
|
28 | 15 |
|
@@ -52,130 +39,6 @@ const gridCellToCellId = (gridCell, columns) => {
|
52 | 39 | return `${colLetter}${rowIndex + 1}`;
|
53 | 40 | };
|
54 | 41 |
|
55 |
| -const SheetHeader = ({ |
56 |
| - sheet, |
57 |
| - setRunId, |
58 |
| - hasChanges, |
59 |
| - onSave, |
60 |
| - sheetRunning, |
61 |
| - runId, |
62 |
| -}) => { |
63 |
| - const navigate = useNavigate(); |
64 |
| - |
65 |
| - const saveSheet = () => { |
66 |
| - onSave(); |
67 |
| - }; |
68 |
| - |
69 |
| - const runSheet = () => { |
70 |
| - const runSheetAction = () => { |
71 |
| - axios() |
72 |
| - .post(`/api/sheets/${sheet.uuid}/run`) |
73 |
| - .then((response) => { |
74 |
| - setRunId(response.data.run_id); |
75 |
| - }) |
76 |
| - .catch((error) => { |
77 |
| - console.error(error); |
78 |
| - enqueueSnackbar( |
79 |
| - `Error running sheet: ${ |
80 |
| - error?.response?.data?.detail || error.message |
81 |
| - }`, |
82 |
| - { variant: "error" }, |
83 |
| - ); |
84 |
| - }); |
85 |
| - }; |
86 |
| - |
87 |
| - if (hasChanges) { |
88 |
| - onSave().then(runSheetAction); |
89 |
| - } else { |
90 |
| - runSheetAction(); |
91 |
| - } |
92 |
| - }; |
93 |
| - |
94 |
| - const downloadSheet = () => { |
95 |
| - window.open(`/api/sheets/${sheet.uuid}/download`, "_blank"); |
96 |
| - }; |
97 |
| - |
98 |
| - return ( |
99 |
| - <Stack> |
100 |
| - <Typography variant="h5" className="section-header"> |
101 |
| - <Stack |
102 |
| - direction={"row"} |
103 |
| - sx={{ justifyContent: "space-between", alignItems: "center" }} |
104 |
| - > |
105 |
| - <Stack direction="row" alignItems="center" spacing={2}> |
106 |
| - <Tooltip title="Back to Sheets List"> |
107 |
| - <IconButton |
108 |
| - onClick={() => navigate("/sheets")} |
109 |
| - sx={{ color: "action.disabled", padding: 0 }} |
110 |
| - > |
111 |
| - <ArrowBackIcon |
112 |
| - fontSize="small" |
113 |
| - sx={{ |
114 |
| - color: "action.disabled", |
115 |
| - padding: 0, |
116 |
| - }} |
117 |
| - /> |
118 |
| - </IconButton> |
119 |
| - </Tooltip> |
120 |
| - <Stack> |
121 |
| - {sheet?.name} |
122 |
| - <Typography variant="caption" sx={{ color: "#666" }}> |
123 |
| - {sheet?.description || sheet?.data?.description || ""} |
124 |
| - </Typography> |
125 |
| - </Stack> |
126 |
| - </Stack> |
127 |
| - <Stack direction={"row"} gap={1}> |
128 |
| - <Tooltip title="Save changes"> |
129 |
| - <Button |
130 |
| - onClick={saveSheet} |
131 |
| - disabled={!hasChanges} |
132 |
| - color="primary" |
133 |
| - variant="outlined" |
134 |
| - sx={{ minWidth: "40px", padding: "5px", borderRadius: "4px" }} |
135 |
| - > |
136 |
| - <SaveIcon /> |
137 |
| - </Button> |
138 |
| - </Tooltip> |
139 |
| - {!sheetRunning && ( |
140 |
| - <Tooltip title="Download CSV"> |
141 |
| - <Button |
142 |
| - onClick={downloadSheet} |
143 |
| - color="primary" |
144 |
| - variant="outlined" |
145 |
| - sx={{ minWidth: "40px", padding: "5px", borderRadius: "4px" }} |
146 |
| - > |
147 |
| - <DownloadIcon /> |
148 |
| - </Button> |
149 |
| - </Tooltip> |
150 |
| - )} |
151 |
| - <Tooltip |
152 |
| - title={ |
153 |
| - sheetRunning ? "Sheet is already running" : "Run the sheet" |
154 |
| - } |
155 |
| - > |
156 |
| - <Button |
157 |
| - variant="contained" |
158 |
| - size="medium" |
159 |
| - onClick={runSheet} |
160 |
| - disabled={sheetRunning} |
161 |
| - sx={{ |
162 |
| - bgcolor: "success.main", |
163 |
| - "&:hover": { bgcolor: "success.dark" }, |
164 |
| - minWidth: "40px", |
165 |
| - padding: "5px", |
166 |
| - borderRadius: "4px !important", |
167 |
| - }} |
168 |
| - > |
169 |
| - {sheetRunning ? <PauseIcon /> : <PlayArrowIcon />} |
170 |
| - </Button> |
171 |
| - </Tooltip> |
172 |
| - </Stack> |
173 |
| - </Stack> |
174 |
| - </Typography> |
175 |
| - </Stack> |
176 |
| - ); |
177 |
| -}; |
178 |
| - |
179 | 42 | function Sheet(props) {
|
180 | 43 | const { sheetId } = props;
|
181 | 44 | const [sheetRunning, setSheetRunning] = useState(false);
|
|
0 commit comments