Skip to content

Commit 53706c2

Browse files
authored
Implement Rich Editor UI in Admin via Astro (#4274)
1 parent c4ed4ce commit 53706c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1297
-418
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ backend/schema.graphql
137137
backend/__pypackages__/
138138
backend/custom_admin/.astro/
139139
backend/custom_admin/core.*
140+
core.*

backend/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ RUN apt-get update -y && apt-get install -y curl
7575
RUN groupadd -r app && useradd -r -g app app && mkdir -p ${FUNCTION_DIR} && chown -R app:app ${FUNCTION_DIR}
7676

7777
COPY --chown=app:app --from=js-stage ${FUNCTION_DIR}/dist/*.html ${FUNCTION_DIR}/custom_admin/templates/astro/
78+
COPY --chown=app:app --from=js-stage ${FUNCTION_DIR}/dist/widgets/*.html ${FUNCTION_DIR}/custom_admin/templates/astro/widgets/
7879
COPY --chown=app:app --from=js-stage ${FUNCTION_DIR}/dist/_astro ${FUNCTION_DIR}/custom_admin/static/_astro/
7980
COPY --chown=app:app --from=build-stage ${FUNCTION_DIR}/.venv ${FUNCTION_DIR}/.venv
8081

backend/custom_admin/context_processors.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,3 @@
33

44
def admin_settings(request):
55
return {"CURRENT_ENV": settings.ENVIRONMENT}
6-
7-
8-
def astro_settings(request):
9-
return {
10-
"ASTRO_URL": request.build_absolute_uri("/astro"),
11-
"APOLLO_GRAPHQL_URL": "/admin/graphql",
12-
}

backend/custom_admin/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424
"@radix-ui/react-toast": "^1.2.4",
2525
"@radix-ui/react-toolbar": "^1.1.1",
2626
"@radix-ui/themes": "^3.1.6",
27+
"@tiptap/core": "^2.10.4",
2728
"@tiptap/extension-color": "^2.10.3",
29+
"@tiptap/extension-focus": "^2.10.4",
30+
"@tiptap/extension-heading": "^2.10.4",
31+
"@tiptap/extension-link": "^2.10.4",
2832
"@tiptap/extension-list-item": "^2.10.3",
33+
"@tiptap/extension-placeholder": "^2.10.4",
2934
"@tiptap/extension-text-align": "^2.10.3",
3035
"@tiptap/extension-text-style": "^2.10.3",
36+
"@tiptap/extension-underline": "^2.10.4",
3137
"@tiptap/pm": "^2.10.3",
3238
"@tiptap/react": "^2.10.3",
3339
"@tiptap/starter-kit": "^2.10.3",

backend/custom_admin/pnpm-lock.yaml

Lines changed: 147 additions & 81 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/custom_admin/src/components/invitation-letter-document-builder/editor-section.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
} from "@radix-ui/themes";
1111
import { Box } from "@radix-ui/themes";
1212
import { MoveDown, MoveUp, Pencil, Trash } from "lucide-react";
13-
import { Editor } from "./editor";
13+
import { RichEditor } from "../shared/rich-editor";
14+
import { HideNode } from "../shared/rich-editor/menu-bar";
1415
import { useLocalData } from "./local-state";
1516

1617
export const EditorSection = ({
@@ -50,7 +51,11 @@ export const EditorSection = ({
5051
{isPage && <RemovePage onRemove={onRemove} />}
5152
</Flex>
5253
<Box height="var(--space-3)" />
53-
<Editor content={content} onUpdate={onUpdate} />
54+
<RichEditor
55+
hide={[HideNode.buttonNode, HideNode.link]}
56+
content={content}
57+
onUpdate={onUpdate}
58+
/>
5459
</Box>
5560
);
5661
};

backend/custom_admin/src/components/invitation-letter-document-builder/local-state.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useInvitationLetterDocumentSuspenseQuery } from "./invitation-letter-do
44
import { useUpdateInvitationLetterDocumentMutation } from "./update-invitation-letter-document.generated";
55

66
import { createContext } from "react";
7-
import { getArg } from "../shared/get-arg";
7+
import { useArgs } from "../shared/args";
88

99
type State = {
1010
header: string;
@@ -173,7 +173,7 @@ const removeTypenames = (obj) => {
173173
};
174174

175175
const useLoadRemoteData = (dispatch) => {
176-
const documentId = getArg("document_id");
176+
const { documentId } = useArgs();
177177

178178
const { data } = useInvitationLetterDocumentSuspenseQuery({
179179
variables: {
@@ -199,13 +199,14 @@ const useLoadRemoteData = (dispatch) => {
199199
const useSaveRemoteData = (): [(newData) => void, boolean, boolean] => {
200200
const [updateInvitationLetter, { loading: savingChanges, error }] =
201201
useUpdateInvitationLetterDocumentMutation();
202+
const { documentId } = useArgs();
202203

203204
return [
204205
(newData) => {
205206
updateInvitationLetter({
206207
variables: {
207208
input: {
208-
id: getArg("document_id"),
209+
id: documentId,
209210
dynamicDocument: newData,
210211
},
211212
},

backend/custom_admin/src/components/invitation-letter-document-builder/menu-bar.tsx

Lines changed: 0 additions & 72 deletions
This file was deleted.

backend/custom_admin/src/components/invitation-letter-document-builder/root.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ import { DjangoAdminLayout } from "../shared/django-admin-layout";
55
import { InvitationLetterBuilder } from "./builder";
66
import { LocalStateProvider } from "./local-state";
77

8-
export const InvitationLetterDocumentBuilderRoot = () => {
8+
export const InvitationLetterDocumentBuilderRoot = ({
9+
documentId,
10+
breadcrumbs,
11+
}) => {
912
return (
10-
<Base>
13+
<Base
14+
args={{
15+
documentId,
16+
breadcrumbs,
17+
}}
18+
>
1119
<DjangoAdminLayout>
1220
<Suspense
1321
fallback={

backend/custom_admin/src/components/schedule-builder/placeholder.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ export const Placeholder = ({
8585
}}
8686
>
8787
{isMovingItemLoading && <span>Please wait</span>}
88-
{!isMovingItemLoading && !canDrop && <span>Click to add</span>}
89-
{!isMovingItemLoading && canDrop && <span>Drop here to move</span>}
88+
{!isMovingItemLoading && <span>Drop / Add</span>}
9089
<PlusIcon />
9190
</div>
9291
);

0 commit comments

Comments
 (0)