Skip to content

Commit

Permalink
feat: Capture node_data directly alongside feeback (#3156)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored May 16, 2024
1 parent 4eeea8f commit 8033d92
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
5 changes: 5 additions & 0 deletions editor.planx.uk/src/lib/feedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type FeedbackMetadata = {
nodeType?: string | null;
device: Bowser.Parser.ParsedResult;
userData: UserData;
nodeData: Store.node["data"];
};

export async function getInternalFeedbackMetadata(): Promise<FeedbackMetadata> {
Expand All @@ -40,6 +41,7 @@ export async function getInternalFeedbackMetadata(): Promise<FeedbackMetadata> {
nodeType: node?.type ? TYPES[node.type] : null,
device: Bowser.parse(window.navigator.userAgent),
userData: userData,
nodeData: node?.data
};

return metadata;
Expand All @@ -55,6 +57,7 @@ export async function insertFeedbackMutation(data: {
userContext?: string;
userComment: string;
feedbackType: string;
nodeData?: Store.node["data"];
}) {
const result = await publicClient.mutate({
mutation: gql`
Expand All @@ -68,6 +71,7 @@ export async function insertFeedbackMutation(data: {
$userContext: String
$userComment: String!
$feedbackType: feedback_type_enum_enum!
$nodeData: jsonb
) {
insert_feedback(
objects: {
Expand All @@ -80,6 +84,7 @@ export async function insertFeedbackMutation(data: {
user_context: $userContext
user_comment: $userComment
feedback_type: $feedbackType
node_data: $nodeData
}
) {
affected_rows
Expand Down
1 change: 1 addition & 0 deletions hasura.planx.uk/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
- feedback_type
- flow_id
- id
- node_data
- node_id
- node_type
- status
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
comment on column "public"."feedback"."node_data" is NULL;

ALTER TABLE feedback DROP COLUMN node_data;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alter table "public"."feedback" add column "node_data" jsonb
null;

comment on column "public"."feedback"."node_data" is E'The data of the node the user was on when their feedback was left';
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
DROP VIEW "public"."feedback_summary";

-- Most recent version of view from planx-new/hasura.planx.uk/migrations/1715784133713_run_sql_migration/up.sql
CREATE OR REPLACE VIEW "public"."feedback_summary" AS
SELECT
fb.id AS feedback_id,
t.slug AS team,
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,
COALESCE(
published_flow_node.data ->> 'title',
published_flow_node.data ->> 'text',
published_flow_node.data ->> 'flagSet'
) AS node_title,
published_flow_node.data ->> 'description' AS node_text,
published_flow_node.data ->> 'info' AS help_text,
published_flow_node.data ->> 'policyRef' AS help_sources,
published_flow_node.data ->> 'howMeasured' AS help_definition,
COALESCE(
fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'single_line_address',
fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'title'
) AS address,
(fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'uprn') AS uprn,
(fb.user_data -> 'passport' -> 'data' ->> 'proposal.projectType') AS project_type,
(fb.user_data -> 'passport' -> 'data' ->> 'property.constraints.planning') AS intersecting_constraints,
published_flow_node.data AS node_data
FROM
feedback fb
LEFT JOIN
flows f ON f.id = fb.flow_id
LEFT JOIN
teams t ON t.id = fb.team_id
LEFT JOIN LATERAL
(
SELECT
(published_flows.data -> fb.node_id) -> 'data' AS data
FROM
published_flows
WHERE
published_flows.flow_id = fb.flow_id
AND published_flows.created_at < fb.created_at
ORDER BY
published_flows.created_at DESC
LIMIT 1
) AS published_flow_node ON true;

GRANT SELECT ON public.feedback_summary TO metabase_read_only;
40 changes: 40 additions & 0 deletions hasura.planx.uk/migrations/1715868696352_run_sql_migration/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
DROP VIEW "public"."feedback_summary";

CREATE OR REPLACE VIEW "public"."feedback_summary" AS
SELECT
fb.id AS feedback_id,
t.slug AS team,
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',
fb.node_data ->> 'text',
fb.node_data ->> 'flagSet'
) AS node_title,
fb.node_data ->> 'description' AS node_text,
fb.node_data ->> 'info' AS help_text,
fb.node_data ->> 'policyRef' AS help_sources,
fb.node_data ->> 'howMeasured' AS help_definition,
COALESCE(
fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'single_line_address',
fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'title'
) AS address,
(fb.user_data -> 'passport' -> 'data' -> '_address' ->> 'uprn') AS uprn,
(fb.user_data -> 'passport' -> 'data' ->> 'proposal.projectType') AS project_type,
(fb.user_data -> 'passport' -> 'data' ->> 'property.constraints.planning') 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;

GRANT SELECT ON public.feedback_summary TO metabase_read_only;

0 comments on commit 8033d92

Please sign in to comment.