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

Use MarkdownEditor in dashboard #12462

Merged
merged 7 commits into from
Mar 21, 2025
Merged

Use MarkdownEditor in dashboard #12462

merged 7 commits into from
Mar 21, 2025

Conversation

kazcw
Copy link
Contributor

@kazcw kazcw commented Mar 11, 2025

Pull Request Description

In the dashboard, replace marked with an instance of the MarkdownEditor used by project-view.

Gravacao.do.ecra.2025-03-14.as.16.42.41.mov

Fixes #12063.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.
  • If meaningful changes were made to logic or tests affecting Enso Cloud integration in the libraries,
    or the Snowflake database integration, a run of the Extra Tests has been scheduled.
    • If applicable, it is suggested to paste a link to a successful run of the Extra Tests.

@kazcw kazcw added the CI: No changelog needed Do not require a changelog entry for this PR. label Mar 11, 2025
@kazcw kazcw marked this pull request as ready for review March 11, 2025 09:22
Copy link

github-actions bot commented Mar 11, 2025

🧪 Storybook is successfully deployed!

📊 Dashboard:

}) {
const keyboard = injectKeyboard()
function useBindings(view: EditorView) {
const keyboard = injectKeyboard(true)
Copy link
Contributor

@farmaazon farmaazon Mar 11, 2025

Choose a reason for hiding this comment

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

Perhaps we could move provideKeyboard from GraphEditor.vue to App.vue, then it should be visible in React.

const transformImageUrl: UrlTransformer = (path: string) =>
/^https?:/.test(path) ?
Promise.resolve({ ok: true, value: { url: path } })
: imgUrlResolver(path).then((url) => ({ ok: true, value: { url } }))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep catching exceptions on imgUrlResolver, as in Dashboard's codebase exceptions are thrown more freely.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this situation it'd be better to replace the image with an error and display the rest of the docs. So I'm voting for catching errors here or down the line.
Also, as we rely on Suspense features, we catch these errors in an 'ErrorBoundary' placed higher in the tree. But I'm not sure we can catch errors occuring in vue and outside of render/useSuspenseQuery phases

/** Extracts the properties defined by a component, excluding various Vue internals. */
type VueComponentProps<T> = Omit<ComponentProps<T>, keyof AllowedComponentProps | keyof VNodeProps>

/** Creates a React component wrapping a Vue component. */
Copy link
Contributor

Choose a reason for hiding this comment

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

Jusdging by Docs, it's exactly the same as applyPureVueInReact.

Suggested change
/** Creates a React component wrapping a Vue component. */
/** Creates a Lazy React component wrapping a Vue component. */

Copy link
Contributor

@MrFlashAccount MrFlashAccount left a comment

Choose a reason for hiding this comment

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

Did a shallow review, will do a deeper look later on

export function vueComponent<T extends { default?: unknown }>(
lazyImport: () => Promise<T>,
): React.LazyExoticComponent<(props: VueComponentProps<T['default']>) => React.JSX.Element> {
return React.lazy(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lazy shouldn't be mandatory, bacause it's a perf optimization and usage depends on the context.

dangerouslySetInnerHTML={{ __html: markdownToHtml }}
/>
)
return <MarkdownEditor content={text} transformImageUrl={transformImageUrl} toolbar={false} />
Copy link
Contributor

Choose a reason for hiding this comment

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

No testid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The asset docs panel has a testid; the editor can be located relative to it.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not sustainable, we'd like to be able to set a test id for this element

const transformImageUrl: UrlTransformer = (path: string) =>
/^https?:/.test(path) ?
Promise.resolve({ ok: true, value: { url: path } })
: imgUrlResolver(path).then((url) => ({ ok: true, value: { url } }))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this situation it'd be better to replace the image with an error and display the rest of the docs. So I'm voting for catching errors here or down the line.
Also, as we rely on Suspense features, we catch these errors in an 'ErrorBoundary' placed higher in the tree. But I'm not sure we can catch errors occuring in vue and outside of render/useSuspenseQuery phases

@kazcw kazcw marked this pull request as draft March 14, 2025 16:44
@kazcw kazcw marked this pull request as ready for review March 17, 2025 07:12
@kazcw kazcw requested a review from MrFlashAccount March 19, 2025 10:27
@@ -19,6 +19,11 @@ function locateAssetPanelDescription(page: Page) {
return locateAssetPanel(page).getByTestId('asset-panel-description')
}

/** Find the contents of the Markdown editor within the given {@link Locator}. */
function locateMarkdownContent(locator: Locator) {
return locator.locator('.cm-content')
Copy link
Contributor

Choose a reason for hiding this comment

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

className selectors are forbidden as selectors in tests

Copy link
Contributor

Choose a reason for hiding this comment

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

Why it is so? We are not shy of using class selector in our tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

Because class selectors aren't sustainable. Causing false-positives because of className change isn't a good practice overall

Copy link
Contributor

Choose a reason for hiding this comment

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

Quick searching, here are an example of best practices from cypress website: https://docs.cypress.io/app/core-concepts/best-practices#How-It-Works

Copy link
Contributor Author

@kazcw kazcw Mar 21, 2025

Choose a reason for hiding this comment

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

This class is part of the public API of CodeMirror. If they changed it, it would be a breaking change for a lot more than our tests.

return `<blockquote class="${'relative my-1 pl-2 before:bg-primary/20 before:absolute before:left-0 before:top-0 before:h-full before:w-[1.5px] before:rounded-full'}">${this.parser.parse(tokens)}</blockquote>`
},
}
export const MarkdownEditor = lazyVueComponent(() => import('@/components/MarkdownEditor.vue'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Lazy should be declared in place, not globally.

@kazcw kazcw requested a review from MrFlashAccount March 20, 2025 09:56
Copy link
Contributor

@MrFlashAccount MrFlashAccount left a comment

Choose a reason for hiding this comment

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

LGTM

@kazcw kazcw added the CI: Ready to merge This PR is eligible for automatic merge label Mar 21, 2025
@mergify mergify bot merged commit 990ca19 into develop Mar 21, 2025
60 of 61 checks passed
@mergify mergify bot deleted the wip/kw/dashboard-docs branch March 21, 2025 13:33
@jdunkerley jdunkerley added this to the 2025-Q1 Release milestone Mar 21, 2025
farmaazon pushed a commit that referenced this pull request Mar 21, 2025
In the dashboard, replace `marked` with an instance of the `MarkdownEditor` used by `project-view`.

https://github.com/user-attachments/assets/6b627a57-70ec-4b93-8967-35d0929c79d8

Fixes #12063.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify docpanel's implementations
4 participants