Skip to content

Commit

Permalink
fix: admin search content (#1019)
Browse files Browse the repository at this point in the history
* fix: sur la recherche de contenu lié

* fix: recherche par slug

* fix: ajout de la recherche par mot clé + tri par date creation

* feat: ajout de l'option SP pour les generiques

* feat: add url field

* chore: handle down migration

* chore: handle down migration

---------

Co-authored-by: Victor Zeinstra <[email protected]>
  • Loading branch information
Viczei and Victor Zeinstra authored Sep 20, 2023
1 parent 5039397 commit f1e3b18
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 47 deletions.
44 changes: 35 additions & 9 deletions targets/frontend/src/components/contributions/answers/Answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 (
<>
<Grid container>
Expand Down Expand Up @@ -174,7 +192,7 @@ export const ContributionsAnswer = ({
}}
/>
</FormControl>
{answer && !isCodeDuTravail(answer) && (
{answer && (
<FormRadioGroup
name="otherAnswer"
label="Type de réponse"
Expand All @@ -185,17 +203,25 @@ export const ContributionsAnswer = ({
label: "Afficher la réponse",
value: "ANSWER",
},
{
label: "La convention collective ne prévoit rien",
value: "NOTHING",
},
{
label: "Nous n'avons pas la réponse",
value: "UNKNOWN",
},
...(isCodeDuTravail(answer)
? genericResponseOptions
: agreementResponseOptions),
]}
/>
)}
{answer && isCodeDuTravail(answer) && (
<FormControl>
<FormTextField
label="Url Service public"
name="urlSp"
disabled={isNotEditable(answer)}
control={control}
rules={{
required: answer && answer.otherAnswer === "SP",
}}
/>
</FormControl>
)}
{answer && !isCodeDuTravail(answer) && (
<KaliReferenceInput
name="kaliReferences"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
} from "./answerReferences";

export const contributionAnswerUpdateMutation = `
mutation contributionAnswerUpdate($id: uuid!, $content: String, $otherAnswer: String, $status: statustype!, $userId: uuid!, $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}) {
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}) {
__typename
}
insert_contribution_answer_statuses_one(object: {status: $status, user_id: $userId, answer_id: $id}) {
Expand Down Expand Up @@ -49,6 +49,7 @@ export type MutationProps = Pick<
Answer,
| "id"
| "otherAnswer"
| "urlSp"
| "content"
| "kaliReferences"
| "legiReferences"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ query contribution_answer($id: uuid) {
content
otherAnswer: other_answer
updatedAt: updated_at
urlSp: url_sp
question {
id
content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,34 @@ import { useQuery } from "urql";
import { CdtnReference, Document } from "../../type";
import { Result } from "./ReferenceInput";

export const contributionSearchCdtnReferencesSearch = `
query SearchCdtnReferences($query: String, $sources: [String!]) {
documents(where: {
_or: [
{slug: {_ilike: $query}},
{title: {_ilike: $query}}
],
is_available: {_eq: true},
is_published: {_eq: true},
source: {_in: $sources}},
limit: 10
) {
title
cdtnId: cdtn_id
source
slug
}
}
`;

type QueryResult = {
documents: Document[];
};

export const useContributionSearchCdtnReferencesQuery = (
query: string | undefined
): Result<Pick<CdtnReference, "document">> => {
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<QueryResult>({
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
Expand All @@ -68,7 +49,10 @@ export const useContributionSearchCdtnReferencesQuery = (
"outils",
"modeles_de_courriers",
"contributions",
"fiches_service_public",
],
slug,
title,
},
});
return {
Expand Down
3 changes: 2 additions & 1 deletion targets/frontend/src/components/contributions/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ select_permissions:
- other_answer
- question_id
- updated_at
- url_sp
filter: {}
allow_aggregations: true
update_permissions:
Expand All @@ -71,6 +72,7 @@ update_permissions:
columns:
- content
- other_answer
- url_sp
filter: {}
check: null
set:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "contribution"."answers" drop column "url_sp";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "contribution"."answers" add column "url_sp" text
null;

0 comments on commit f1e3b18

Please sign in to comment.