Merge pull request #13522 from mufaddal7/scaffolder/error-handling

Scaffolder - Addition of  Dismissable Error Banner
This commit is contained in:
Fredrik Adelöw
2022-09-09 08:48:01 +02:00
committed by GitHub
4 changed files with 49 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder': patch
---
Addition of a dismissible Error Banner in Scaffolder page
@@ -0,0 +1,39 @@
/*
* Copyright 2022 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 { Box } from '@material-ui/core';
import React, { useEffect, useRef } from 'react';
import { DismissableBanner } from '@backstage/core-components';
type TaskErrorsProps = {
error?: Error;
};
export const TaskErrors = ({ error }: TaskErrorsProps) => {
const id = useRef('');
useEffect(() => {
id.current = String(Math.random());
}, [error]);
return error ? (
<Box>
<DismissableBanner
id={id.current}
variant="warning"
message={error.message}
/>
</Box>
) : null;
};
@@ -54,6 +54,7 @@ import {
} from '../../routes';
import { ScaffolderTaskStatus, ScaffolderTaskOutput } from '../../types';
import { useTaskEventStream } from '../hooks/useEventStream';
import { TaskErrors } from './TaskErrors';
import { TaskPageLinks } from './TaskPageLinks';
// typings are wrong for this library, so fallback to not parsing types.
@@ -356,6 +357,7 @@ export const TaskPage = ({ loadingText }: TaskPageProps) => {
{!currentStepId && <Progress />}
<div style={{ height: '80vh' }}>
<TaskErrors error={taskStream.error} />
<LogViewer text={logAsString} />
</div>
</Grid>
@@ -49,6 +49,7 @@ type ReducerLogEntry = {
status?: ScaffolderTaskStatus;
message: string;
output?: ScaffolderTaskOutput;
error?: Error;
};
};
@@ -114,6 +115,8 @@ function reducer(draft: TaskStream, action: ReducerAction) {
case 'COMPLETED': {
draft.completed = true;
draft.output = action.data.body.output;
draft.error = action.data.body.error;
return;
}