-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extend progress stepper results
This changes the existing work on `ResultProgressStep` to include status handling for cancelled and failed. Further improving UX by ensuring that the status reporting is consistent across the page
- Loading branch information
Showing
5 changed files
with
171 additions
and
13 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 |
---|---|---|
|
@@ -2,15 +2,81 @@ | |
// SPDX-License-Identifier: MIT | ||
|
||
import React, { useMemo } from "react"; | ||
import { ProgressStepper, ProgressStep, Tooltip } from "@patternfly/react-core"; | ||
import { | ||
ProgressStepper, | ||
ProgressStep, | ||
Tooltip, | ||
ProgressStepProps, | ||
} from "@patternfly/react-core"; | ||
import { Timestamp } from "../utils/Timestamp"; | ||
import { prettyFormat } from "@imranbarbhuiya/duration"; | ||
import { | ||
AngleDoubleRightIcon, | ||
BanIcon, | ||
QuestionCircleIcon, | ||
SkypeIcon, | ||
} from "@patternfly/react-icons"; | ||
|
||
/** | ||
* Different statuses that we should map within the component | ||
*/ | ||
export type AcceptedStatuses = | ||
| "success" | ||
| "fail" | ||
| "skipped" | ||
| "cancelled" | ||
| "unknown"; | ||
|
||
/** | ||
* The icon and name that we will display to the user. Icon is taken from | ||
* PatternFly's ProgressStep directly and is thus inherited. Name is always a | ||
* lowercase word | ||
*/ | ||
type StepStatus = { | ||
// Inherited from PatternFly | ||
variant: NonNullable<ProgressStepProps["variant"]>; | ||
// Always lowercase and current-tense, such as "[the build] Failed" | ||
name: Lowercase<string>; | ||
icon?: React.ReactNode; | ||
}; | ||
|
||
/** | ||
* Key-value mapping of the accepted statuses that we will map within the | ||
* component, as well as an object value to contain the wording we will use and | ||
* the icon | ||
*/ | ||
export const ResultProgressStepStatus: Record<AcceptedStatuses, StepStatus> = { | ||
success: { | ||
variant: "success", | ||
name: "successful", | ||
}, | ||
fail: { | ||
variant: "danger", | ||
name: "failed", | ||
}, | ||
skipped: { | ||
variant: "pending", | ||
name: "skipped", | ||
icon: <AngleDoubleRightIcon />, | ||
}, | ||
cancelled: { | ||
variant: "danger", | ||
name: "cancelled", | ||
icon: <BanIcon />, | ||
}, | ||
unknown: { | ||
variant: "info", | ||
name: "unknown", | ||
icon: <QuestionCircleIcon />, | ||
}, | ||
}; | ||
|
||
export interface ResultProgressStepProps { | ||
submittedTime: number; | ||
startTime?: number; | ||
finishedTime?: number; | ||
noun?: string; | ||
status?: keyof typeof ResultProgressStepStatus; | ||
} | ||
|
||
/** | ||
|
@@ -19,18 +85,14 @@ export interface ResultProgressStepProps { | |
* build itself. However, this can be more versatile if need be | ||
* as we can change to a higher level component and use React contexts | ||
* | ||
* TODO (spytec): When/If we have consolidated the list of different | ||
* statuses between our results, such as a Results utility to help | ||
* us decide if a build/run is successful, in progress, failed, or | ||
* has warnings. Then we can incorporate that into this component to indicate where the failure is. | ||
* | ||
* @author Freya Gustavsson <[email protected]> | ||
* @author Freya Gustavsson <[email protected]> | ||
*/ | ||
export const ResultProgressStep: React.FC<ResultProgressStepProps> = ({ | ||
noun = "Build", | ||
submittedTime, | ||
startTime, | ||
finishedTime, | ||
status = "success", | ||
}) => { | ||
const submittedStep = useMemo(() => { | ||
const isCurrent = !startTime; | ||
|
@@ -65,7 +127,16 @@ export const ResultProgressStep: React.FC<ResultProgressStepProps> = ({ | |
return ( | ||
<ProgressStep | ||
isCurrent={isCurrent} | ||
variant={isPending ? "pending" : isCurrent ? "info" : "success"} | ||
variant={ | ||
isPending | ||
? "pending" | ||
: isCurrent | ||
? "info" | ||
: ResultProgressStepStatus[status].variant | ||
} | ||
icon={ | ||
finishedTimeEpoch ? ResultProgressStepStatus[status].icon : undefined | ||
} | ||
id="step-submitted" | ||
description={ | ||
startTime && finishedTime ? ( | ||
|
@@ -95,7 +166,12 @@ export const ResultProgressStep: React.FC<ResultProgressStepProps> = ({ | |
titleId="step-submitted-title" | ||
aria-label="has been submitted" | ||
> | ||
{noun} {isPending ? "Pending" : isCurrent ? "In Progress" : "Done"} | ||
{noun}{" "} | ||
{isPending | ||
? "Pending" | ||
: isCurrent | ||
? "In Progress" | ||
: ResultProgressStepStatus[status].name} | ||
</ProgressStep> | ||
); | ||
}, [startTime, finishedTime, noun]); | ||
|
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