Skip to content

Commit

Permalink
feat: Setup query, routing, and placeholder Feedbac component
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed May 17, 2024
1 parent d7d08eb commit 386c755
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Box from "@mui/material/Box";
import React from "react";
import { Feedback } from "routes/feedback";

interface Props {
feedback: Feedback[];
}

export const FeedbackPage: React.FC<Props> = ({ feedback }) => {
return (
<Box component="pre" sx={{ fontSize: 12, overflowY: "auto" }}>
{JSON.stringify(feedback, null, 4)}
</Box>
);
};
73 changes: 73 additions & 0 deletions editor.planx.uk/src/routes/feedback.tsx
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;
2 changes: 2 additions & 0 deletions editor.planx.uk/src/routes/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ const routes = compose(
};
}),

"/feedback": lazy(() => import("./feedback")),

"/nodes": compose(
withView((req) => {
const [flow, ...breadcrumbs] = req.params.flow.split(",");
Expand Down

0 comments on commit 386c755

Please sign in to comment.