-
Notifications
You must be signed in to change notification settings - Fork 885
[EuiMarkdownEditor] Allow more plugins to be excludable #7676
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
Merged
cee-chen
merged 5 commits into
elastic:main
from
sakurai-youhei:make-line-breaks-plugin-excludable
Apr 13, 2024
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7612d36
Add option to opt out of line-breaks plugin
sakurai-youhei 5f01ec1
Add changelog
sakurai-youhei caf13dd
Updated snippet
sakurai-youhei d04966a
Extend `exclude` API to allow for excluding even more plugins
cee-chen f297f6f
Update docs & changelog
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| - Added a way to exclude the line-breaks plugin from defaults in EuiMarkdownEditor. | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
84 changes: 84 additions & 0 deletions
84
src/components/markdown_editor/plugins/markdown_default_plugins/plugins.test.ts
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ Thank you so much for adding a test file here and for so carefully following our QA steps!! Not all of them apply to every PR but I super appreciate the time you took to check it! |
This file contains hidden or 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,84 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import breaks from 'remark-breaks'; | ||
|
|
||
| import * as MarkdownTooltip from '../markdown_tooltip'; | ||
| import { getDefaultEuiMarkdownPlugins } from './plugins'; | ||
|
|
||
| import type { Pluggable, PluginTuple, Settings } from 'unified'; | ||
| import type { EuiMarkdownEditorUiPlugin } from '../../markdown_types'; | ||
|
|
||
| const excludableDefaultPlugins: Array< | ||
| [ | ||
| 'tooltip' | 'line-breaks', | ||
| Pluggable<any[], Settings> | null, | ||
| React.ComponentType<any> | null, | ||
| EuiMarkdownEditorUiPlugin | null | ||
| ] | ||
| > = [ | ||
| [ | ||
| 'tooltip', | ||
| MarkdownTooltip.parser, | ||
| MarkdownTooltip.renderer, | ||
| MarkdownTooltip.plugin, | ||
| ], | ||
| ['line-breaks', breaks, null, null], | ||
| ]; | ||
|
|
||
| describe('opt out of default plugins', () => { | ||
| it('exclude nothing', () => { | ||
| const { parsingPlugins, processingPlugins, uiPlugins } = | ||
| getDefaultEuiMarkdownPlugins({}); | ||
|
|
||
| excludableDefaultPlugins.forEach( | ||
| ([, parsingPlugin, processingPlugin, uiPlugin]) => { | ||
| if (parsingPlugin !== null) { | ||
| expect( | ||
| parsingPlugins.find((p) => (p as PluginTuple)[0] === parsingPlugin) | ||
| ).not.toBeUndefined(); | ||
| } | ||
|
|
||
| if (processingPlugin !== null) { | ||
| expect(Object.values(processingPlugins[1][1].components)).toContain( | ||
| processingPlugin | ||
| ); | ||
| } | ||
|
|
||
| if (uiPlugin !== null) { | ||
| expect(uiPlugins).toContain(uiPlugin); | ||
| } | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test.each(excludableDefaultPlugins)( | ||
| 'exclude %s', | ||
| (plugin, parsingPlugin, processingPlugin, uiPlugin) => { | ||
| const { parsingPlugins, processingPlugins, uiPlugins } = | ||
| getDefaultEuiMarkdownPlugins({ exclude: [plugin] }); | ||
|
|
||
| if (parsingPlugin !== null) { | ||
| expect( | ||
| parsingPlugins.find((p) => (p as PluginTuple)[0] === parsingPlugin) | ||
| ).toBeUndefined(); | ||
| } | ||
|
|
||
| if (processingPlugin !== null) { | ||
| expect(Object.values(processingPlugins[1][1].components)).not.toContain( | ||
| processingPlugin | ||
| ); | ||
| } | ||
|
|
||
| if (uiPlugin !== null) { | ||
| expect(uiPlugins).not.toContain(uiPlugin); | ||
| } | ||
| } | ||
| ); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Not a blocking comment, just me thinking out loud] I wonder if we should extend the
excludelist more generally to allow excluding any of the default plugins. I might spike out an attempt at this if you're cool with that!Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sakurai-youhei I'm so sorry I kind of just took over your PR 😂 d04966a
Let me know what you think of the changes! I think it makes sense to allow consumers to set configure plugins flexibly where possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cee-chen Thank you for giving me such a great opportunity to learn from your code. I shrunk and limited the scope to the specific exclusion because I didn't think I could handle the full scope. The flexibility makes sense to me, too.