-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Theme Plugin Loading #1524
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
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
172d5c2
Theme variable loading
bmingles dd445fc
Loading themes from plugins
bmingles f554d4f
Cleanup theme files
bmingles 6caa97c
Renamed function and added comments
bmingles af7a38c
Simplified preload cache
bmingles 32c844d
Cleanup and comments to theme utils
bmingles 8fa4828
Logging
bmingles 7846b1f
Comments
bmingles cfad94b
Refactored theme utils
bmingles bf93a0b
Unit tests
bmingles 1c269cd
ThemeCache tests
bmingles 39dfbd9
ThemeUtils tests
bmingles bf6c436
Theme tests
bmingles cd19788
useTheme and useThemeCache tests
bmingles 85b6966
Check to make sure plugin export is defined
bmingles 81c821b
Renamed config to themes
bmingles c8a93e3
Reverted some color styles
bmingles a51fed6
Adjusted a color
bmingles cf59e0e
Removed ThemeCache for a simpler mechanism
bmingles e3170ac
Moved theme registration to ThemeBootstrap
bmingles 52f3e44
Improved error messages
bmingles e771241
Simplified test
bmingles 4943cd9
Fixed comments
bmingles 8a2da85
Debug log registered themes
bmingles 8209fd4
Plugin types test
bmingles 9ca3b4b
Addressed code review comments
bmingles 0e24329
Removed ThemeRegistration mapping
bmingles 7b092b4
Moved themes inside of src/
bmingles 0587bde
Changed back to inline to avoid duplicates
bmingles ab10c3d
Added a comment regarding Webpack inline
bmingles a1a4bfd
Added inline to babel transform
bmingles 724065a
Refactored theme provider
bmingles 69627b7
Refactored ThemeProvider
bmingles 52d774f
Removed 'only' from test
bmingles 749a1a7
Added assertions
bmingles 3b3dbeb
Removed nullish
bmingles 892b5fe
Added test cases
bmingles 8e2a510
Fixed a theme flicker bug
bmingles 8a83265
Added named effect function
bmingles 029d349
Fixed key format in failing test
bmingles ac83f90
Fallback $background color
bmingles 2d9d2fa
Fallback $background color
bmingles 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { ThemeProvider } from '@deephaven/components'; | ||
| import { useContext, useMemo } from 'react'; | ||
| import { getThemeDataFromPlugins } from '../plugins'; | ||
| import { PluginsContext } from './PluginsBootstrap'; | ||
|
|
||
| export interface ThemeBootstrapProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export function ThemeBootstrap({ children }: ThemeBootstrapProps): JSX.Element { | ||
| // The `usePlugins` hook throws if the context value is null. Since this is | ||
| // the state while plugins load asynchronously, we are using `useContext` | ||
| // directly to avoid the exception. | ||
| const pluginModules = useContext(PluginsContext); | ||
|
|
||
| const themes = useMemo( | ||
| () => | ||
| pluginModules == null ? null : getThemeDataFromPlugins(pluginModules), | ||
| [pluginModules] | ||
| ); | ||
|
|
||
| return <ThemeProvider themes={themes}>{children}</ThemeProvider>; | ||
| } | ||
|
|
||
| export default ThemeBootstrap; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import { ThemeData } from '@deephaven/components'; | ||
| import { DashboardPlugin, PluginModule, ThemePlugin } from '@deephaven/plugin'; | ||
| import { getThemeDataFromPlugins } from './PluginUtils'; | ||
|
|
||
| beforeEach(() => { | ||
| document.body.removeAttribute('style'); | ||
| document.head.innerHTML = ''; | ||
| jest.clearAllMocks(); | ||
| expect.hasAssertions(); | ||
| }); | ||
|
|
||
| describe('getThemeDataFromPlugins', () => { | ||
| const themePluginSingleDark: ThemePlugin = { | ||
| name: 'mock.themePluginNameA', | ||
| type: 'ThemePlugin', | ||
| themes: { | ||
| name: 'mock.customDark', | ||
| baseTheme: 'dark', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| }; | ||
|
|
||
| const themePluginSingleLight: ThemePlugin = { | ||
| name: 'mock.themePluginNameB', | ||
| type: 'ThemePlugin', | ||
| themes: { | ||
| name: 'mock.customLight', | ||
| baseTheme: 'light', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| }; | ||
|
|
||
| const themePluginMultiConfig: ThemePlugin = { | ||
| name: 'mock.themePluginNameC', | ||
| type: 'ThemePlugin', | ||
| themes: [ | ||
| { | ||
| name: 'mock.customDark', | ||
| baseTheme: 'dark', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| { | ||
| name: 'mock.customLight', | ||
| baseTheme: 'light', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| { | ||
| name: 'mock.customUndefined', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const otherPlugin: DashboardPlugin = { | ||
| name: 'mock.otherPluginName', | ||
| type: 'DashboardPlugin', | ||
| component: () => null, | ||
| }; | ||
|
|
||
| const pluginMap = new Map<string, PluginModule>([ | ||
| ['mock.themePluginNameA', themePluginSingleDark], | ||
| ['mock.themePluginNameB', themePluginSingleLight], | ||
| ['mock.themePluginNameC', themePluginMultiConfig], | ||
| ['mock.otherPluginName', otherPlugin], | ||
| ]); | ||
|
|
||
| it('should return theme data from plugins', () => { | ||
| const actual = getThemeDataFromPlugins(pluginMap); | ||
| const expected: ThemeData[] = [ | ||
| { | ||
| name: 'mock.customDark', | ||
| baseThemeKey: 'default-dark', | ||
| themeKey: 'mock.themePluginNameA_mock.customDark', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| { | ||
| name: 'mock.customLight', | ||
| baseThemeKey: 'default-light', | ||
| themeKey: 'mock.themePluginNameB_mock.customLight', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| { | ||
| name: 'mock.customDark', | ||
| baseThemeKey: 'default-dark', | ||
| themeKey: 'mock.themePluginNameC_mock.customDark', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| { | ||
| name: 'mock.customLight', | ||
| baseThemeKey: 'default-light', | ||
| themeKey: 'mock.themePluginNameC_mock.customLight', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| { | ||
| name: 'mock.customUndefined', | ||
| baseThemeKey: 'default-dark', | ||
| themeKey: 'mock.themePluginNameC_mock.customUndefined', | ||
| styleContent: 'mock.styleContent', | ||
| }, | ||
| ]; | ||
|
|
||
| expect(actual).toEqual(expected); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.