-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the scope of selecting the Runtime in use, a settings page pointing to a catalog URL is needed. This commit adds a Settings component and a Settings provider. By default, it will store the settings to the browser's LocalStorage. The idea behind using a SettingsAdapter is to give the possibilit in the future to set the settings at VSCode level if needed. fix: #834
- Loading branch information
Showing
40 changed files
with
1,087 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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,15 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"description": "JSON Schema for Kaoto configuration", | ||
"properties": { | ||
"catalogUrl": { | ||
"title": "Camel Catalog URL", | ||
"description": "URL that points to the `index.json` file from the Kaoto Camel Catalog. Leave it empty to use the embedded catalog.", | ||
"default": "<empty string>", | ||
"type": "string", | ||
"format": "uri" | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/ui/src/components/LoadDefaultCatalog/LoadDefaultCatalog.test.tsx
This file contains 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,59 @@ | ||
import { render } from '@testing-library/react'; | ||
import { AbstractSettingsAdapter, DefaultSettingsAdapter } from '../../models/settings'; | ||
import { ReloadContext, SettingsProvider } from '../../providers'; | ||
import { LoadDefaultCatalog } from './LoadDefaultCatalog'; | ||
|
||
describe('LoadDefaultCatalog', () => { | ||
let reloadPage: jest.Mock; | ||
let settingsAdapter: AbstractSettingsAdapter; | ||
|
||
beforeEach(() => { | ||
reloadPage = jest.fn(); | ||
settingsAdapter = new DefaultSettingsAdapter(); | ||
}); | ||
|
||
it('should render correctly', () => { | ||
const wrapper = render( | ||
<ReloadContext.Provider value={{ reloadPage, lastRender: 0 }}> | ||
<SettingsProvider adapter={settingsAdapter}> | ||
<LoadDefaultCatalog errorMessage="Test error message" /> | ||
</SettingsProvider> | ||
</ReloadContext.Provider>, | ||
); | ||
|
||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render child components', () => { | ||
const wrapper = render( | ||
<ReloadContext.Provider value={{ reloadPage, lastRender: 0 }}> | ||
<SettingsProvider adapter={settingsAdapter}> | ||
<LoadDefaultCatalog errorMessage="Test error message"> | ||
<div>Test children</div> | ||
</LoadDefaultCatalog> | ||
</SettingsProvider> | ||
</ReloadContext.Provider>, | ||
); | ||
|
||
const child = wrapper.getByText('Test children'); | ||
|
||
expect(child).toBeInTheDocument(); | ||
}); | ||
|
||
it('should call reloadCatalog on button click', () => { | ||
const wrapper = render( | ||
<ReloadContext.Provider value={{ reloadPage, lastRender: 0 }}> | ||
<SettingsProvider adapter={settingsAdapter}> | ||
<LoadDefaultCatalog errorMessage="Test error message"> | ||
<div>Test children</div> | ||
</LoadDefaultCatalog> | ||
</SettingsProvider> | ||
</ReloadContext.Provider>, | ||
); | ||
|
||
const button = wrapper.getByText('Reload with default Catalog'); | ||
button.click(); | ||
|
||
expect(reloadPage).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/ui/src/components/LoadDefaultCatalog/LoadDefaultCatalog.tsx
This file contains 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,62 @@ | ||
import { | ||
Bullseye, | ||
Button, | ||
EmptyState, | ||
EmptyStateActions, | ||
EmptyStateBody, | ||
EmptyStateFooter, | ||
EmptyStateHeader, | ||
EmptyStateIcon, | ||
EmptyStateVariant, | ||
ExpandableSection, | ||
} from '@patternfly/react-core'; | ||
import { ExclamationCircleIcon } from '@patternfly/react-icons'; | ||
import { FunctionComponent, PropsWithChildren, useContext } from 'react'; | ||
import { useReloadContext } from '../../hooks/useReloadContext/useReloadContext'; | ||
import { SettingsContext } from '../../providers'; | ||
|
||
interface ILoadDefaultCatalogProps { | ||
errorMessage: string; | ||
} | ||
|
||
export const LoadDefaultCatalog: FunctionComponent<PropsWithChildren<ILoadDefaultCatalogProps>> = (props) => { | ||
const settingsAdapter = useContext(SettingsContext); | ||
const { reloadPage } = useReloadContext(); | ||
|
||
const reloadCatalog = () => { | ||
const currentSettings = settingsAdapter.getSettings(); | ||
settingsAdapter.saveSettings({ ...currentSettings, catalogUrl: '' }); | ||
reloadPage(); | ||
}; | ||
|
||
return ( | ||
<Bullseye> | ||
<EmptyState variant={EmptyStateVariant.lg} data-testid="load-default-catalog"> | ||
<EmptyStateHeader | ||
titleText="The Catalog couldn't be loaded" | ||
headingLevel="h4" | ||
icon={<EmptyStateIcon icon={ExclamationCircleIcon} />} | ||
/> | ||
|
||
<EmptyStateBody>{props.children}</EmptyStateBody> | ||
|
||
<EmptyStateFooter> | ||
<EmptyStateActions> | ||
<Button variant="primary" onClick={reloadCatalog}> | ||
Reload with default Catalog | ||
</Button> | ||
</EmptyStateActions> | ||
<ExpandableSection | ||
toggleText="Error details" | ||
toggleId="expandable-section-toggle" | ||
contentId="expandable-section-content" | ||
> | ||
<code> | ||
<pre>{JSON.stringify(props.errorMessage, null, 2)}</pre> | ||
</code> | ||
</ExpandableSection> | ||
</EmptyStateFooter> | ||
</EmptyState> | ||
</Bullseye> | ||
); | ||
}; |
Oops, something went wrong.