From 5e82be762b55dc30103afdb00b858b9f362b661a Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Tue, 28 May 2024 15:27:27 +0100 Subject: [PATCH] wip: Styled feedback table --- .../components/Flow/FeedbackPage.tsx | 191 ++++++++++++++++-- editor.planx.uk/src/routes/feedback.tsx | 2 + 2 files changed, 181 insertions(+), 12 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/Flow/FeedbackPage.tsx b/editor.planx.uk/src/pages/FlowEditor/components/Flow/FeedbackPage.tsx index 59a2788649..4b77018744 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/Flow/FeedbackPage.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/Flow/FeedbackPage.tsx @@ -1,14 +1,51 @@ +import CancelIcon from "@mui/icons-material/Cancel"; +import CheckCircleIcon from "@mui/icons-material/CheckCircle"; +import KeyboardArrowDown from "@mui/icons-material/KeyboardArrowDown"; +import KeyboardArrowUp from "@mui/icons-material/KeyboardArrowUp"; +import LightbulbIcon from "@mui/icons-material/Lightbulb"; +import MoreHorizIcon from "@mui/icons-material/MoreHoriz"; +import RuleIcon from "@mui/icons-material/Rule"; +import WarningIcon from "@mui/icons-material/Warning"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; +import Collapse from "@mui/material/Collapse"; +import Container from "@mui/material/Container"; +import IconButton from "@mui/material/IconButton"; +import { styled } from "@mui/material/styles"; +import Table from "@mui/material/Table"; +import TableBody from "@mui/material/TableBody"; +import TableCell from "@mui/material/TableCell"; +import TableContainer from "@mui/material/TableContainer"; +import TableHead from "@mui/material/TableHead"; +import TableRow from "@mui/material/TableRow"; +import Typography from "@mui/material/Typography"; +import { SummaryListTable } from "@planx/components/shared/Preview/SummaryList"; +import { format } from "date-fns"; import gql from "graphql-tag"; import { client } from "lib/graphql"; -import React from "react"; +import React, { useState } from "react"; import { Feedback } from "routes/feedback"; +import EditorRow from "ui/editor/EditorRow"; interface Props { feedback: Feedback[]; } +const Feed = styled(TableContainer)(() => ({ + maxHeight: "60vh", + overflow: "auto", + display: "flex", + flexDirection: "column-reverse", + readingOrder: "flex-visual", +})); + +const DetailedFeedback = styled(Box)(({ theme }) => ({ + fontSize: "1em", + margin: 1, + maxWidth: "100%", + padding: theme.spacing(2, 1), +})); + const GET_FEEDBACK_BY_ID_QUERY = gql` query GetFeedbackById($feedbackId: Int!) { feedback: feedback_summary(where: { feedback_id: { _eq: $feedbackId } }) { @@ -16,7 +53,7 @@ const GET_FEEDBACK_BY_ID_QUERY = gql` createdAt: created_at device feedbackId: feedback_id - feedbackType: feedback_type + type: feedback_type helpDefinition: help_definition helpSources: help_sources helpText: help_text @@ -49,17 +86,147 @@ const getDetailedFeedback = async (feedbackId: number) => { console.log(detailedFeedback); }; +type FeedbackType = + | "issue" + | "idea" + | "comment" + | "inaccuracy" + | "helpful" + | "unhelpful"; + +const feedbackTypeIcon = (type: FeedbackType) => { + switch (type) { + case "issue": + return { icon: , title: "Issue" }; + case "idea": + return { icon: , title: "Idea" }; + case "comment": + return { icon: , title: "Comment" }; + case "helpful": + return { + icon: , + title: "Helpful (help text)", + }; + case "unhelpful": + return { + icon: , + title: "Unhelpful (help text)", + }; + default: + return { icon: , title: "inaccuracy" }; + } +}; + export const FeedbackPage: React.FC = ({ feedback }) => { return ( - - {feedback.map((item) => ( - - {JSON.stringify(item, null, 4)} - - - ))} - + + + + + Feedback log + + + User-sumbitted feedback gathered for this service. + + + + + + + *": { borderBottomColor: "black !important" } }} + > + + Type + + + Date + + + Comment + + + + + + {feedback.map((item) => ( + + ))} + +
+
+
+
+
+ ); +}; + +const CollapsibleRow: React.FC = (item) => { + const [open, setOpen] = useState(false); + const { icon, title } = feedbackTypeIcon(item.type); + + const details = [ + { label: "Project address", value: item.address }, + { label: "Page title", value: item.nodeTitle }, + { label: "Component type", value: item.nodeType }, + { label: "Feedback ID", value: item.id }, + ]; + + return ( + + + + + {icon} {title} + + + + {format(new Date(item.createdAt), "dd/MM/yy hh:mm:ss")} + + {item.userComment} + + setOpen(!open)} + > + {open ? : } + + + + theme.palette.background.paper }}> + + + `1px solid ${theme.palette.border.light}`, + padding: (theme) => theme.spacing(0, 1.5), + }} + > + + + {details.map((detail, index) => ( + <> + {detail.label} + {detail.value} + + ))} + + + + + + + ); }; diff --git a/editor.planx.uk/src/routes/feedback.tsx b/editor.planx.uk/src/routes/feedback.tsx index 078223a994..c744505f73 100644 --- a/editor.planx.uk/src/routes/feedback.tsx +++ b/editor.planx.uk/src/routes/feedback.tsx @@ -20,6 +20,7 @@ export interface Feedback { userComment: string | null; userContext: string | null; createdAt: string; + address: string | null; } const feedbackRoutes = compose( @@ -56,6 +57,7 @@ const feedbackRoutes = compose( userComment: user_comment userContext: user_context createdAt: created_at + address } } `,