Skip to content

Commit

Permalink
feat: Display feedback score in feedback log (#3942)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Nov 13, 2024
1 parent dee5e1a commit 98e181e
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React from "react";
import { FeedbackEditor } from "./Editor";

const meta = {
title: "Editor Components/Feedback",
title: "Editor Components/Feedback modal",
component: FeedbackEditor,
} satisfies Meta<typeof FeedbackEditor>;

Expand Down
1 change: 1 addition & 0 deletions editor.planx.uk/src/components/Feedback/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type FeedbackCategory =
| "comment"
| "inaccuracy"
| "component";

export type FeedbackView = "banner" | "triage" | FeedbackCategory | "thanks";
export type ClickEvents = "close" | "back" | "triage" | FeedbackCategory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const FeedbackLog: React.FC<FeedbackLogProps> = ({ feedback }) => {
<TableCell sx={{ width: 100 }}>
<strong>Date</strong>
</TableCell>
<TableCell sx={{ width: 140 }}>
<strong>Rating</strong>
</TableCell>
<TableCell sx={{ width: 340 }}>
<strong>Comment</strong>
</TableCell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ export const CollapsibleRow: React.FC<CollapsibleRowProps> = (item) => {
userContext: "What were you doing?",
};

enum EmojiRating {
Terrible,
Poor,
Average,
Good,
Excellent,
}

const feedbackScore =
item.feedbackScore && EmojiRating[item.feedbackScore + 1]; // enums are 0-indexed

const renderContent = (key: string, value: any) => {
if (key === "combinedHelp" && value) {
return <ReactMarkdownOrHtml source={value} openLinksOnNewTab />;
Expand All @@ -144,6 +155,7 @@ export const CollapsibleRow: React.FC<CollapsibleRowProps> = (item) => {
<TableCell>
{format(new Date(item.createdAt), "dd/MM/yy hh:mm:ss")}
</TableCell>
<TableCell sx={{ textAlign: "center" }}>{feedbackScore}</TableCell>
<TableCell>{commentSummary}</TableCell>
<TableCell sx={{ textAlign: "right" }}>
<IconButton
Expand Down
8 changes: 5 additions & 3 deletions editor.planx.uk/src/routes/feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface Feedback {
userContext: string | null;
createdAt: string;
address: string | null;
feedbackScore: number;
}

const feedbackRoutes = compose(
Expand All @@ -36,14 +37,14 @@ const feedbackRoutes = compose(
const isAuthorised = useStore.getState().canUserEditTeam(teamSlug);
if (!isAuthorised)
throw new NotFoundError(
`User does not have access to ${req.originalUrl}`,
`User does not have access to ${req.originalUrl}`
);

const {
data: { feedback },
} = await client.query<{ feedback: Feedback[] }>({
query: gql`
query GetFeebackForFlow($teamSlug: String!, $flowSlug: String!) {
query GetFeedbackForFlow($teamSlug: String!, $flowSlug: String!) {
feedback: feedback_summary(
order_by: { created_at: asc }
where: {
Expand All @@ -57,6 +58,7 @@ const feedbackRoutes = compose(
nodeType: node_type
userComment: user_comment
userContext: user_context
feedbackScore: feedback_score
createdAt: created_at
address
}
Expand All @@ -70,7 +72,7 @@ const feedbackRoutes = compose(
view: <FeedbackLog feedback={feedback} />,
};
}),
}),
})
);

export default feedbackRoutes;
27 changes: 15 additions & 12 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,17 @@
- role: demoUser
permission:
columns:
- feedback_id
- device
- node_data
- address
- created_at
- device
- feedback_id
- feedback_score
- feedback_type
- help_definition
- help_sources
- help_text
- intersecting_constraints
- node_data
- node_id
- node_text
- node_title
Expand All @@ -325,7 +327,6 @@
- uprn
- user_comment
- user_context
- created_at
filter:
team:
flows:
Expand All @@ -335,15 +336,17 @@
- role: platformAdmin
permission:
columns:
- feedback_id
- device
- node_data
- address
- created_at
- device
- feedback_id
- feedback_score
- feedback_type
- help_definition
- help_sources
- help_text
- intersecting_constraints
- node_data
- node_id
- node_text
- node_title
Expand All @@ -355,21 +358,22 @@
- uprn
- user_comment
- user_context
- created_at
filter: {}
comment: ""
- role: teamEditor
permission:
columns:
- feedback_id
- device
- node_data
- address
- created_at
- device
- feedback_id
- feedback_score
- feedback_type
- help_definition
- help_sources
- help_text
- intersecting_constraints
- node_data
- node_id
- node_text
- node_title
Expand All @@ -381,7 +385,6 @@
- uprn
- user_comment
- user_context
- created_at
filter:
team:
members:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
-- Drop the existing feedback_summary view
DROP VIEW IF EXISTS public.feedback_summary;

-- Recreate the feedback_summary view without feedback_score
CREATE OR REPLACE VIEW "public"."feedback_summary" AS
SELECT fb.id AS feedback_id,
t.slug AS team_slug,
f.slug AS service_slug,
fb.created_at,
fb.node_id,
fb.device,
fb.user_context,
fb.user_comment,
fb.feedback_type,
fb.status,
fb.node_type,
fb.node_data,
COALESCE((fb.node_data ->> 'title'::text), (fb.node_data ->> 'text'::text), (fb.node_data ->> 'flagSet'::text)) AS node_title,
(fb.node_data ->> 'description'::text) AS node_text,
(fb.node_data ->> 'info'::text) AS help_text,
(fb.node_data ->> 'policyRef'::text) AS help_sources,
(fb.node_data ->> 'howMeasured'::text) AS help_definition,
COALESCE(((((fb.user_data -> 'passport'::text) -> 'data'::text) -> '_address'::text) ->> 'single_line_address'::text), ((((fb.user_data -> 'passport'::text) -> 'data'::text) -> '_address'::text) ->> 'title'::text)) AS address,
((((fb.user_data -> 'passport'::text) -> 'data'::text) -> '_address'::text) ->> 'uprn'::text) AS uprn,
(((fb.user_data -> 'passport'::text) -> 'data'::text) ->> 'proposal.projectType'::text) AS project_type,
(((fb.user_data -> 'passport'::text) -> 'data'::text) ->> 'property.constraints.planning'::text) AS intersecting_constraints
FROM ((feedback fb
LEFT JOIN flows f ON ((f.id = fb.flow_id)))
LEFT JOIN teams t ON ((t.id = fb.team_id)));
26 changes: 26 additions & 0 deletions hasura.planx.uk/migrations/1731495319577_run_sql_migration/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE OR REPLACE VIEW "public"."feedback_summary" AS
SELECT fb.id AS feedback_id,
t.slug AS team_slug,
f.slug AS service_slug,
fb.created_at,
fb.node_id,
fb.device,
fb.user_context,
fb.user_comment,
fb.feedback_type,
fb.status,
fb.node_type,
fb.node_data,
COALESCE((fb.node_data ->> 'title'::text), (fb.node_data ->> 'text'::text), (fb.node_data ->> 'flagSet'::text)) AS node_title,
(fb.node_data ->> 'description'::text) AS node_text,
(fb.node_data ->> 'info'::text) AS help_text,
(fb.node_data ->> 'policyRef'::text) AS help_sources,
(fb.node_data ->> 'howMeasured'::text) AS help_definition,
COALESCE(((((fb.user_data -> 'passport'::text) -> 'data'::text) -> '_address'::text) ->> 'single_line_address'::text), ((((fb.user_data -> 'passport'::text) -> 'data'::text) -> '_address'::text) ->> 'title'::text)) AS address,
((((fb.user_data -> 'passport'::text) -> 'data'::text) -> '_address'::text) ->> 'uprn'::text) AS uprn,
(((fb.user_data -> 'passport'::text) -> 'data'::text) ->> 'proposal.projectType'::text) AS project_type,
(((fb.user_data -> 'passport'::text) -> 'data'::text) ->> 'property.constraints.planning'::text) AS intersecting_constraints,
fb.feedback_score
FROM ((feedback fb
LEFT JOIN flows f ON ((f.id = fb.flow_id)))
LEFT JOIN teams t ON ((t.id = fb.team_id)));

0 comments on commit 98e181e

Please sign in to comment.