Skip to content

Commit 7942f7f

Browse files
Merge pull request #22 from AuthEceSoftEng:thanos
Enhance file handling and UI adjustments
2 parents 2041495 + 28b40ca commit 7942f7f

File tree

16 files changed

+721
-751
lines changed

16 files changed

+721
-751
lines changed

src/api/api-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const rootApi = ky.extend({
4040
return new Response(JSON.stringify({ success: false }), { status: 200 });
4141
}
4242

43-
if (status === 404) {
43+
if (status === 404 && !_req.url.includes("/file/download/")) {
4444
globalThis.location.href = "/";
4545
}
4646

src/api/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,34 @@ export const signUp = (username, email, password) => api.post("createUser", { us
2222
export const invitedSignUp = (username, email, password, token) => api.post("createUserInvited", { username, email, password, token });
2323
export const uploadFile = (body) => rootApi.post("file/", { body }).json();
2424
export const reUploadFile = (body) => rootApi.put("file/", { body }).json();
25+
export const getFile = async (organization, saveName, originalName) => {
26+
try {
27+
const fileName = originalName || saveName;
28+
// Make the API call to get the file as a blob
29+
const response = await rootApi.get(
30+
`file/download/${encodeURIComponent(organization)}/${encodeURIComponent(saveName)}/${encodeURIComponent(fileName)}`,
31+
);
32+
const blob = await response.blob();
33+
34+
// Create a download link and trigger it
35+
const url = globalThis.URL.createObjectURL(blob);
36+
const a = document.createElement("a");
37+
a.href = url;
38+
a.download = fileName;
39+
document.body.append(a);
40+
a.click();
41+
42+
// Cleanup
43+
a.remove();
44+
globalThis.URL.revokeObjectURL(url);
45+
46+
return { success: true };
47+
} catch (error) {
48+
console.error("Error downloading file:", error);
49+
throw error;
50+
}
51+
};
52+
2553
export const deleteFile = (info) => api.post("file/delete/", info);
2654
export const inviteUser = (email) => api.post("user", { email });
2755
export const removeUser = (id) => api.post("user/delete", { id });

src/components/Card.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ const Card = ({
3434
padding,
3535
backgroundColor: transparent ? "transparent" : colors?.[backgroundColor] || backgroundColor,
3636
opacity: transparent ? opacity : 1,
37-
boxSizing: "border-box", // Ensure padding is included in the width
38-
overflow: "hidden", // Prevent content overflow
39-
borderRadius,
37+
boxSizing: "border-box",
38+
overflow: "hidden",
39+
borderRadius: `${Number.parseInt(borderRadius, 10) + Number.parseInt(padding, 10)}px`,
4040
cursor: clickable ? "pointer" : "default",
4141
transition: "all 0.2s ease-in-out",
42-
boxShadow: transparent ? elevation : null, // Add shadow based on elevation
42+
boxShadow: transparent ? elevation : null,
4343
"&:hover": hoverEffect && clickable ? {
4444
transform: "scale(1.02)",
45-
boxShadow: transparent ? elevation + 15 : null, // Increase shadow on hover
45+
boxShadow: transparent ? elevation + 15 : null,
4646
} : {},
4747
}}
4848
onClick={clickable ? onClick : undefined}
@@ -57,9 +57,9 @@ const Card = ({
5757
flexDirection="row"
5858
justifyContent="center"
5959
alignItems="center"
60-
boxSizing="border-box" // Ensure padding is included in the width
60+
boxSizing="border-box"
6161
borderRadius={borderRadius}
62-
sx={{ flexShrink: 0 }} // Prevent title from shrinking
62+
sx={{ flexShrink: 0 }}
6363
>
6464
{typeof title === "string" ? (
6565
<Typography variant="body" component="h2" sx={{ fontWeight: "bold", fontSize: titleFontSize }}>
@@ -75,7 +75,7 @@ const Card = ({
7575
padding="10px 5px"
7676
justifyContent="center"
7777
alignItems="center"
78-
boxSizing="border-box" // Ensure padding is included in the width
78+
boxSizing="border-box"
7979
flexGrow={1}
8080
>
8181
{children}
@@ -89,8 +89,8 @@ const Card = ({
8989
flexDirection="column"
9090
justifyContent="space-between"
9191
alignItems="center"
92-
boxSizing="border-box" // Ensure padding is included in the width
93-
sx={{ flexShrink: 0 }} // Prevent footer from shrinking
92+
boxSizing="border-box"
93+
sx={{ flexShrink: 0 }}
9494
>
9595
{typeof footer === "string" ? (
9696
<Typography variant="h6" component="h2" align="left" fontSize={footerFontSize}>

src/components/Plot.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ const Plot = ({
9797
suffix: d.suffix,
9898
font: { color: colors?.[d?.textColor] || d?.textColor || "black" },
9999
},
100+
hovertemplate: d.hovertemplate,
101+
customdata: d.customdata,
100102
sort: d.sort ?? true,
101103
orientation: d.orientation || "v",
104+
automargin: true,
102105
};
103106

104107
// Add pie-specific properties
@@ -111,7 +114,6 @@ const Plot = ({
111114
text: pieDataThereshold(d.values, 0.03),
112115
textinfo: "text",
113116
hoverinfo: "label+percent+value",
114-
automargin: true,
115117
insidetextorientation: "radial",
116118
domain: { x: [0, 1], y: [0, 1] },
117119
textfont: { color: "white", size: 12 },
@@ -126,8 +128,6 @@ const Plot = ({
126128
? (colors?.[d.color] || d.color)
127129
: agriColors[index % agriColors.length],
128130
},
129-
hovertemplate: d.hovertemplate, // Add this line
130-
customdata: d.customdata, // Add this line
131131
gauge: d.type === "indicator" ? {
132132
axis: { range: d.range },
133133
bar: { color: colors?.[d?.color] || d?.color, thickness: 1 },
@@ -141,7 +141,6 @@ const Plot = ({
141141
}),
142142
} : undefined,
143143
domain: { x: [0, 1], y: [0, 1] },
144-
automargin: true,
145144
labels: d.labels,
146145
textfont: { color: "white" },
147146
};

src/components/Sidebar.js

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const useStyles = makeStyles((theme) => ({
3535
minHeight: "30px",
3636
transition: "transform 0.3s ease-in-out",
3737
},
38+
buttonHover: {
39+
"&:hover": {
40+
backgroundColor: "rgba(255, 255, 255, 0.1)",
41+
transition: "background-color 0.3s ease",
42+
},
43+
},
3844
}));
3945

4046
const IconRenderer = ({ icon, text, size = "25px" }) => (
@@ -60,22 +66,19 @@ const LogoRenderer = ({ logo, title, size = "20px", borderRadius = "8px" }) => (
6066
</div>
6167
);
6268

63-
const ButtonWithText = ({ text, icon, more, handler }) => (
69+
const ButtonWithText = ({ text, icon, more, handler, classes }) => (
6470
<span key={text}>
6571
{!more
6672
&& (
6773
<Button
6874
key={text}
75+
className={classes.buttonHover}
6976
sx={{
7077
width: "100%",
7178
display: "flex",
7279
flexDirection: "row",
7380
justifyContent: "flex-start",
7481
padding: "8px 40px 8px 16px",
75-
"&:hover": {
76-
backgroundColor: "rgba(255, 255, 255, 0.1)", // subtle white overlay on hover
77-
transition: "background-color 0.3s ease",
78-
},
7982
}}
8083
onClick={(event) => handler(event)}
8184
>
@@ -122,10 +125,7 @@ const ButtonWithText = ({ text, icon, more, handler }) => (
122125
sx={{
123126
justifyContent: "flex-start",
124127
marginLeft: "20px",
125-
"&:hover": {
126-
backgroundColor: "rgba(255, 255, 255, 0.1)",
127-
transition: "background-color 0.3s ease",
128-
},
128+
...classes.buttonHover,
129129
}}
130130
onClick={el.handler}
131131
>
@@ -143,21 +143,18 @@ const ButtonWithText = ({ text, icon, more, handler }) => (
143143
</span>
144144
);
145145

146-
const ButtonSimple = ({ text, icon, handler, ind }) => (
146+
const ButtonSimple = ({ text, icon, handler, ind, classes }) => (
147147
<Button
148148
key={text}
149+
className={classes.buttonHover}
149150
sx={{
150151
minWidth: "30px!important",
151152
padding: "8px",
152153
position: "absolute",
153-
top: `${ind * 40}px`, // Fixed position based on index (adjust the multiplier as needed)
154+
top: `${ind * 40}px`,
154155
left: "50%",
155156
transform: "translateX(-50%)",
156157
transition: "top 0.5s ease-in-out, background-color 0.3s ease",
157-
"&:hover": {
158-
backgroundColor: "rgba(255, 255, 255, 0.1)",
159-
transition: "background-color 0.3s ease",
160-
},
161158
}}
162159
onClick={(event) => handler(event)}
163160
>
@@ -179,38 +176,32 @@ const Sidebar = ({ isSmall: sidebarIsSmall, onToggleSidebar }) => {
179176

180177
useEffect(() => setIsSmall(sidebarIsSmall), [sidebarIsSmall]);
181178

179+
// Create a wrapper handler
180+
const createNavigationHandler = (path) => () => {
181+
handleServicesMenuClose();
182+
navigate(path);
183+
};
184+
182185
const buttons = [
183186
{
184187
icon: <HomeRounded />,
185-
text: "Overview",
186-
handler: () => {
187-
handleServicesMenuClose();
188-
navigate("/home");
189-
},
188+
text: "Home",
189+
handler: createNavigationHandler("/home"),
190190
},
191191
{
192192
icon: <AgricultureRounded />,
193193
text: "Products",
194-
handler: () => {
195-
handleServicesMenuClose();
196-
navigate("/products");
197-
},
194+
handler: createNavigationHandler("/products"),
198195
},
199196
{
200197
icon: <MapRounded />,
201198
text: "Map",
202-
handler: () => {
203-
handleServicesMenuClose();
204-
navigate("/Map");
205-
},
199+
handler: createNavigationHandler("/Map"),
206200
},
207201
{
208202
icon: <CrisisAlertRounded />,
209203
text: "Contaminants",
210-
handler: () => {
211-
handleServicesMenuClose();
212-
navigate("/contaminants");
213-
},
204+
handler: createNavigationHandler("/contaminants"),
214205
},
215206
{
216207
icon: <SpaRounded />,
@@ -277,6 +268,7 @@ const Sidebar = ({ isSmall: sidebarIsSmall, onToggleSidebar }) => {
277268
className={classes.toggleButton}
278269
sx={{
279270
transform: isSmall ? "rotate(-90deg)" : "rotate(90deg)",
271+
...classes.buttonHover,
280272
}}
281273
onClick={toggleSidebar}
282274
>
@@ -289,6 +281,7 @@ const Sidebar = ({ isSmall: sidebarIsSmall, onToggleSidebar }) => {
289281
text={button.text}
290282
handler={button.handler}
291283
more={button.more}
284+
classes={classes}
292285
/>
293286
))}
294287
{isSmall && (
@@ -310,6 +303,7 @@ const Sidebar = ({ isSmall: sidebarIsSmall, onToggleSidebar }) => {
310303
handler={button.handler}
311304
more={button.more}
312305
ind={ind}
306+
classes={classes}
313307
/>
314308
))}
315309
</div>

src/config/LofsConfig.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const createStatsConfig = (baseConfig, statsParams, attribute, stat, plotId, inc
1515
});
1616

1717
const lofsConfigs = (product, startDate, endDate) => {
18-
// Base configuration
1918
const baseConfig = {
2019
project: "lofsproject",
2120
collection: "weatherdata",
@@ -54,7 +53,7 @@ const lofsConfigs = (product, startDate, endDate) => {
5453
attributes: [
5554
"key", "timestamp", "temp_max_c", "temp_min_c",
5655
"rain_mm", "etp_mm", "humidity_percent",
57-
"co2_ppm", "solar_radiation_j_cm2", "solar_radiation_mj_m2", "wind_speed_2m",
56+
"co2_ppm", "solar_radiation_mj_m2", "wind_speed_2m", // "solar_radiation_j_cm2",
5857
],
5958
filters: [baseConfig.productFilter, ...dateFilter],
6059
order_by: { field: "timestamp", order: "asc" },

0 commit comments

Comments
 (0)