From 084ef81aadf451028bc06acbf1112e5e719c3fe0 Mon Sep 17 00:00:00 2001 From: Govind Kamtamneni Date: Thu, 13 Jul 2023 20:38:50 -0400 Subject: [PATCH 1/2] update spending chart to include add generated sql button --- .../components/ui/chats/spending-chart.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/typescript/frontend/src/components/ui/chats/spending-chart.tsx b/typescript/frontend/src/components/ui/chats/spending-chart.tsx index 32765216..080d63bd 100644 --- a/typescript/frontend/src/components/ui/chats/spending-chart.tsx +++ b/typescript/frontend/src/components/ui/chats/spending-chart.tsx @@ -2,6 +2,7 @@ import {useState} from 'react'; import {format} from 'date-fns'; import {Area, AreaChart, ResponsiveContainer, Tooltip, XAxis} from 'recharts'; import {SpendingData} from '@/data/static/spending'; +import Button from "@/components/ui/button"; function CustomAxis({ x, y, payload }: any) { const date = format(new Date(payload.value * 1000), 'MMM'); @@ -85,6 +86,24 @@ export default function SpendingChart() { /> + +
+

+ Most expensive month +

+

+ June 2023 (SQL generated by GPT) +

+ +
+ ); From c811ae9de5d6e70b012d6881cd669d01360fc097 Mon Sep 17 00:00:00 2001 From: Govind Kamtamneni Date: Thu, 13 Jul 2023 21:23:28 -0400 Subject: [PATCH 2/2] add gpt generated sql modal to frontend --- .../modal-views/generated-sql-modal.tsx | 61 +++++ .../components/transaction/custom-axis.tsx | 15 ++ .../components/ui/chats/spending-chart.tsx | 208 +++++++++--------- 3 files changed, 181 insertions(+), 103 deletions(-) create mode 100644 typescript/frontend/src/components/modal-views/generated-sql-modal.tsx create mode 100644 typescript/frontend/src/components/transaction/custom-axis.tsx diff --git a/typescript/frontend/src/components/modal-views/generated-sql-modal.tsx b/typescript/frontend/src/components/modal-views/generated-sql-modal.tsx new file mode 100644 index 00000000..efc27b28 --- /dev/null +++ b/typescript/frontend/src/components/modal-views/generated-sql-modal.tsx @@ -0,0 +1,61 @@ +import React from "react"; + +interface ModalProps { + isOpen: boolean; + closeModal: () => void; +} + +export default function SqlModal({ isOpen, closeModal }: ModalProps) { + if (!isOpen) { + return null; + } + + return ( +
+
+ + +
+
+ {/* TODO: Fetch generated SQL */} +
+ +
+

+ "What is the most expensive purchase made by the user in the last year?" +

+
+ +

+ SELECT + u.user_id, + u.first_name, + u.last_name, + MAX(t.transaction_amount) AS most_expensive_purchase + FROM + users u + JOIN + transactions t ON u.user_id = t.user_id + WHERE + t.transaction_date {'>'}= DATE_TRUNC('year', CURRENT_DATE - INTERVAL '1 year') + GROUP BY + u.user_id, u.first_name, u.last_name; +

+
+
+
+ +
+
+
+
+ ); +} diff --git a/typescript/frontend/src/components/transaction/custom-axis.tsx b/typescript/frontend/src/components/transaction/custom-axis.tsx new file mode 100644 index 00000000..a6f828d3 --- /dev/null +++ b/typescript/frontend/src/components/transaction/custom-axis.tsx @@ -0,0 +1,15 @@ +import {format} from "date-fns"; + +export default function CustomAxis({ x, y, payload }: any) { + const date = format(new Date(payload.value * 1000), 'MMM'); + return ( + + + {date} + + + ); +} diff --git a/typescript/frontend/src/components/ui/chats/spending-chart.tsx b/typescript/frontend/src/components/ui/chats/spending-chart.tsx index 080d63bd..59fdcf3d 100644 --- a/typescript/frontend/src/components/ui/chats/spending-chart.tsx +++ b/typescript/frontend/src/components/ui/chats/spending-chart.tsx @@ -1,110 +1,112 @@ -import {useState} from 'react'; -import {format} from 'date-fns'; -import {Area, AreaChart, ResponsiveContainer, Tooltip, XAxis} from 'recharts'; -import {SpendingData} from '@/data/static/spending'; +import {useState} from "react"; +import {format} from "date-fns"; +import SqlModal from "@/components/modal-views/generated-sql-modal"; +import {Area, AreaChart, ResponsiveContainer, Tooltip, XAxis} from "recharts"; +import {SpendingData} from "@/data/static/spending"; import Button from "@/components/ui/button"; - -function CustomAxis({ x, y, payload }: any) { - const date = format(new Date(payload.value * 1000), 'MMM'); - return ( - - - {date} - - - ); -} - +import CustomAxis from "@/components/transaction/custom-axis"; export default function SpendingChart() { - let [date, setDate] = useState(Date.now()); - let [spending, setSpending] = useState('34,500'); + let [date, setDate] = useState(Date.now()); + let [spending, setSpending] = useState('34,500'); + let [isModalOpen, setIsModalOpen] = useState(false); // state variable for modal open status const formattedDate = format(new Date(date * 1000), 'MMMM d, yyyy'); - return ( -
-

- Spending -

-
- ${spending} / YTD -
-
- {formattedDate} -
-
- - { - if (data.isTooltipActive) { - setDate( - data.activePayload && data.activePayload[0].payload.date - ); - setSpending( - data.activePayload && - data.activePayload[0].payload.monthlyExpense - ); - } - }} - > - - - - - - - } - interval={0} - tickMargin={5} - /> - } cursor={{ stroke: '#7645D9' }} /> - - - -
-

- Most expensive month -

-

- June 2023 (SQL generated by GPT) -

- -
+ const closeModal = () => { // function to close the modal + setIsModalOpen(false); + }; + + const openModal = () => { // function to open the modal + setIsModalOpen(true); + }; + + return ( +
+
+

+ Spending +

+
+ ${spending} / YTD +
+
+ {formattedDate} +
+
+ + { + if (data.isTooltipActive) { + setDate( + data.activePayload && data.activePayload[0].payload.date + ); + setSpending( + data.activePayload && + data.activePayload[0].payload.monthlyExpense + ); + } + }} + > + + + + + + + } + interval={0} + tickMargin={5} + /> + } cursor={{stroke: '#7645D9'}}/> + + + + +
+

+ Most expensive month +

+

+ June 2023 (SQL generated by GPT) +

+ +
-
-
- ); + {/* Render the SqlModal */} + +
+
+
+ ); }