Skip to content

Commit 07da370

Browse files
Merge pull request #36 from GoldenLabHuji:ShlomiShitrit/issue33
issue33: add "help" button
2 parents faae8c8 + 8f79ab8 commit 07da370

File tree

13 files changed

+162
-94
lines changed

13 files changed

+162
-94
lines changed
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Button } from "@mui/material";
21
import { saveAs } from "file-saver";
32
import { parse } from "json2csv";
43
import { WordData } from "@/app/general/interfaces";
54
import { styles } from "@/app/components/CSVButton/CSVButton.style";
5+
import CustomButton from "@/app/components/CustomButton";
6+
import { DOWNLOAD_RESULTS } from "@/app/general/constants";
67

78
export default function CSVButton({ queryWords }: { queryWords: WordData[] }) {
89
const handleDownload = () => {
@@ -12,13 +13,10 @@ export default function CSVButton({ queryWords }: { queryWords: WordData[] }) {
1213
};
1314

1415
return (
15-
<Button
16-
variant="contained"
17-
color="primary"
16+
<CustomButton
1817
onClick={handleDownload}
1918
sx={styles.button}
20-
>
21-
Download Results
22-
</Button>
19+
text={DOWNLOAD_RESULTS}
20+
/>
2321
);
2422
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export const styles = {};
1+
export const styles = {
2+
button: { width: "120%" },
3+
};
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import { Button, Grid } from "@mui/material";
1+
"use client";
2+
import { Grid } from "@mui/material";
3+
import CustomButton from "@/app/components/CustomButton";
24
import SendIcon from "@mui/icons-material/Send";
5+
import { styles } from "./ChatButton.style";
6+
import { SEND } from "@/app/general/constants";
37

48
export default function ChatButton() {
59
return (
610
<Grid item xs={2}>
7-
<Button
8-
sx={{ width: "120%" }}
9-
color="primary"
10-
variant="contained"
11+
<CustomButton
12+
sx={styles.button}
1113
endIcon={<SendIcon />}
1214
type="submit"
13-
>
14-
Send
15-
</Button>
15+
text={SEND}
16+
/>
1617
</Grid>
1718
);
1819
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const styles = {}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import "@testing-library/jest-dom/jest-globals";
2+
import "@testing-library/jest-dom";
3+
import { render, screen } from "@testing-library/react";
4+
import CustomButton from "@/app/components/CustomButton";
5+
import { CustomButtonProps } from "@/app/general/interfaces";
6+
7+
describe("CustomButton", () => {
8+
const defaultProps: CustomButtonProps = {
9+
text: "Click Me",
10+
};
11+
12+
it("renders the button with the provided text", () => {
13+
render(<CustomButton {...defaultProps} />);
14+
const buttonElement = screen.getByRole("button", { name: /click me/i });
15+
expect(buttonElement).toBeInTheDocument();
16+
});
17+
18+
it("applies additional props to the Button component", () => {
19+
render(<CustomButton {...defaultProps} disabled />);
20+
const buttonElement = screen.getByRole("button", { name: /click me/i });
21+
expect(buttonElement).toBeDisabled();
22+
});
23+
24+
it("applies primary color and contained variant by default", () => {
25+
render(<CustomButton {...defaultProps} />);
26+
const buttonElement = screen.getByRole("button", { name: /click me/i });
27+
expect(buttonElement).toHaveClass("MuiButton-containedPrimary");
28+
});
29+
});
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"use client";
2+
import { CustomButtonProps } from "@/app/general/interfaces";
3+
import { Button, ButtonProps } from "@mui/material";
4+
import { styles } from "./CustomButton.style";
5+
6+
export default function CustomButton({
7+
text,
8+
...props
9+
}: CustomButtonProps & ButtonProps) {
10+
return (
11+
<Button {...props} color="primary" variant="contained">
12+
{text}
13+
</Button>
14+
);
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import CustomButton from './CustomButton'
2+
3+
export default CustomButton;

src/app/components/Dialog/Dialog.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import { DialogProps } from "@/app/general/interfaces";
3+
import CustomButton from "@/app/components/CustomButton";
34
import {
4-
Button,
55
Dialog as MuiDialog,
66
DialogActions,
77
DialogContent,
@@ -24,9 +24,11 @@ export default function Dialog({
2424
{children}
2525
</DialogContent>
2626
<DialogActions>
27-
<Button onClick={() => setOpen(false)} autoFocus>
28-
Close
29-
</Button>
27+
<CustomButton
28+
onClick={() => setOpen(false)}
29+
autoFocus
30+
text="Close"
31+
/>
3032
</DialogActions>
3133
</MuiDialog>
3234
);

src/app/components/Header/Header.style.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@ export const styles = {
33
display: "flex",
44
backgroundColor: "#f8f9fa",
55
padding: 2,
6-
justifyContent: "center",
76
color: "black",
87
},
98
typContainer: {
109
width: "34%",
1110
textAlign: "center",
1211
justifyContent: "center",
1312
},
14-
dataContainer: {
15-
width: "33%",
16-
direction: "rtl",
17-
},
18-
buttonContainer: {
19-
width: "33%",
20-
},
21-
attributeButton: {
22-
width: "25%",
13+
button: {
14+
width: "22%",
15+
height: "80%",
16+
fontSize: "14px",
17+
borderRadius: "15px",
18+
margin: "5px",
2319
},
24-
dataButton: {
25-
width: "25%",
20+
buttonsContainer: {
21+
width: "30%",
2622
},
2723
};
Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use client";
22
import { useState } from "react";
33
import { styles } from "./Header.style";
4-
import { Box, Typography, Button } from "@mui/material";
4+
import { Box, Typography } from "@mui/material";
55
import Table from "@/app/components/Table";
66
import Dialog from "@/app/components/Dialog";
7+
import CustomButton from "@/app/components/CustomButton";
78
import {
89
HeaderProps,
910
NameAndDescription,
@@ -14,81 +15,80 @@ import {
1415
SAMPLE_SIZE,
1516
ATTRIBUTES_BUTTON_TEXT,
1617
SAMPLE_BUTTON_TEXT,
18+
NO_HELP_DESCRIPTION,
1719
} from "@/app/general/constants";
20+
import { getTableInfo } from "@/app/general/utils";
1821

1922
export default function Header({ bot }: HeaderProps) {
2023
const [openAttribute, setOpenAttribute] = useState<boolean>(false);
2124
const [openData, setOpenData] = useState<boolean>(false);
25+
const [openHelp, setOpenHelp] = useState<boolean>(false);
2226

23-
const botHeaders = bot?._data.headers;
24-
const botColumns = bot?._data.columns;
25-
26-
const rows: generalObject<strOrNum>[] = botHeaders.map((_, index) => {
27-
const row: generalObject<strOrNum> = {};
28-
botColumns.forEach((col) => {
29-
row[col.displayName] = col.rows[index];
30-
});
31-
return row;
32-
});
33-
27+
const helpDescription = bot?._details.helpDescription;
28+
const { botHeaders, botColumns, rows } = getTableInfo(bot);
3429
const sampleRows = rows.slice(0, SAMPLE_SIZE);
3530

3631
const attributesRows = botColumns?.map((column) => ({
3732
name: column.displayName,
3833
description: column._description,
3934
}));
4035

36+
const buttons = [
37+
{ onClick: () => setOpenAttribute(true), text: ATTRIBUTES_BUTTON_TEXT },
38+
{ onClick: () => setOpenData(true), text: SAMPLE_BUTTON_TEXT },
39+
{ onClick: () => setOpenHelp(true), text: "Help!" },
40+
];
41+
42+
const dialogs = [
43+
{
44+
open: openAttribute,
45+
setOpen: setOpenAttribute,
46+
title: "Details of Attributes",
47+
children: (
48+
<Table<NameAndDescription>
49+
headers={["name", "description"]}
50+
rows={attributesRows}
51+
/>
52+
),
53+
},
54+
{
55+
open: openData,
56+
setOpen: setOpenData,
57+
title: "Sample of Data",
58+
children: (
59+
<Table<generalObject<strOrNum>>
60+
headers={botHeaders}
61+
rows={sampleRows}
62+
/>
63+
),
64+
},
65+
{
66+
open: openHelp,
67+
setOpen: setOpenHelp,
68+
title: "Help!",
69+
content: helpDescription ?? NO_HELP_DESCRIPTION,
70+
},
71+
];
72+
4173
return (
4274
<Box component="header" sx={styles.box}>
43-
<Box component="div" sx={styles.buttonContainer}>
44-
<Button
45-
variant="contained"
46-
color="primary"
47-
sx={styles.attributeButton}
48-
onClick={() => setOpenAttribute(true)}
49-
>
50-
{ATTRIBUTES_BUTTON_TEXT}
51-
</Button>
75+
<Box component="div" sx={styles.buttonsContainer}>
76+
{buttons.map((button, index) => (
77+
<CustomButton key={index} sx={styles.button} {...button} />
78+
))}
5279
</Box>
5380
<Box component="div" sx={styles.typContainer}>
5481
<Typography variant="h4" component="h1">
5582
{bot?._details.name as string}
5683
</Typography>
5784
</Box>
58-
<Box component="div" sx={styles.dataContainer}>
59-
<Button
60-
variant="contained"
61-
color="primary"
62-
sx={styles.dataButton}
63-
onClick={() => setOpenData(true)}
64-
>
65-
{SAMPLE_BUTTON_TEXT}
66-
</Button>
67-
</Box>
68-
<Dialog
69-
title="Details of Attributes"
70-
content=""
71-
open={openAttribute}
72-
setOpen={setOpenAttribute}
73-
children={
74-
<Table<NameAndDescription>
75-
headers={["name", "description"]}
76-
rows={attributesRows}
77-
/>
78-
}
79-
></Dialog>
80-
<Dialog
81-
title="Sample of Data"
82-
content=""
83-
open={openData}
84-
setOpen={setOpenData}
85-
children={
86-
<Table<generalObject<strOrNum>>
87-
headers={botHeaders}
88-
rows={sampleRows}
89-
/>
90-
}
91-
></Dialog>
85+
{dialogs.map((dialog, index) => (
86+
<Dialog
87+
key={index}
88+
content={dialog?.content ?? ""}
89+
{...dialog}
90+
/>
91+
))}
9292
</Box>
9393
);
9494
}

0 commit comments

Comments
 (0)