diff --git a/targets/frontend/src/components/contributions/answers/Answer.tsx b/targets/frontend/src/components/contributions/answers/Answer.tsx index b0a106270..5215da97f 100644 --- a/targets/frontend/src/components/contributions/answers/Answer.tsx +++ b/targets/frontend/src/components/contributions/answers/Answer.tsx @@ -113,6 +113,7 @@ export const ContributionsAnswer = ({ otherAnswer: data.otherAnswer, status: newStatus, userId: user?.id, + urlSp: data.urlSp, kaliReferences: data.kaliReferences, legiReferences: data.legiReferences, cdtnReferences: data.cdtnReferences, @@ -127,6 +128,23 @@ export const ContributionsAnswer = ({ setSnack({ open: true, severity: "error", message: e.message }); } }; + + const agreementResponseOptions = [ + { + label: "La convention collective ne prévoit rien", + value: "NOTHING", + }, + { + label: "Nous n'avons pas la réponse", + value: "UNKNOWN", + }, + ]; + const genericResponseOptions = [ + { + label: "Utiliser la fiche service public", + value: "SP", + }, + ]; return ( <> @@ -174,7 +192,7 @@ export const ContributionsAnswer = ({ }} /> - {answer && !isCodeDuTravail(answer) && ( + {answer && ( )} + {answer && isCodeDuTravail(answer) && ( + + + + )} {answer && !isCodeDuTravail(answer) && ( > => { - const querySplit = query?.split(/[ -,]/); - const slugQuery = querySplit?.map( - (text) => `{slug: {_ilike: "%${text.normalize()}%"}}` - ).join(`, - `); - const titleQuery = querySplit?.map( - (text) => `{title: {_ilike: "%${text.normalize()}%"}}` - ).join(`, - `); + const [slug] = query?.split("/").reverse() ?? [""]; + const title = `%${slug + ?.split(/[\ \-\,]/gm) + ?.map((text) => text.normalize().replace(/[\u0300-\u036f]/g, "")) + .join("%")}%`; const [{ data, fetching, error }] = useQuery({ query: ` - query SearchCdtnReferences($sources: [String!]) { + query SearchCdtnReferences($sources: [String!], $slug: String, $title: String) { documents(where: { - _or: [ - {_and: [${slugQuery}]} - {_and: [${titleQuery}]} - ], + _or: [{ + title: {_ilike: $title} + }, { + slug: {_eq: $slug} + }], is_available: {_eq: true}, is_published: {_eq: true}, - source: {_in: $sources}}, + source: {_in: $sources} + }, + order_by: { + created_at: asc + }, limit: 10 ) { title @@ -68,7 +49,10 @@ export const useContributionSearchCdtnReferencesQuery = ( "outils", "modeles_de_courriers", "contributions", + "fiches_service_public", ], + slug, + title, }, }); return { diff --git a/targets/frontend/src/components/contributions/type.ts b/targets/frontend/src/components/contributions/type.ts index cc88c519f..814641565 100644 --- a/targets/frontend/src/components/contributions/type.ts +++ b/targets/frontend/src/components/contributions/type.ts @@ -89,13 +89,14 @@ export type CdtnReference = { document: Document; }; -export type OtherAnswer = "ANSWER" | "NOTHING" | "UNKNOWN"; +export type OtherAnswer = "ANSWER" | "NOTHING" | "UNKNOWN" | "SP"; export type Answer = { id: string; agreementId: string; questionId: string; otherAnswer?: OtherAnswer; + urlSp?: string; agreement: Agreement; statuses: AnswerStatus[]; status: AnswerStatus; diff --git a/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml b/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml index bc2df4b0c..2796a921a 100644 --- a/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml +++ b/targets/hasura/metadata/databases/default/tables/contribution_answers.yaml @@ -63,6 +63,7 @@ select_permissions: - other_answer - question_id - updated_at + - url_sp filter: {} allow_aggregations: true update_permissions: @@ -71,6 +72,7 @@ update_permissions: columns: - content - other_answer + - url_sp filter: {} check: null set: diff --git a/targets/hasura/migrations/default/1695203843006_alter_table_contribution_answers_add_column_url_sp/down.sql b/targets/hasura/migrations/default/1695203843006_alter_table_contribution_answers_add_column_url_sp/down.sql new file mode 100644 index 000000000..c3049f84f --- /dev/null +++ b/targets/hasura/migrations/default/1695203843006_alter_table_contribution_answers_add_column_url_sp/down.sql @@ -0,0 +1 @@ +alter table "contribution"."answers" drop column "url_sp"; diff --git a/targets/hasura/migrations/default/1695203843006_alter_table_contribution_answers_add_column_url_sp/up.sql b/targets/hasura/migrations/default/1695203843006_alter_table_contribution_answers_add_column_url_sp/up.sql new file mode 100644 index 000000000..c0f5cf458 --- /dev/null +++ b/targets/hasura/migrations/default/1695203843006_alter_table_contribution_answers_add_column_url_sp/up.sql @@ -0,0 +1,2 @@ +alter table "contribution"."answers" add column "url_sp" text + null;