Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: contribution cc hover cc search delete question #1057

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions targets/frontend/src/components/contributions/answers/Answer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { AlertColor, Box, Stack, Typography } from "@mui/material";
import {
AlertColor,
Box,
Stack,
Tooltip,
TooltipProps,
Typography,
styled,
tooltipClasses,
} from "@mui/material";
import React, { useState } from "react";
import { useUser } from "src/hooks/useUser";

Expand All @@ -11,6 +20,7 @@ import { statusesMapping } from "../status/data";
import { SnackBar } from "../../utils/SnackBar";
import { Breadcrumb, BreadcrumbLink } from "src/components/utils";
import { AnswerForm } from "./AnswerForm";
import { fr } from "@codegouvfr/react-dsfr";

export type ContributionsAnswerProps = {
id: string;
Expand Down Expand Up @@ -77,7 +87,19 @@ export const ContributionsAnswer = ({
{answer?.question?.content}
</>
</BreadcrumbLink>
<BreadcrumbLink>{answer?.agreement?.id}</BreadcrumbLink>
<BreadcrumbLink>
<HtmlTooltip
title={
<>
<Typography color="inherit">
{answer?.agreement?.name}
</Typography>
</>
}
>
<Typography>{answer?.agreement?.id}</Typography>
</HtmlTooltip>
</BreadcrumbLink>
</Breadcrumb>
{answer?.status && (
<div style={{ color: statusesMapping[answer?.status.status].color }}>
Expand Down Expand Up @@ -106,3 +128,15 @@ export const ContributionsAnswer = ({
</>
);
};

const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => (
<Tooltip {...props} classes={{ popper: className }} />
))(({ theme }) => ({
[`& .${tooltipClasses.tooltip}`]: {
backgroundColor: fr.colors.decisions.background.default.grey.hover,
color: fr.colors.decisions.text.default.grey.default,
maxWidth: 220,
fontSize: theme.typography.pxToRem(12),
border: `1px solid ${fr.colors.decisions.border.default.grey.default}`,
},
}));
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ export const AnswerForm = ({
name="cdtnReferences"
control={control}
disabled={isNotEditable(answer)}
idcc={
answer.agreement?.id
? parseInt(answer.agreement?.id).toString()
: undefined
}
/>
<Stack direction="row" justifyContent="end" spacing={2} padding={2}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const answerBase: AnswerWithStatus = {
contentFichesSpDocument: null,
status: {
status: "TODO",
createdAt: new Date().toISOString(),
},
updateDate: "29/09/2023",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ type Props = {
name: string;
control: Control<any>;
disabled?: boolean;
idcc?: string;
};

export const CdtnReferenceInput = ({
name,
control,
disabled = false,
idcc,
}: Props): React.ReactElement => (
<ReferenceInput<CdtnReference>
isMultiple={true}
Expand All @@ -23,6 +25,7 @@ export const CdtnReferenceInput = ({
disabled={disabled}
control={control}
fetcher={useContributionSearchCdtnReferencesQuery}
idcc={idcc}
isEqual={(option, value) =>
value.document.cdtnId === option.document.cdtnId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type Props<Type> = {
label: string;
name: string;
control: Control<any>;
fetcher: (query: string | undefined) => Result<Type>;
fetcher: (query: string | undefined, idcc?: string) => Result<Type>;
isEqual: (value: Type, option: Type) => boolean;
getLabel: (option: Type) => string;
onClick: (value: Type) => void;
Expand All @@ -29,6 +29,7 @@ type Props<Type> = {
| "warning";
disabled: boolean;
isMultiple?: true;
idcc?: string;
};

export const ReferenceInput = <Type,>({
Expand All @@ -42,9 +43,10 @@ export const ReferenceInput = <Type,>({
color,
disabled,
isMultiple,
idcc,
}: Props<Type>): ReactElement | null => {
const [query, setQuery] = useState<string | undefined>();
const { data, fetching, error } = fetcher(query);
const { data, fetching, error } = fetcher(query, idcc);

const [open, setOpen] = useState(false);
const [options, setOptions] = useState<readonly Type[]>([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ export const getSlugFromUrl = (query: string | undefined): string => {
};

export const SearchCdtnReferencesQuery = `
query SearchCdtnReferences($sources: [String!], $slug: String, $title: String) {
query SearchCdtnReferences($sources: [String!], $slug: String, $title: String, $slugRegex: String) {
documents(where: {
_or: [{
title: {_ilike: $title}
}, {
slug: {_eq: $slug}
}],
slug: { _regex: $slugRegex },
is_available: {_eq: true},
is_published: {_eq: true},
source: {_in: $sources}
Expand All @@ -46,10 +47,14 @@ query SearchCdtnReferences($sources: [String!], $slug: String, $title: String) {
`;

export const useContributionSearchCdtnReferencesQuery = (
query: string | undefined
query: string | undefined,
idcc?: string
): Result<Pick<CdtnReference, "document">> => {
const slug = getSlugFromUrl(query);
const title = getNormalizedTitle(slug);
const slugRegex = `^(${idcc ? `${idcc}|` : ""}[^0-9])${
idcc ? `{${idcc.length}}` : ""
}[\-a-zA-Z0-9_]+$`;
const [{ data, fetching, error }] = useQuery<SearchCdtnReferencesQueryResult>(
{
query: SearchCdtnReferencesQuery,
Expand All @@ -66,6 +71,7 @@ export const useContributionSearchCdtnReferencesQuery = (
],
slug,
title,
slugRegex,
},
}
);
Expand Down
7 changes: 5 additions & 2 deletions targets/frontend/src/components/forms/EditionField/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,12 @@ const StyledEditorContent = styled(EditorContent)(() => {
},
".details": {
display: "flex",
margin: "1rem 0",
border: "0",
padding: "0.5rem",
padding: "1rem 0",
borderTop: `1px solid ${fr.colors.decisions.text.default.grey.default}`,
":first-child": {
border: "none",
},
"> button": {
display: "flex",
cursor: "pointer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ export const MenuSpecial = ({ editor }: { editor: Editor | null }) => {
<GridOnIcon />
</button>
<button
onClick={() =>
editor.isActive("details")
? editor.chain().focus().unsetDetails().run()
: editor.chain().focus().setDetails().run()
}
onClick={() => editor.chain().focus().setDetails().run()}
className={editor.isActive("details") ? "is-active" : ""}
type="button"
title="Ajouter un accordéon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export const MenuStyle = ({ editor }: { editor: Editor | null }) => {
</button>
<button
onClick={() => {
editor.isActive("details")
? editor.chain().focus().unsetDetails().run()
: editor.chain().focus().setDetails().run();
editor.chain().focus().setDetails().run();
}}
className={editor.isActive("details") ? "is-active" : ""}
type="button"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
delete from contribution.questions
where "order" = any(
array [2, 49, 3, 32, 21, 22, 24, 25, 27, 28, 30, 31]
);
Loading