From ce7d38e95bfc60697e03a6881e2098fe5af6f578 Mon Sep 17 00:00:00 2001 From: WindowsCrashed Date: Fri, 25 Aug 2023 23:44:31 -0300 Subject: [PATCH] add filters query --- .../pages/assessment/NewAssessmentManual.tsx | 12 +- .../assessment/components/FiltersSideBar.tsx | 106 +++++++++++------- .../assessment/components/QuestionCard.tsx | 5 +- .../components/SelectFilterField.tsx | 2 +- 4 files changed, 74 insertions(+), 51 deletions(-) diff --git a/app/javascript/pages/assessment/NewAssessmentManual.tsx b/app/javascript/pages/assessment/NewAssessmentManual.tsx index 4856477..b86cf40 100644 --- a/app/javascript/pages/assessment/NewAssessmentManual.tsx +++ b/app/javascript/pages/assessment/NewAssessmentManual.tsx @@ -41,17 +41,13 @@ const QUESTIONS_QUERY = gql` ` export const NewAssessementManual = () => { - // const [questions, setQuestions] = useState([ - // "Question 1", "Question 2", "Question 3", "Question 4", - // "Question 5", "Question 6", "Question 7"]) const [questions, setQuestions] = useState([]) const [selectedQuestions, setSelectedQuestions] = useState<{id: string, label: string, removeHandler: Function}[]>([]) - const { fetchMore } = useQuery(QUESTIONS_QUERY, { - onCompleted: (respose) => { - const { questions: questionConnection } = respose + useQuery(QUESTIONS_QUERY, { + onCompleted: (response) => { + const { questions: questionConnection } = response setQuestions(questionConnection.nodes as Question[]) - console.log(respose) }, fetchPolicy: "network-only" }) @@ -71,8 +67,6 @@ export const NewAssessementManual = () => { setSelectedQuestions([]) } - fetchMore({}) - return ( <> diff --git a/app/javascript/pages/assessment/components/FiltersSideBar.tsx b/app/javascript/pages/assessment/components/FiltersSideBar.tsx index b87b665..8cba45a 100644 --- a/app/javascript/pages/assessment/components/FiltersSideBar.tsx +++ b/app/javascript/pages/assessment/components/FiltersSideBar.tsx @@ -1,55 +1,83 @@ -import React, { FC, } from "react"; +import React, { FC, useState, } from "react"; import { SideBar } from "./SideBar"; -import { SelectedQuestionCard } from "./SelectedQuestionCard"; import { Button } from "../../../components"; import { SelectFilterField } from "./SelectFilterField"; import { RangeFilterField } from "./RangeFilterField"; +import { BLOOM_TAXONOMY, CHECK_TYPE, DIFFICULTY } from "../../../utils/types"; +import { gql, useQuery } from "@apollo/client"; +import { Axis, Category, Query, Subject } from "../../../__generated__/graphql-schema"; + +const FILTERS_QUERY = gql` + query { + categories { + nodes { + id + name + } + } + axes { + nodes { + id + name + } + } + subjects { + nodes { + id + name + } + } + } +` type Props = { - questions?: { - id: string, label: string, removeHandler: Function - }[] + } export const FiltersSideBar: FC = () => { + const [categories, setCategories] = useState([]) + const [axis, setAxis] = useState([]) + const [subjects, setSubjects] = useState([]) + + const difficulties = DIFFICULTY.map(item => ({id: item.value, label: item.label})) + const bloomTaxonomyTypes = BLOOM_TAXONOMY.map(item => ({id: item.value, label: item.label})) + const checkTypes = CHECK_TYPE.map(item => ({id: item.value, label: item.label})) + const authorshipTypes = [ + {id: 1, label: 'Própria'}, + {id: 2, label: 'Outro'}, + ] + + useQuery(FILTERS_QUERY, { + onCompleted: (response) => { + const { + categories: categoriesConnection, + axes: axisConnection, + subjects: subjectConnection + } = response + setCategories(categoriesConnection.nodes as Category[]) + setAxis(axisConnection.nodes as Axis[]) + setSubjects(subjectConnection.nodes as Subject[]) + }, + fetchPolicy: "network-only" + }) + return (
- - - - - - - + + ({id: item.id, label: item.name})) + }/> + ({id: item.id, label: item.name})) + }/> + ({id: item.id, label: item.name})) + }/> + + +