-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:1007 admin liste des contenus modifiés lors dune maj des données…
… - page info (#1013) * feat: implementation du schéma de donnée page info * feat: implementation des pages info * fix: review * refactor: implement page info refactor * feat: implementation page creation * feat: add upsert + publish * feat: publish * feat: publish + refactor to module * chore: remove npmrc * fix: publish dep * feat: page info validation (#1040) * feat: zod validation page info * feat: implementation page info validation avec zod * feat: clean deepPartial * chore: clean --------- Co-authored-by: Victor Zeinstra <[email protected]> * chore: clean * chore: clean * chore: use helper text for error * feat: change url to regex check for files * chore: add test * chore: review * chore: yarn * refactor: use confirm modal * chore: downgrade next * fix: breadcrumb display * chore: clean --------- Co-authored-by: Victor Zeinstra <[email protected]>
- Loading branch information
Showing
80 changed files
with
3,394 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { FormGroup, FormControlLabel, Checkbox } from "@mui/material"; | ||
import React, { PropsWithChildren } from "react"; | ||
import { Controller } from "react-hook-form"; | ||
import { CommonFormProps } from "../type"; | ||
|
||
export type FormCheckboxProps = PropsWithChildren<CommonFormProps>; | ||
export const FormCheckbox = ({ | ||
name, | ||
rules, | ||
label, | ||
control, | ||
disabled, | ||
}: FormCheckboxProps) => { | ||
return ( | ||
<Controller | ||
name={name} | ||
control={control} | ||
rules={rules} | ||
render={({ field: { onChange, value } }) => { | ||
return ( | ||
<FormGroup> | ||
<FormControlLabel | ||
control={<Checkbox onChange={onChange} checked={value} />} | ||
label={label} | ||
disabled={disabled} | ||
/> | ||
</FormGroup> | ||
); | ||
}} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getElementsToDelete } from "../mutationUtils"; | ||
|
||
describe("Fonction utilitaire getElementsToDelete", () => { | ||
it("doit remonter pour un champs donné, la liste d'élément différent entre les 2 objets", () => { | ||
const result = getElementsToDelete( | ||
{ | ||
list: [ | ||
{ | ||
id: 1, | ||
}, | ||
{ | ||
id: 2, | ||
}, | ||
{ | ||
id: 3, | ||
}, | ||
], | ||
}, | ||
{ | ||
list: [ | ||
{ | ||
id: 1, | ||
}, | ||
{ | ||
id: 3, | ||
}, | ||
], | ||
}, | ||
["list", "id"] | ||
); | ||
expect(result.length).toEqual(1); | ||
expect(result[0]).toEqual(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { Client } from "urql"; | ||
import { DocumentNode } from "graphql/index"; | ||
import { TypedDocumentNode } from "@graphql-typed-document-node/core"; | ||
import { OperationContext, OperationResult } from "@urql/core/dist/types/types"; | ||
import { client as gqlClient } from "@shared/graphql-client"; | ||
|
||
export class ApiClient { | ||
client: Client; | ||
hasuraGraphqlAdminSecret: string; | ||
sessionVariables?: any; | ||
|
||
constructor(client: Client, sessionVariables?: any) { | ||
this.client = client; | ||
this.hasuraGraphqlAdminSecret = | ||
process.env.HASURA_GRAPHQL_ADMIN_SECRET ?? "admin1"; | ||
this.sessionVariables = sessionVariables; | ||
} | ||
|
||
public static build(sessionVariables: any = undefined): ApiClient { | ||
return new ApiClient(gqlClient, sessionVariables); | ||
} | ||
|
||
async query<Data = any, Variables extends object = {}>( | ||
query: DocumentNode | TypedDocumentNode<Data, Variables> | string, | ||
variables?: Variables, | ||
context?: Partial<OperationContext> | ||
): Promise<OperationResult<Data, Variables>> { | ||
let headers = context?.headers; | ||
if (this.sessionVariables) { | ||
headers = { | ||
...headers, | ||
...this.sessionVariables, | ||
"x-hasura-admin-secret": this.hasuraGraphqlAdminSecret, | ||
}; | ||
} | ||
const result = await this.client | ||
.query(query, variables, { | ||
...context, | ||
fetchOptions: () => ({ | ||
...context?.fetchOptions, | ||
headers, | ||
}), | ||
}) | ||
.toPromise(); | ||
|
||
return result; | ||
} | ||
|
||
async mutation<Data = any, Variables extends object = {}>( | ||
query: DocumentNode | TypedDocumentNode<Data, Variables> | string, | ||
variables?: Variables, | ||
context?: Partial<OperationContext> | ||
): Promise<OperationResult<Data, Variables>> { | ||
let headers = context?.headers; | ||
if (this.sessionVariables) { | ||
headers = { | ||
...headers, | ||
...this.sessionVariables, | ||
"x-hasura-admin-secret": this.hasuraGraphqlAdminSecret, | ||
}; | ||
} | ||
const result = await this.client | ||
.mutation(query, variables, { | ||
...context, | ||
fetchOptions: () => ({ | ||
...context?.fetchOptions, | ||
headers, | ||
}), | ||
}) | ||
.toPromise(); | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface ErrorWithCause<T> { | ||
name: T; | ||
message: string; | ||
cause: any; | ||
} | ||
|
||
export class ErrorBase<T extends string> extends Error { | ||
name: T; | ||
message: string; | ||
cause: any; | ||
|
||
constructor(error: ErrorWithCause<T>) { | ||
super(); | ||
this.name = error.name; | ||
this.message = error.message; | ||
this.cause = error.cause; | ||
} | ||
} | ||
|
||
export class NotFoundError extends ErrorBase<"NOT_FOUND"> {} | ||
|
||
export const DEFAULT_ERROR_500_MESSAGE = | ||
"Internal server error during fetching data"; | ||
|
||
export class InvalidQueryError extends ErrorBase<"INVALID_QUERY"> { | ||
constructor(message: string, cause: any) { | ||
super({ name: "INVALID_QUERY", message, cause }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./ApiClient"; | ||
export * from "./ApiErrors"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NextApiResponse } from "next"; | ||
import { Boom } from "@hapi/boom"; | ||
|
||
export function createErrorFor(res: NextApiResponse) { | ||
return function toError({ output: { statusCode, payload } }: Boom) { | ||
res.status(statusCode).json(payload); | ||
}; | ||
} | ||
|
||
export function serverError( | ||
res: NextApiResponse, | ||
{ output: { statusCode, payload } }: Boom | ||
) { | ||
return res.status(statusCode).json(payload); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const getElementsByPath = (obj: any, path: string[]): string[] => { | ||
const clonedKeys = [...path]; | ||
const key = clonedKeys.shift(); | ||
if (!key) return []; | ||
const objToParse = obj[key]; | ||
if (!clonedKeys.length && objToParse && typeof objToParse !== "object") { | ||
return [objToParse]; | ||
} else if (Array.isArray(objToParse)) { | ||
return objToParse.reduce((arr, item) => { | ||
return arr.concat(getElementsByPath(item, clonedKeys)); | ||
}, []); | ||
} else if (typeof objToParse === "object") { | ||
return getElementsByPath(objToParse, clonedKeys); | ||
} | ||
return []; | ||
}; | ||
|
||
export const getElementsToDelete = ( | ||
oldObj: any, | ||
newObj: any, | ||
keys: string[] | ||
) => { | ||
const oldIds = getElementsByPath(oldObj, keys); | ||
const newIds = getElementsByPath(newObj, keys); | ||
return oldIds.filter((el) => newIds.indexOf(el) === -1); | ||
}; |
Oops, something went wrong.