move move frontend to progress-test
This commit is contained in:
18
app/javascript/utils/graphql/NodeId.ts
Normal file
18
app/javascript/utils/graphql/NodeId.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Node } from "../../__generated__/graphql-schema";
|
||||
|
||||
const SEPARATOR_TOKEN = "-";
|
||||
|
||||
type Decoded = { typeName: string; id: string };
|
||||
|
||||
const decode = (id: Node["id"]): Decoded => {
|
||||
const raw = Buffer.from(id, "base64").toString("ascii");
|
||||
|
||||
const [nodeTypeName, nodeId] = raw.split(SEPARATOR_TOKEN);
|
||||
|
||||
return {
|
||||
id: nodeId,
|
||||
typeName: nodeTypeName,
|
||||
};
|
||||
};
|
||||
|
||||
export const NodeId = { decode };
|
||||
1
app/javascript/utils/graphql/index.ts
Normal file
1
app/javascript/utils/graphql/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./NodeId";
|
||||
1
app/javascript/utils/index.ts
Normal file
1
app/javascript/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./strings";
|
||||
1
app/javascript/utils/math/index.ts
Normal file
1
app/javascript/utils/math/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./range";
|
||||
5
app/javascript/utils/math/range.ts
Normal file
5
app/javascript/utils/math/range.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const range = (start: number, end: number) => {
|
||||
const length = end - start;
|
||||
|
||||
return Array.from({ length }, (_, i) => start + i);
|
||||
};
|
||||
1
app/javascript/utils/plugins/index.ts
Normal file
1
app/javascript/utils/plugins/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./wiris";
|
||||
7
app/javascript/utils/plugins/wiris.ts
Normal file
7
app/javascript/utils/plugins/wiris.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export const loadWIRISplugin = () => {
|
||||
const script = document.createElement("script");
|
||||
script.src = process.env.REACT_APP_WIRIS_PLUGIN_URL ?? "";
|
||||
script.async = true;
|
||||
|
||||
document.body.appendChild(script);
|
||||
};
|
||||
1
app/javascript/utils/questions/index.ts
Normal file
1
app/javascript/utils/questions/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./questionValidations";
|
||||
100
app/javascript/utils/questions/questionValidations.ts
Normal file
100
app/javascript/utils/questions/questionValidations.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
Question,
|
||||
QuestionCreateInput,
|
||||
} from "../../__generated__/graphql-schema";
|
||||
|
||||
export type QuestionEditForm = Question & {
|
||||
subjectId: string;
|
||||
reviewerId: string;
|
||||
};
|
||||
|
||||
export const validateQuestionInputs = (inputs: QuestionCreateInput) => {
|
||||
/**
|
||||
* transform string with lenght 0 to undefined
|
||||
*/
|
||||
const tempValues: { [key: string]: any } = {};
|
||||
|
||||
Object.keys(inputs).forEach((key: string) => {
|
||||
const value = (inputs as any)[key];
|
||||
|
||||
tempValues[key] = value === "" ? undefined : value;
|
||||
});
|
||||
|
||||
const values = tempValues as QuestionCreateInput;
|
||||
|
||||
const errors = [];
|
||||
|
||||
const {
|
||||
alternatives,
|
||||
authorshipYear,
|
||||
body,
|
||||
explanation,
|
||||
references,
|
||||
difficulty,
|
||||
bloomTaxonomy,
|
||||
checkType,
|
||||
subjectId,
|
||||
authorship,
|
||||
intention,
|
||||
reviewerUserId,
|
||||
} = values;
|
||||
|
||||
if (!body || body.length <= 5) {
|
||||
errors.push(`"Enunciado" não preenchido.`);
|
||||
}
|
||||
|
||||
const answer = alternatives?.find((a) => a.correct);
|
||||
|
||||
if (!answer?.text?.length) {
|
||||
errors.push(`"Resposta Correta" não preenchida.`);
|
||||
}
|
||||
|
||||
if (!explanation || explanation.length <= 5) {
|
||||
errors.push(`"Explicação" não preenchida.`);
|
||||
}
|
||||
|
||||
if (!references || references.length <= 5) {
|
||||
errors.push(`"Referências" não preenchidas.`);
|
||||
}
|
||||
|
||||
const distractors = alternatives?.filter((a) => !a.correct);
|
||||
const emptyDistractores = distractors?.filter((a) => !a.text?.length);
|
||||
|
||||
if (emptyDistractores?.length) {
|
||||
errors.push(`Um ou mais "Distratores" não preenchidos.`);
|
||||
}
|
||||
|
||||
if (!authorship) {
|
||||
errors.push(`"Fonte" não preenchida.`);
|
||||
}
|
||||
|
||||
if (!authorshipYear) {
|
||||
errors.push(`"Ano" não preenchido.`);
|
||||
}
|
||||
|
||||
if (!difficulty) {
|
||||
errors.push(`"Grau de Dificuldade" não preenchido.`);
|
||||
}
|
||||
|
||||
if (!subjectId) {
|
||||
errors.push(`"Assunto" não preenchido.`);
|
||||
}
|
||||
|
||||
if (!checkType) {
|
||||
errors.push(`"Tipo" não preenchido.`);
|
||||
}
|
||||
|
||||
if (!bloomTaxonomy) {
|
||||
errors.push(`"Habilidade" não preenchida.`);
|
||||
}
|
||||
|
||||
if (!intention) {
|
||||
errors.push(`"Intenção" não preenchido.`);
|
||||
}
|
||||
|
||||
if (!reviewerUserId) {
|
||||
errors.push(`"Revisor" não preenchido.`);
|
||||
}
|
||||
|
||||
return errors;
|
||||
};
|
||||
2
app/javascript/utils/strings/classNames.ts
Normal file
2
app/javascript/utils/strings/classNames.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export const classNames = (...classes: string[]) =>
|
||||
classes.filter(Boolean).join(" ");
|
||||
1
app/javascript/utils/strings/index.ts
Normal file
1
app/javascript/utils/strings/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./classNames";
|
||||
27
app/javascript/utils/types.ts
Normal file
27
app/javascript/utils/types.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export const CHECK_TYPE = [
|
||||
{ value: "unique_answer", label: "Resposta Única" },
|
||||
{ value: "incomplete_affirmation", label: "Afirmação Incompleta" },
|
||||
{ value: "multiple_answer", label: "Resposta Múltipla" },
|
||||
{ value: "negative_focus", label: "Foco Negativo" },
|
||||
{ value: "assertion_and_reason", label: "Asserção e Razão" },
|
||||
{ value: "gap", label: "Lacuna" },
|
||||
{ value: "interpretation", label: "Interpretação" },
|
||||
{ value: "association", label: "Associação" },
|
||||
{ value: "ordering_or_ranking", label: "Ordenação ou Seriação" },
|
||||
{ value: "constant_alternatives", label: "Alternativas Constantes" },
|
||||
];
|
||||
|
||||
export const DIFFICULTY = [
|
||||
{ value: "easy", label: "Fácil" },
|
||||
{ value: "medium", label: "Média" },
|
||||
{ value: "hard", label: "Difícil" },
|
||||
];
|
||||
|
||||
export const BLOOM_TAXONOMY = [
|
||||
{ value: "remember", label: "Recordar" },
|
||||
{ value: "understand", label: "Compreender" },
|
||||
{ value: "apply", label: "Aplicar" },
|
||||
{ value: "analyze", label: "Analisar" },
|
||||
{ value: "evaluate", label: "Avaliar" },
|
||||
{ value: "create", label: "Criar" },
|
||||
];
|
||||
Reference in New Issue
Block a user