Skip to content

Conversation

@ahtesham-quraish
Copy link
Contributor

@ahtesham-quraish ahtesham-quraish commented Nov 11, 2025

What are the relevant tickets?

In reference to #2691

Description (What does it do?)

This is about to consume the tiptap component that is created in #2691 and make changes in unit test as well

Screenshots (if appropriate):

Screen.Recording.2025-11-11.at.5.54.13.PM.mov

How can this be tested?

  • Hit the following url for create new articles '/articles/new'
  • Once you create new article then you can see the detail and edit

Additional Context

@ahtesham-quraish ahtesham-quraish changed the title Ahtesham/consume tiptap feat: incorporating the tiptap in articles CRUD operations Nov 11, 2025

.simple-editor-wrapper {
width: 100vw;
height: 100vh;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's override these from our parent code to avoid modifying ejected library css. This should smooth the ride when we upgrade to new Tiptap versions.

You can do e.g.

styled(TiptapEditor)({
  ".simple-editor-wrapper": {
    width: "auto",
    height: "auto"
  }
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok done

Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. Let's improve the layout by pinning the toolbar to the header as we discussed (assuming not too much effort).

className="input-field"
/>

<ClientContainer className="editor-box">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a previous PR, but this classname isn't referenced - can be removed


return (
<RestrictedRoute requires={Permission.ArticleEditor}>
<Container className="article-wrapper">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a previous PR, but this classname isn't referenced - can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

margin: "10px 0",
})

styled(TiptapEditor)({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't do anything unless used, ie.

const StyledTiptapEditor = styled(TiptapEditor)({ ... })

... and then use StyledTiptapEditor in the component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this for now lets remove it

const [text, setText] = useState("")
const [json, setJson] = useState({})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [json, setJson] = useState<Record<string, any>>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tiptap/core exports type JSONContent so we can do useState<JSONContent>. We don't want to install @tiptap/core in the main workspace, but could re-export from ol-components as TiptapJSONContent, or better - add an export map to the ol-components package.json so we can do

import type { JSONContent } from "ol-components/tiptap-editor"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const [text, setText] = useState("")
const [json, setJson] = useState({})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [json, setJson] = useState<Record<string, any>>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSONContent type here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 20 to 46
jest.mock("ol-components", () => {
// Reuse other exports from ol-components if needed
const actual = jest.requireActual("ol-components")
return {
...actual,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
TiptapEditor: ({ value, onChange, "data-testid": testId }: any) => {
return (
<textarea
data-testid={testId || "editor"}
value={JSON.stringify(value, null, 2)}
onChange={(e) => {
try {
// Allow simulating JSON-like updates if needed
const parsed = JSON.parse(e.target.value)
onChange?.(parsed)
} catch {
// fallback to raw string for simple tests
onChange?.(e.target.value)
}
}}
/>
)
},
}
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need to mock the editor here. For the actual instance to work, we'll need two things:

  • the data-testid to be passed to TiptapEditor and set on its containing div for the expect(screen.getByTestId("editor")).toBeInTheDocument() assertion. SimpleEditorProps could extend React.HTMLAttributes<HTMLDivElement> so we can set any div props on the contiainer, or just:
interface SimpleEditorProps {
  value?: object
  onChange?: (json: object) => void
  readOnly?: boolean
  "data-testid"?: string
}
  • the article factory must return a valid document on the content, e.g.
    const article = factories.articles.article({
      id: 42,
      title: "Existing Title",
      content: {
        type: "doc",
        content: [
          {
            type: "paragraph",
            content: [{ type: "text", text: "Existing content" }],
          },
        ],
      },
    })

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we need a placeholder image, let's use one already in the repo, e.g. https://github.com/mitodl/mit-learn/blob/main/frontends/main/public/mit-dome-2.jpg

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@ahtesham-quraish ahtesham-quraish force-pushed the ahtesham/consume-tiptap branch 2 times, most recently from 848f12f to bb13dcd Compare November 12, 2025 17:59
Copy link
Contributor

@jonkafton jonkafton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 #2699 to follow up

@ahtesham-quraish ahtesham-quraish merged commit 4169b0c into main Nov 13, 2025
13 checks passed
@ahtesham-quraish ahtesham-quraish deleted the ahtesham/consume-tiptap branch November 13, 2025 15:15
@odlbot odlbot mentioned this pull request Nov 17, 2025
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants