From d03b1c9183d0713a19354b4cb4bcea651d66508e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Wed, 10 Aug 2022 17:38:02 +0000 Subject: [PATCH 1/3] hide pagination when there no result on question query --- .../pages/question/List/QuestionsList.tsx | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/javascript/pages/question/List/QuestionsList.tsx b/app/javascript/pages/question/List/QuestionsList.tsx index 725f36b..5f144cd 100644 --- a/app/javascript/pages/question/List/QuestionsList.tsx +++ b/app/javascript/pages/question/List/QuestionsList.tsx @@ -59,23 +59,25 @@ export const QuestionsList: FC = ({ questions, title, pagination }) => {

{title}

-
- - Página: {pageCount} - -
+ {questions.length > 0 && +
+ + Página: {pageCount} + +
+ }

From f9fc5fc3a7c5529ec712119a66003019022d36d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Wed, 10 Aug 2022 17:59:04 +0000 Subject: [PATCH 2/3] fix feature form authorship options select --- app/javascript/pages/question/Form/Form.tsx | 13 ++++++++++--- .../pages/question/Form/FormContext.tsx | 12 +++--------- .../steps/FeaturesFromStep/FeaturesFormStep.tsx | 15 ++++++--------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/javascript/pages/question/Form/Form.tsx b/app/javascript/pages/question/Form/Form.tsx index 304815a..2f046fa 100644 --- a/app/javascript/pages/question/Form/Form.tsx +++ b/app/javascript/pages/question/Form/Form.tsx @@ -1,5 +1,5 @@ import React, {FC, useState} from 'react' -import {useForm} from 'react-hook-form'; +import {FieldValue, FieldValues, useForm} from 'react-hook-form'; import {ExclamationCircleIcon} from '@heroicons/react/outline'; import {useHistory} from "react-router-dom"; import {useDispatch, useSelector} from "react-redux"; @@ -57,7 +57,14 @@ export const Form: FC = ({question, onSubmit, onDraftSubmit, alert}) => { const [validationErrors, setValidationErrors] = useState([]) const [confirmSaveDialogIsOpen, setConfirmFinishDialogIsOpen] = useState(false) const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false) - const {register, control, setValue, getValues, reset, formState} = useForm() + const formHooks = useForm({ + defaultValues: { + authorship: 'UNIFESO', + authorshipYear: new Date().getFullYear().toString(), + } + }) + const {register, control, setValue, getValues, reset, formState, resetField} = formHooks + const [currentStep, setCurrentStep] = useState(0) const unsavedChanges = useSelector((state: RootState) => state.unsavedChanges) const history = useHistory() @@ -119,7 +126,7 @@ export const Form: FC = ({question, onSubmit, onDraftSubmit, alert}) => { } return ( - + {alert && ( )} diff --git a/app/javascript/pages/question/Form/FormContext.tsx b/app/javascript/pages/question/Form/FormContext.tsx index 9c611ce..645e113 100644 --- a/app/javascript/pages/question/Form/FormContext.tsx +++ b/app/javascript/pages/question/Form/FormContext.tsx @@ -1,15 +1,9 @@ -import React, { FC, useContext } from 'react' -import { Control, FieldValues } from 'react-hook-form'; +import React, { FC, useContext } from 'react'; +import { FieldValues, UseFormReturn } from 'react-hook-form'; import { Question } from '../../../__generated__/graphql-schema'; -type FormContextHooks = { - register: any - setValue: Function - control: Control -} - type FormContextProps = { - hooks: FormContextHooks + hooks: UseFormReturn question?: Question } diff --git a/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx b/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx index b9c6c8c..3469346 100644 --- a/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx +++ b/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx @@ -25,19 +25,20 @@ export const FeaturesFragment = gql` ` export const FeaturesFormStep: FC = () => { - const { question, hooks: { setValue, register } } = useFormProvider(); + const { question, hooks: { setValue, register, formState, getValues } } = useFormProvider(); const currentYear = new Date().getFullYear(); + if (!question) return null + const { - authorship, - authorshipYear, difficulty, bloomTaxonomy, checkType, - } = question || {} as Question + } = question - const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO" || authorship === undefined || authorship === null); + const authorship = getValues('authorship') + const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO") const handleOwnCheck = (value: string) => { if (value === 'UNIFESO') { @@ -61,7 +62,6 @@ export const FeaturesFormStep: FC = () => {
{
{
@@ -106,7 +104,6 @@ export const FeaturesFormStep: FC = () => { min="1999" max={currentYear} step="1" - defaultValue={authorshipYear ?? new Date().getFullYear().toString()} readOnly={!!ownQuestion} />
From 483234de3187b937c6b39044f83a2e5059483621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Geonizeli?= Date: Wed, 10 Aug 2022 18:26:17 +0000 Subject: [PATCH 3/3] fix reviews query --- .../resolvers/reviewers_query_resolver.rb | 3 +- app/javascript/pages/question/Form/Form.tsx | 7 +- .../FeaturesFromStep/FeaturesFormStep.tsx | 70 +++++++++---------- app/javascript/pages/question/formatInputs.ts | 1 + 4 files changed, 42 insertions(+), 39 deletions(-) diff --git a/app/graphql/resolvers/reviewers_query_resolver.rb b/app/graphql/resolvers/reviewers_query_resolver.rb index a61fe5e..5a27465 100644 --- a/app/graphql/resolvers/reviewers_query_resolver.rb +++ b/app/graphql/resolvers/reviewers_query_resolver.rb @@ -8,8 +8,7 @@ module Resolvers def resolve UserPolicy::Scope.new(@context[:current_user], User) .resolve - .joins(:roles) - .where(roles: { name: %i[teacher nde] }) + .where(roles: %i[teacher nde]) .where.not(id: @context[:current_user].id) .distinct end diff --git a/app/javascript/pages/question/Form/Form.tsx b/app/javascript/pages/question/Form/Form.tsx index 2f046fa..1d83ca1 100644 --- a/app/javascript/pages/question/Form/Form.tsx +++ b/app/javascript/pages/question/Form/Form.tsx @@ -59,8 +59,13 @@ export const Form: FC = ({question, onSubmit, onDraftSubmit, alert}) => { const [leaveDialogIsOpen, setLeaveDialogIsOpen] = useState(false) const formHooks = useForm({ defaultValues: { - authorship: 'UNIFESO', + authorship: question?.authorship ?? 'UNIFESO', + authorshipType: question?.authorship === 'UNIFESO' ? 'UNIFESO' : 'OTHER', authorshipYear: new Date().getFullYear().toString(), + difficulty: question?.difficulty, + checkType: question?.checkType, + bloomTaxonomy: question?.bloomTaxonomy, + intention: question?.intention, } }) const {register, control, setValue, getValues, reset, formState, resetField} = formHooks diff --git a/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx b/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx index 3469346..1efc2d7 100644 --- a/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx +++ b/app/javascript/pages/question/Form/steps/FeaturesFromStep/FeaturesFormStep.tsx @@ -1,20 +1,23 @@ -import React, { FC, useState } from "react"; import { gql } from "@apollo/client"; +import React, { FC, useState } from "react"; import { Card } from "../../../../../components"; -import { SubjectSelect, SubjectFragment } from "./SubjectSelect"; -import { ReviewerSelect, ReviewerFragment } from "./ReviewSelect"; -import { useFormProvider } from '../../FormContext' +import { useFormProvider } from "../../FormContext"; +import { ReviewerFragment, ReviewerSelect } from "./ReviewSelect"; +import { SubjectFragment, SubjectSelect } from "./SubjectSelect"; -import { BLOOM_TAXONOMY, CHECK_TYPE, DIFFICULTY } from "../../../../../utils/types"; -import { Question } from "../../../../../__generated__/graphql-schema"; +import { + BLOOM_TAXONOMY, + CHECK_TYPE, + DIFFICULTY, +} from "../../../../../utils/types"; export const FeaturesFragment = gql` ${ReviewerFragment} ${SubjectFragment} fragment FeaturesFields on Question { - ... ReviewerFields - ... SubjectFields + ...ReviewerFields + ...SubjectFields authorship authorshipYear difficulty @@ -22,31 +25,24 @@ export const FeaturesFragment = gql` intention bloomTaxonomy } -` +`; export const FeaturesFormStep: FC = () => { - const { question, hooks: { setValue, register, formState, getValues } } = useFormProvider(); - + const { + hooks: { setValue, register, getValues }, + } = useFormProvider(); const currentYear = new Date().getFullYear(); - if (!question) return null - - const { - difficulty, - bloomTaxonomy, - checkType, - } = question - - const authorship = getValues('authorship') - const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO") + const authorship = getValues("authorship"); + const [ownQuestion, setOwnQuestion] = useState(authorship === "UNIFESO"); const handleOwnCheck = (value: string) => { - if (value === 'UNIFESO') { - setOwnQuestion(true) + if (value === "UNIFESO") { + setOwnQuestion(true); setValue("authorship", "UNIFESO"); setValue("authorshipYear", currentYear.toString()); } else { - setOwnQuestion(false) + setOwnQuestion(false); setValue("authorship", ""); setValue("authorshipYear", ""); } @@ -62,23 +58,29 @@ export const FeaturesFormStep: FC = () => {
handleOwnCheck("UNIFESO")} /> - +
handleOwnCheck("")} /> - +
@@ -87,7 +89,7 @@ export const FeaturesFormStep: FC = () => {
@@ -98,7 +100,7 @@ export const FeaturesFormStep: FC = () => {

Ano

{

Grau de Dificuldade