-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add SQL functions for partner-block * update migration file based on review * add unique constraint to partner_block table * create POST endpoint for partners block * add more accepted block to conditional block * consume partners block api in main-frontend and also generate-bindings * + partner_block route in main-frontend * finalize partners block feature * reduce width of partners icions * remove broken breadcrumbs * make partners block responsive * fix error with back button in partners block * + comment to migration file * add test for partners-block * remove unused code * use proper type * update check for existence of partner-block in a course * add test asset * create test for partner-block * + asset * stash commit * remove spinner and error component * update snapshots * resolve accessibility issues * resolve accessibility issues * update snapshots * update test * update test * update snapshot test
- Loading branch information
1 parent
bec3610
commit 27fa855
Showing
42 changed files
with
1,000 additions
and
85 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
88 changes: 88 additions & 0 deletions
88
services/cms/src/components/editors/PartnersBlockEditor.tsx
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,88 @@ | ||
/* eslint-disable i18next/no-literal-string */ | ||
import { css } from "@emotion/css" | ||
import { BlockInstance } from "@wordpress/blocks" | ||
import dynamic from "next/dynamic" | ||
import React, { useContext, useState } from "react" | ||
import { useTranslation } from "react-i18next" | ||
|
||
import { allowedPartnerCoreBlocks } from "../../blocks/supportedGutenbergBlocks" | ||
import CourseContext from "../../contexts/CourseContext" | ||
import mediaUploadBuilder from "../../services/backend/media/mediaUpload" | ||
import { modifyBlocks } from "../../utils/Gutenberg/modifyBlocks" | ||
|
||
import { PartnersBlock } from "@/shared-module/common/bindings" | ||
import Button from "@/shared-module/common/components/Button" | ||
import Spinner from "@/shared-module/common/components/Spinner" | ||
|
||
interface PartnersBlockEditorProps { | ||
data: PartnersBlock | ||
handleSave: (updatedTemplate: unknown) => Promise<PartnersBlock> | ||
} | ||
|
||
const EditorLoading = <Spinner variant="medium" /> | ||
|
||
const PartnersBlockGutenbergEditor = dynamic(() => import("./GutenbergEditor"), { | ||
ssr: false, | ||
loading: () => EditorLoading, | ||
}) | ||
|
||
const PartnersSectionEditor: React.FC<React.PropsWithChildren<PartnersBlockEditorProps>> = ({ | ||
data, | ||
handleSave, | ||
}) => { | ||
const courseId = useContext(CourseContext)?.courseId | ||
const { t } = useTranslation() | ||
const [content, setContent] = useState<BlockInstance[]>( | ||
modifyBlocks( | ||
(data.content ?? []) as BlockInstance[], | ||
allowedPartnerCoreBlocks, | ||
) as BlockInstance[], | ||
) | ||
const [saving, setSaving] = useState(false) | ||
const [error, setError] = useState<string | null>(null) | ||
|
||
const handleOnSave = async () => { | ||
setSaving(true) | ||
try { | ||
const res = await handleSave(content) | ||
setContent(res.content as BlockInstance[]) | ||
setError(null) | ||
} catch (e: unknown) { | ||
if (!(e instanceof Error)) { | ||
throw e | ||
} | ||
setError(e.toString()) | ||
} finally { | ||
setSaving(false) | ||
} | ||
} | ||
|
||
return ( | ||
<> | ||
<div className="editor__component"> | ||
<div | ||
className={css` | ||
margin: 4rem 0 2.5rem 0; | ||
`} | ||
> | ||
{error && <pre>{error}</pre>} | ||
<Button variant="primary" size="medium" disabled={saving} onClick={handleOnSave}> | ||
{t("save")} | ||
</Button> | ||
</div> | ||
</div> | ||
|
||
{courseId && ( | ||
<PartnersBlockGutenbergEditor | ||
content={content} | ||
onContentChange={setContent} | ||
allowedBlocks={allowedPartnerCoreBlocks} | ||
mediaUpload={mediaUploadBuilder({ courseId: courseId })} | ||
needToRunMigrationsAndValidations={false} | ||
setNeedToRunMigrationsAndValidations={() => {}} | ||
/> | ||
)} | ||
</> | ||
) | ||
} | ||
export default PartnersSectionEditor |
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,66 @@ | ||
import dynamic from "next/dynamic" | ||
import React from "react" | ||
|
||
import CourseContext from "../../../contexts/CourseContext" | ||
|
||
import { fetchPartnersBlock, setPartnerBlockForCourse } from "@/services/backend/partners-block" | ||
import { PartnersBlock } from "@/shared-module/common/bindings" | ||
import ErrorBanner from "@/shared-module/common/components/ErrorBanner" | ||
import Spinner from "@/shared-module/common/components/Spinner" | ||
import { withSignedIn } from "@/shared-module/common/contexts/LoginStateContext" | ||
import useStateQuery from "@/shared-module/common/hooks/useStateQuery" | ||
import dontRenderUntilQueryParametersReady, { | ||
SimplifiedUrlQuery, | ||
} from "@/shared-module/common/utils/dontRenderUntilQueryParametersReady" | ||
import withErrorBoundary from "@/shared-module/common/utils/withErrorBoundary" | ||
|
||
const EditorLoading = <Spinner variant="medium" /> | ||
|
||
const PartnersBlockEditor = dynamic( | ||
() => import("../../../components/editors/PartnersBlockEditor"), | ||
{ | ||
ssr: false, | ||
loading: () => EditorLoading, | ||
}, | ||
) | ||
|
||
export interface PartnersBlockProps { | ||
query: SimplifiedUrlQuery<"id"> | ||
} | ||
|
||
const PartnersBlockEdit: React.FC<React.PropsWithChildren<PartnersBlockProps>> = ({ query }) => { | ||
// const [needToRunMigrationsAndValidations, setNeedToRunMigrationsAndValidations] = useState(false) | ||
const courseId = query.id | ||
// eslint-disable-next-line i18next/no-literal-string | ||
const blockQuery = useStateQuery(["partners-block", courseId], (courseId) => | ||
fetchPartnersBlock(courseId), | ||
) | ||
|
||
if (blockQuery.state === "error") { | ||
return ( | ||
<> | ||
<ErrorBanner variant={"readOnly"} error={blockQuery.error} /> | ||
</> | ||
) | ||
} | ||
|
||
if (blockQuery.state !== "ready") { | ||
return <Spinner variant={"medium"} /> | ||
} | ||
|
||
const handleSave = async (data: unknown): Promise<PartnersBlock> => { | ||
const res = await setPartnerBlockForCourse(courseId, data ?? []) | ||
await blockQuery.refetch() | ||
return res | ||
} | ||
|
||
return ( | ||
<CourseContext.Provider value={{ courseId: courseId }}> | ||
<PartnersBlockEditor data={blockQuery.data} handleSave={handleSave} /> | ||
</CourseContext.Provider> | ||
) | ||
} | ||
|
||
export default withErrorBoundary( | ||
withSignedIn(dontRenderUntilQueryParametersReady(PartnersBlockEdit)), | ||
) |
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,22 @@ | ||
import { cmsClient } from "./cmsClient" | ||
|
||
import { PartnersBlock } from "@/shared-module/common/bindings" | ||
import { isPartnersBlock } from "@/shared-module/common/bindings.guard" | ||
import { validateResponse } from "@/shared-module/common/utils/fetching" | ||
|
||
export const setPartnerBlockForCourse = async ( | ||
courseId: string, | ||
data: object | null, | ||
): Promise<PartnersBlock> => { | ||
const response = await cmsClient.post(`/courses/${courseId}/partners-block`, data) | ||
return validateResponse(response, isPartnersBlock) | ||
} | ||
|
||
export const fetchPartnersBlock = async (courseId: string): Promise<PartnersBlock> => { | ||
const response = await cmsClient.get(`/courses/${courseId}/partners-block`) | ||
return validateResponse(response, isPartnersBlock) | ||
} | ||
|
||
export const deletePartnersBlock = async (courseId: string): Promise<void> => { | ||
await cmsClient.delete(`/courses/${courseId}/partners-block`) | ||
} |
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
Oops, something went wrong.