-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core-app-api: deprecate dependency on core-components
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
- Loading branch information
Showing
13 changed files
with
219 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@backstage/dev-utils': patch | ||
--- | ||
|
||
Migrated to explicit passing of components to `createApp`. |
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,33 @@ | ||
--- | ||
'@backstage/create-app': patch | ||
--- | ||
|
||
Migrated the app template to pass on explicit `components` to the `createApp` options, as not doing this has been deprecated and will need to be done in the future. | ||
|
||
To migrate an existing application, make the following change to `packages/app/src/App.tsx`: | ||
|
||
```diff | ||
+import { defaultAppComponents } from '@backstage/core-components'; | ||
|
||
// ... | ||
|
||
const app = createApp({ | ||
apis, | ||
+ components: defaultAppComponents(), | ||
bindRoutes({ bind }) { | ||
``` | ||
|
||
If you already supply custom app components, you can use the following: | ||
|
||
```diff | ||
|
||
// ... | ||
|
||
const app = createApp({ | ||
apis, | ||
+ components: { | ||
...defaultAppComponents(), | ||
+ Progress: MyCustomProgressComponent, | ||
}, | ||
bindRoutes({ bind }) { | ||
``` |
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,5 @@ | ||
--- | ||
'@backstage/core-components': patch | ||
--- | ||
|
||
Added a new `defaultAppComponents` method that creates a minimal set of components to pass on to `createApp` from `@backstage/core-app-api`. |
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,16 @@ | ||
--- | ||
'@backstage/core-app-api': patch | ||
--- | ||
|
||
Deprecated the defaulting of the `components` options of `createApp`, meaning it will become required in the future. When not passing the required components options a deprecation warning is currently logged, and it will become required in a future release. | ||
|
||
The keep the existing components intact, migrate to using `defaultAppComponents` from `@backstage/core-components`: | ||
|
||
```ts | ||
const app = createApp({ | ||
components: { | ||
...defaultAppComponents(), | ||
// Place any custom components here | ||
}, | ||
}); | ||
``` |
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
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
38 changes: 38 additions & 0 deletions
38
packages/core-components/src/defaultAppComponents.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,38 @@ | ||
/* | ||
* Copyright 2020 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { OptionallyWrapInRouter } from './defaultAppComponents'; | ||
|
||
describe('OptionallyWrapInRouter', () => { | ||
it('should wrap with router if not yet inside a router', async () => { | ||
render(<OptionallyWrapInRouter>Test</OptionallyWrapInRouter>); | ||
|
||
expect(screen.getByText('Test')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not wrap with router if already inside a router', async () => { | ||
render( | ||
<MemoryRouter> | ||
<OptionallyWrapInRouter>Test</OptionallyWrapInRouter> | ||
</MemoryRouter>, | ||
); | ||
|
||
expect(screen.getByText('Test')).toBeInTheDocument(); | ||
}); | ||
}); |
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,83 @@ | ||
/* | ||
* Copyright 2021 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import React, { ReactNode } from 'react'; | ||
import Button from '@material-ui/core/Button'; | ||
import { | ||
AppComponents, | ||
BootErrorPageProps, | ||
ErrorBoundaryFallbackProps, | ||
} from '@backstage/core-plugin-api'; | ||
import { ErrorPanel, Progress } from './components'; | ||
import { ErrorPage } from './layout'; | ||
import { MemoryRouter, useInRouterContext } from 'react-router'; | ||
|
||
export function OptionallyWrapInRouter({ children }: { children: ReactNode }) { | ||
if (useInRouterContext()) { | ||
return <>{children}</>; | ||
} | ||
return <MemoryRouter>{children}</MemoryRouter>; | ||
} | ||
|
||
const DefaultNotFoundPage = () => ( | ||
<ErrorPage status="404" statusMessage="PAGE NOT FOUND" /> | ||
); | ||
|
||
const DefaultBootErrorPage = ({ step, error }: BootErrorPageProps) => { | ||
let message = ''; | ||
if (step === 'load-config') { | ||
message = `The configuration failed to load, someone should have a look at this error: ${error.message}`; | ||
} else if (step === 'load-chunk') { | ||
message = `Lazy loaded chunk failed to load, try to reload the page: ${error.message}`; | ||
} | ||
// TODO: figure out a nicer way to handle routing on the error page, when it can be done. | ||
return ( | ||
<OptionallyWrapInRouter> | ||
<ErrorPage status="501" statusMessage={message} /> | ||
</OptionallyWrapInRouter> | ||
); | ||
}; | ||
const DefaultErrorBoundaryFallback = ({ | ||
error, | ||
resetError, | ||
plugin, | ||
}: ErrorBoundaryFallbackProps) => { | ||
return ( | ||
<ErrorPanel | ||
title={`Error in ${plugin?.getId()}`} | ||
defaultExpanded | ||
error={error} | ||
> | ||
<Button variant="outlined" onClick={resetError}> | ||
Retry | ||
</Button> | ||
</ErrorPanel> | ||
); | ||
}; | ||
|
||
/** | ||
* Creates a set of default components to pass along to {@link @backstage/core-app-api#createApp}. | ||
* | ||
* @public | ||
*/ | ||
export function defaultAppComponents(): Omit<AppComponents, 'Router'> { | ||
return { | ||
Progress, | ||
NotFoundErrorPage: DefaultNotFoundPage, | ||
BootErrorPage: DefaultBootErrorPage, | ||
ErrorBoundaryFallback: DefaultErrorBoundaryFallback, | ||
}; | ||
} |
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
Oops, something went wrong.