Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/components/CSVButton/CSVButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { parse } from "json2csv";
import { WordData } from "@/app/general/interfaces";
import { styles } from "@/app/components/CSVButton/CSVButton.style";
import CustomButton from "@/app/components/CustomButton";
import { DOWNLOAD_RESULTS } from "@/app/general/constants";
import { GENERAL_BUTTONS_TEXTS } from "@/app/general/constants";

export default function CSVButton({ queryWords }: { queryWords: WordData[] }) {
const handleDownload = () => {
Expand All @@ -16,7 +16,7 @@ export default function CSVButton({ queryWords }: { queryWords: WordData[] }) {
<CustomButton
onClick={handleDownload}
sx={styles.button}
text={DOWNLOAD_RESULTS}
text={GENERAL_BUTTONS_TEXTS.downloadResults}
/>
);
}
4 changes: 2 additions & 2 deletions src/app/components/ChatButton/ChatButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Grid } from "@mui/material";
import CustomButton from "@/app/components/CustomButton";
import SendIcon from "@mui/icons-material/Send";
import { styles } from "./ChatButton.style";
import { SEND } from "@/app/general/constants";
import { GENERAL_BUTTONS_TEXTS } from "@/app/general/constants";

export default function ChatButton() {
return (
Expand All @@ -12,7 +12,7 @@ export default function ChatButton() {
sx={styles.button}
endIcon={<SendIcon />}
type="submit"
text={SEND}
text={GENERAL_BUTTONS_TEXTS.send}
/>
</Grid>
);
Expand Down
33 changes: 14 additions & 19 deletions src/app/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
generalObject,
} from "@/app/general/interfaces";
import { strOrNum } from "@/app/general/types";
import {
SAMPLE_SIZE,
HEADER_BUTTONS_TEXTS,
NO_HELP_DESCRIPTION,
NO_MAIL_PROVIDED,
HEADER_DIALOGS_TITLES,
} from "@/app/general/constants";
import { HEADER_TEXTS } from "@/app/general/constants";
import { getTableInfo, convertToCSV, downloadCSV } from "@/app/general/utils";
import _ from "lodash";

Expand All @@ -30,7 +24,7 @@
const helpDescription = bot?._details.helpDescription;
const mailInfo = bot?._details.mailInfo;
const { botHeaders, botColumns, rows } = getTableInfo(bot);
const sampleRows = _.sampleSize(rows, SAMPLE_SIZE);
const sampleRows = _.sampleSize(rows, HEADER_TEXTS.general.sampleSize);

const attributesRows = botColumns?.map((column) => ({
name: column.displayName,
Expand All @@ -42,24 +36,25 @@
const dataButtons = [
{
onClick: () => setOpenAttribute(true),
text: HEADER_BUTTONS_TEXTS.attributes,
text: HEADER_TEXTS.buttons.attributes,
},
{ onClick: () => setOpenData(true), text: HEADER_BUTTONS_TEXTS.data },
{ onClick: () => setOpenData(true), text: HEADER_TEXTS.buttons.data },

Check warning on line 41 in src/app/components/Header/Header.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
{
onClick: () => downloadCSV(csv, "data.csv"),
text: HEADER_BUTTONS_TEXTS.download,
text: HEADER_TEXTS.buttons.download,
},
];

const helpButtons = [
{ onClick: () => setOpenHelp(true), text: HEADER_BUTTONS_TEXTS.help },
{ onClick: () => setOpenMail(true), text: HEADER_BUTTONS_TEXTS.mail },
{ onClick: () => setOpenHelp(true), text: HEADER_TEXTS.buttons.help },

Check warning on line 49 in src/app/components/Header/Header.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
{ onClick: () => setOpenMail(true), text: HEADER_TEXTS.buttons.mail },

Check warning on line 50 in src/app/components/Header/Header.tsx

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
];

const dialogs = [
{
open: openAttribute,
setOpen: setOpenAttribute,
title: HEADER_DIALOGS_TITLES.attributes,
title: HEADER_TEXTS.dialogs.attributes,
children: (
<Table<NameAndDescription>
headers={["name", "description"]}
Expand All @@ -70,7 +65,7 @@
{
open: openData,
setOpen: setOpenData,
title: HEADER_DIALOGS_TITLES.data,
title: HEADER_TEXTS.dialogs.data,
children: (
<Table<generalObject<strOrNum>>
headers={botHeaders}
Expand All @@ -81,16 +76,16 @@
{
open: openHelp,
setOpen: setOpenHelp,
title: HEADER_DIALOGS_TITLES.help,
content: helpDescription ?? NO_HELP_DESCRIPTION,
title: HEADER_TEXTS.dialogs.help,
content: helpDescription ?? HEADER_TEXTS.general.noHelpDescription,
},
{
open: openMail,
setOpen: setOpenMail,
title: HEADER_DIALOGS_TITLES.mail,
title: HEADER_TEXTS.dialogs.mail,
children: (
<Link href={`mailto:${mailInfo}`}>
{mailInfo ?? NO_MAIL_PROVIDED}
{mailInfo ?? HEADER_TEXTS.general.noMailProvided}
</Link>
),
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Message/Message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "@testing-library/jest-dom";
import { render, screen } from "@testing-library/react";
import Message from "@/app/components/Message";
import { Colors, Message as IMessage } from "@/app/general/interfaces";
import { colorCodes } from "@/app/general/resources";
import { colorCodes } from "@/app/general/constants";
import { TypeOfQuestion, Sender } from "@/app/general/types";

// Mock props
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { styles } from "@/app/components/Message/Message.style";
import { MessageProps } from "@/app/general/interfaces";
import SmartToyIcon from "@mui/icons-material/SmartToy";
import PersonIcon from "@mui/icons-material/Person";
import { colorCodes } from "@/app/general/resources";
import { colorCodes } from "@/app/general/constants";

export default function Message({ message, colors }: MessageProps) {
const isBot = message?.sender === "bot";
Expand Down
75 changes: 67 additions & 8 deletions src/app/general/constants.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,79 @@
export const NO_RESULTS_FOUND = "No results found";
export const SAMPLE_SIZE = 5;
export const NO_HELP_DESCRIPTION = "No help description available";
export const NO_MAIL_PROVIDED = "No mail provided for comments";
export const DOWNLOAD_RESULTS = "Download Results";
export const SEND = "Send";
export const GENERAL_BUTTONS_TEXTS = {
downloadResults: "Download Results",
send: "Send",
};

export const RESOURCES_TEXTS = {
paramMessageDefault: "Enter value for parameter",
noResultsFound: "No results found",
propertyMessage: "Which property would you like to start with?",
factorOptions: "The options for this factor attribute are:",
addParameter: "Do you want to add another parameter?",
yesOption: "1. Yes",
noOption: "2. No",
restartMessage:
"To add another parameter, I will go through the same process as before.",
emptyMessage: "empty message",
};

const HEADER_GENERAL_TEXTS = {
sampleSize: 5,
noHelpDescription: "No help description available",
noMailProvided: "No mail provided for comments",
};

export const HEADER_BUTTONS_TEXTS = {
const HEADER_BUTTONS_TEXTS = {
attributes: "Display Attributes",
data: "Display Data Sample",
help: "Help!",
mail: "Leave us a comment",
download: "Download Full Data",
};
export const HEADER_DIALOGS_TITLES = {

const HEADER_DIALOGS_TITLES = {
attributes: "Details of Attributes",
data: "Sample of Data",
help: "Help!",
mail: "Leave us a comment",
};

export const HEADER_TEXTS = {
buttons: HEADER_BUTTONS_TEXTS,
dialogs: HEADER_DIALOGS_TITLES,
general: HEADER_GENERAL_TEXTS,
};

export const colorCodes = {
blue: {
dark: "primary.main",
light: "primary.light",
},
green: {
dark: "#006400",
light: "#90EE90",
},
red: {
dark: "#800000",
light: "#FFB6C1",
},
yellow: {
dark: "#FFD700",
light: "#FFFFE0",
},
purple: {
dark: "secondary.main",
light: "secondary.light",
},
orange: {
dark: "#FF8C00",
light: "#FFA500",
},
black: {
dark: "#000000",
light: "#696969",
},
white: {
dark: "#D3D3D3",
light: "#FFFFFF",
},
};
74 changes: 27 additions & 47 deletions src/app/general/resources.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Message, MessageSection, Bot } from "@/app/general/interfaces";
import { Sender, TypeOfQuestion } from "@/app/general/types";
import { Sender, TypeOfQuestion, DataType } from "@/app/general/types";
import { convertTextToMessage } from "@/app/general/utils";
import { NO_RESULTS_FOUND } from "@/app/general/constants";
import { RESOURCES_TEXTS } from "@/app/general/constants";

export const botMessages = (bot: Bot): Message[] => {
const headers = bot?._data.headers || [];
Expand All @@ -28,7 +28,7 @@

${headersString}

Which property would you like to start with?`,
${RESOURCES_TEXTS.propertyMessage}`,
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.PARAMETER,
answerOptions: Array.from(
Expand Down Expand Up @@ -97,21 +97,36 @@
return displayMessage;
};

export const botFunctionParamsMessages = (
bot: Bot,
currentParam: string
): Message[] => {
const operators = bot?._data.columns.filter(
const column = bot?._data.columns.filter(
(col) => col._id === currentParam
)[0]?.operatorsArray;
)[0];
const operators = column?.operatorsArray;
const columnType = column?.dataType;
const rows = column?.rows;

const chosenOperator = operators[bot.currentOperatorIndex];
const params = chosenOperator.params;

const isFactor = columnType === DataType.FACTOR;
const factorOptions = Array.from(new Set(rows));
const factorOptionsMessage = `${

Check warning on line 116 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
RESOURCES_TEXTS.factorOptions

Check warning on line 117 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
} ${factorOptions?.join(", ")}`;

Check warning on line 118 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
const extraMessage = isFactor ? factorOptionsMessage : "";

const messages: Message[] = params.map((prm, index) => {
return {
id: index,
text: prm?.message ?? `Enter value for parameter ${prm?.name}:`,
text:
(prm?.message ??

Check warning on line 125 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
`${RESOURCES_TEXTS.paramMessageDefault} ${prm?.name}`) +

Check warning on line 126 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
"\n" +
"\n" +
extraMessage,
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.FUNCTION_PARAMS,
};
Expand All @@ -138,31 +153,31 @@
export const botAddMessages: Message[] = [
{
id: 0,
text: `Do you want to add another parameter?
text: `${RESOURCES_TEXTS.addParameter}

1. Yes
2. No`,
${RESOURCES_TEXTS.yesOption}
${RESOURCES_TEXTS.noOption}`,
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.ADD,
answerOptions: [1, 2],
},
];

export const botRestartMessages = (bot: Bot): Message[] => {
const startMsg = botMessages(bot).slice(-1)[0];
const restartSlot = bot?._messages?.slots.restartSlot ?? [];
const restartSlotArray = restartSlot.map((msg, index) =>
convertTextToMessage(
msg,
index,
bot?._messages.customMessages.continueMessage
)
);
return [
...restartSlotArray,
{
id: 0,
text: `To add another parameter, I will go through the same process as before.
text: `${RESOURCES_TEXTS.restartMessage}

Check warning on line 180 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

${bot?._messages.customMessages.continueMessage}`,
sender: Sender.BOT,
Expand All @@ -173,22 +188,22 @@
];
};

Check warning on line 189 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function

export const resultMsg = (bot: Bot, foundResults: boolean): Message[] => {
const resultSlot = bot?._messages?.slots.resultSlot ?? [];
const resultSlotArray = resultSlot.map((msg, index) =>
convertTextToMessage(
msg,
index,
bot?._messages.customMessages.continueMessage
)
);
return [
...resultSlotArray,
{
id: 0,
text: foundResults
? bot?._messages?.customMessages.resultMessage
: NO_RESULTS_FOUND,
: RESOURCES_TEXTS.noResultsFound,

Check warning on line 206 in src/app/general/resources.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.RESULT,
},
Expand All @@ -204,42 +219,7 @@

export const emptyMessage: Message = {
id: 0,
text: "empty message",
text: RESOURCES_TEXTS.emptyMessage,
sender: Sender.BOT,
typeOfQuestion: TypeOfQuestion.FUNCTION_PARAMS,
};

export const colorCodes = {
blue: {
dark: "primary.main",
light: "primary.light",
},
green: {
dark: "#006400",
light: "#90EE90",
},
red: {
dark: "#800000",
light: "#FFB6C1",
},
yellow: {
dark: "#FFD700",
light: "#FFFFE0",
},
purple: {
dark: "secondary.main",
light: "secondary.light",
},
orange: {
dark: "#FF8C00",
light: "#FFA500",
},
black: {
dark: "#000000",
light: "#696969",
},
white: {
dark: "#D3D3D3",
light: "#FFFFFF",
},
};
Loading