From a5901403d289602c24f7b87c6b96ebeb2af39486 Mon Sep 17 00:00:00 2001 From: Caroline <4971715+carolineBda@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:25:44 +0200 Subject: [PATCH] fix(contributions): rename otherAnswer field by contentType (#1027) --- .../src/components/contributions/answers/Answer.tsx | 10 +++++----- .../contributions/answers/answer.mutation.ts | 6 +++--- .../components/contributions/answers/answer.query.ts | 2 +- .../contributions/questions/Question.query.ts | 2 +- targets/frontend/src/components/contributions/type.ts | 4 ++-- .../databases/default/tables/contribution_answers.yaml | 4 ++-- .../down.sql | 1 + .../up.sql | 1 + 8 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/down.sql create mode 100644 targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/up.sql diff --git a/targets/frontend/src/components/contributions/answers/Answer.tsx b/targets/frontend/src/components/contributions/answers/Answer.tsx index 2895894d2..5b72e08f0 100644 --- a/targets/frontend/src/components/contributions/answers/Answer.tsx +++ b/targets/frontend/src/components/contributions/answers/Answer.tsx @@ -54,7 +54,7 @@ export const ContributionsAnswer = ({ values: answer, defaultValues: { content: "", - otherAnswer: "ANSWER", + contentType: "ANSWER", status: { status: "TODO", }, @@ -94,7 +94,7 @@ export const ContributionsAnswer = ({ await updateAnswer({ content: data.content, id: answer.id, - otherAnswer: data.otherAnswer, + contentType: data.contentType, status: newStatus, userId: user?.id, urlSp: data.urlSp, @@ -184,13 +184,13 @@ export const ContributionsAnswer = ({ disabled={isNotEditable(answer)} control={control} rules={{ - required: answer && answer.otherAnswer === "ANSWER", + required: answer && answer.contentType === "ANSWER", }} /> {answer && ( diff --git a/targets/frontend/src/components/contributions/answers/answer.mutation.ts b/targets/frontend/src/components/contributions/answers/answer.mutation.ts index bd24ac8e4..9db7d96bf 100644 --- a/targets/frontend/src/components/contributions/answers/answer.mutation.ts +++ b/targets/frontend/src/components/contributions/answers/answer.mutation.ts @@ -10,8 +10,8 @@ import { } from "./answerReferences"; export const contributionAnswerUpdateMutation = ` -mutation contributionAnswerUpdate($id: uuid!, $content: String, $otherAnswer: String, $status: statustype!, $userId: uuid!, $urlSp: String, $kaliReferences: [contribution_answer_kali_references_insert_input!]!, $legiReferences: [contribution_answer_legi_references_insert_input!]!, $otherReferences: [contribution_answer_other_references_insert_input!]!, $cdtnReferences: [contribution_answer_cdtn_references_insert_input!]!) { - update_contribution_answers_by_pk(pk_columns: {id: $id}, _set: {content: $content, other_answer: $otherAnswer, url_sp: $urlSp}) { +mutation contributionAnswerUpdate($id: uuid!, $content: String, $contentType: String, $status: statustype!, $userId: uuid!, $urlSp: String, $kaliReferences: [contribution_answer_kali_references_insert_input!]!, $legiReferences: [contribution_answer_legi_references_insert_input!]!, $otherReferences: [contribution_answer_other_references_insert_input!]!, $cdtnReferences: [contribution_answer_cdtn_references_insert_input!]!) { + update_contribution_answers_by_pk(pk_columns: {id: $id}, _set: {content: $content, content_type: $contentType, url_sp: $urlSp}) { __typename } insert_contribution_answer_statuses_one(object: {status: $status, user_id: $userId, answer_id: $id}) { @@ -48,7 +48,7 @@ mutation contributionAnswerUpdate($id: uuid!, $content: String, $otherAnswer: St export type MutationProps = Pick< Answer, | "id" - | "otherAnswer" + | "contentType" | "urlSp" | "content" | "kaliReferences" diff --git a/targets/frontend/src/components/contributions/answers/answer.query.ts b/targets/frontend/src/components/contributions/answers/answer.query.ts index 1cf63e386..fab077d99 100644 --- a/targets/frontend/src/components/contributions/answers/answer.query.ts +++ b/targets/frontend/src/components/contributions/answers/answer.query.ts @@ -12,7 +12,7 @@ query contribution_answer($id: uuid) { questionId: question_id agreementId: agreement_id content - otherAnswer: other_answer + contentType: content_type updatedAt: updated_at urlSp: url_sp question { diff --git a/targets/frontend/src/components/contributions/questions/Question.query.ts b/targets/frontend/src/components/contributions/questions/Question.query.ts index f441f3e45..e12834b7b 100644 --- a/targets/frontend/src/components/contributions/questions/Question.query.ts +++ b/targets/frontend/src/components/contributions/questions/Question.query.ts @@ -18,7 +18,7 @@ query SelectQuestion($questionId: uuid) { order_by: {agreement_id: asc} ) { id - otherAnswer: other_answer + contentType: content_type agreement { id name diff --git a/targets/frontend/src/components/contributions/type.ts b/targets/frontend/src/components/contributions/type.ts index e26c45fd8..003a1ade2 100644 --- a/targets/frontend/src/components/contributions/type.ts +++ b/targets/frontend/src/components/contributions/type.ts @@ -91,13 +91,13 @@ export type CdtnReference = { document: Document; }; -export type OtherAnswer = "ANSWER" | "NOTHING" | "UNKNOWN" | "SP"; +export type ContentType = "ANSWER" | "NOTHING" | "UNKNOWN" | "SP"; export type Answer = { id: string; agreementId: string; questionId: string; - otherAnswer?: OtherAnswer; + contentType?: ContentType; urlSp?: string; agreement: Agreement; statuses: AnswerStatus[]; diff --git a/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml b/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml index 2796a921a..e79c9c874 100644 --- a/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml +++ b/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml @@ -60,7 +60,7 @@ select_permissions: - agreement_id - content - id - - other_answer + - content_type - question_id - updated_at - url_sp @@ -71,7 +71,7 @@ update_permissions: permission: columns: - content - - other_answer + - content_type - url_sp filter: {} check: null diff --git a/targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/down.sql b/targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/down.sql new file mode 100644 index 000000000..87b92c203 --- /dev/null +++ b/targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/down.sql @@ -0,0 +1 @@ +alter table "contribution"."answers" rename column "content_type" to "other_answer"; diff --git a/targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/up.sql b/targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/up.sql new file mode 100644 index 000000000..86370378f --- /dev/null +++ b/targets/hasura/migrations/default/1695651246643_alter_table_contribution_answers_alter_column_other_answer/up.sql @@ -0,0 +1 @@ +alter table "contribution"."answers" rename column "other_answer" to "content_type";