-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Setup routing, queries, and permissions for
/:flow/feeback
(#…
- Loading branch information
1 parent
37c310c
commit 1ae1240
Showing
9 changed files
with
302 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
editor.planx.uk/src/pages/FlowEditor/components/Flow/FeedbackPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import gql from "graphql-tag"; | ||
import { client } from "lib/graphql"; | ||
import React from "react"; | ||
import { Feedback } from "routes/feedback"; | ||
|
||
interface Props { | ||
feedback: Feedback[]; | ||
} | ||
|
||
const GET_FEEDBACK_BY_ID_QUERY = gql` | ||
query GetFeedbackById($feedbackId: Int!) { | ||
feedback: feedback_summary(where: { feedback_id: { _eq: $feedbackId } }) { | ||
address | ||
createdAt: created_at | ||
device | ||
feedbackId: feedback_id | ||
feedbackType: feedback_type | ||
helpDefinition: help_definition | ||
helpSources: help_sources | ||
helpText: help_text | ||
intersectingConstraints: intersecting_constraints | ||
nodeData: node_data | ||
nodeId: node_id | ||
nodeText: node_text | ||
nodeTitle: node_title | ||
nodeType: node_type | ||
projectType: project_type | ||
serviceSlug: service_slug | ||
teamSlug: team_slug | ||
status | ||
uprn | ||
userComment: user_comment | ||
userContext: user_context | ||
} | ||
} | ||
`; | ||
|
||
const getDetailedFeedback = async (feedbackId: number) => { | ||
const { | ||
data: { | ||
feedback: [detailedFeedback], | ||
}, | ||
} = await client.query({ | ||
query: GET_FEEDBACK_BY_ID_QUERY, | ||
variables: { feedbackId }, | ||
}); | ||
console.log(detailedFeedback); | ||
}; | ||
|
||
export const FeedbackPage: React.FC<Props> = ({ feedback }) => { | ||
return ( | ||
<Box sx={{ fontSize: 12, overflowY: "auto" }}> | ||
{feedback.map((item) => ( | ||
<React.Fragment key={item.id}> | ||
<Box component="pre">{JSON.stringify(item, null, 4)}</Box> | ||
<Button onClick={() => getDetailedFeedback(item.id)}> | ||
Log out detailed info | ||
</Button> | ||
</React.Fragment> | ||
))} | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { ComponentType } from "@opensystemslab/planx-core/types"; | ||
import { FeedbackCategory } from "components/Feedback"; | ||
import { Sentiment } from "components/Feedback/MoreInfoFeedback"; | ||
import gql from "graphql-tag"; | ||
import { compose, mount, NotFoundError, route, withData } from "navi"; | ||
import { FeedbackPage } from "pages/FlowEditor/components/Flow/FeedbackPage"; | ||
import { useStore } from "pages/FlowEditor/lib/store"; | ||
import React from "react"; | ||
|
||
import { client } from "../lib/graphql"; | ||
import { makeTitle } from "./utils"; | ||
|
||
type FeedbackType = Sentiment & FeedbackCategory; | ||
|
||
export interface Feedback { | ||
id: number; | ||
type: FeedbackType; | ||
nodeTitle: string | null; | ||
nodeType: keyof typeof ComponentType | null; | ||
userComment: string | null; | ||
userContext: string | null; | ||
createdAt: string; | ||
} | ||
|
||
const feedbackRoutes = compose( | ||
withData((req) => ({ | ||
mountpath: req.mountpath, | ||
})), | ||
|
||
mount({ | ||
"/": route(async (req) => { | ||
const { team: teamSlug, flow: flowSlug } = req.params; | ||
|
||
const isAuthorised = useStore.getState().canUserEditTeam(teamSlug); | ||
if (!isAuthorised) | ||
throw new NotFoundError( | ||
`User does not have access to ${req.originalUrl}`, | ||
); | ||
|
||
const { | ||
data: { feedback }, | ||
} = await client.query<{ feedback: Feedback[] }>({ | ||
query: gql` | ||
query GetFeebackForFlow($teamSlug: String!, $flowSlug: String!) { | ||
feedback: feedback_summary( | ||
order_by: { created_at: asc } | ||
where: { | ||
team_slug: { _eq: $teamSlug } | ||
service_slug: { _eq: $flowSlug } | ||
} | ||
) { | ||
id: feedback_id | ||
type: feedback_type | ||
nodeTitle: node_title | ||
nodeType: node_type | ||
userComment: user_comment | ||
userContext: user_context | ||
createdAt: created_at | ||
} | ||
} | ||
`, | ||
variables: { teamSlug, flowSlug }, | ||
}); | ||
|
||
return { | ||
title: makeTitle("Flow Feedback"), | ||
view: <FeedbackPage feedback={feedback} />, | ||
}; | ||
}), | ||
}), | ||
); | ||
|
||
export default feedbackRoutes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
hasura.planx.uk/migrations/1715929881942_run_sql_migration/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
40 changes: 40 additions & 0 deletions
40
hasura.planx.uk/migrations/1715929881942_run_sql_migration/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_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', | ||
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; |