-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixes staging-docs (#4070) * Fixes staging-docs - var interpolation wasn't working with single quotes - also introduce change to skip versioning on PRs which makes the build much faster * Don't disable versioning on PRs * add notifications * Update javascript library version to 0.34.0 * Update helm chart to 4.0.32 to use gitops 0.34.0 * Update the helm reference * Update docs for release 0.34.0 * Update README to point download link to 0.34.0 * Remove test-connection.yaml * replace notiication context with props from EE * fix notifications * using AlertListErrors in Page * fix alert message padding --------- Co-authored-by: Simon <footless@gmail.com> Co-authored-by: weave-gitops-bot <weave-gitops-bot@weave.works> Co-authored-by: Lauri <lauri@weave.works>
- Loading branch information
1 parent
4def008
commit 794ef80
Showing
4 changed files
with
139 additions
and
6 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,130 @@ | ||
import { Box, Button, Collapse } from "@material-ui/core"; | ||
import Alert from "@material-ui/lab/Alert"; | ||
import { sortBy, uniqBy } from "lodash"; | ||
import React, { FC, useEffect, useState } from "react"; | ||
import styled from "styled-components"; | ||
import { ListError } from "../lib/api/core/core.pb"; | ||
import Flex from "./Flex"; | ||
import Icon, { IconType } from "./Icon"; | ||
import Text from "./Text"; | ||
|
||
type compinedError = ListError & { | ||
name?: string; | ||
message?: string; | ||
stack?: string; | ||
}; | ||
|
||
const BoxWrapper = styled(Box)` | ||
width: 100%; | ||
.MuiAlert-root { | ||
margin-bottom: ${(props) => props.theme.spacing.base}; | ||
background: ${(props) => props.theme.colors.alertLight}; | ||
border-radius: ${(props) => props.theme.spacing.xs}; | ||
align-items: center; | ||
} | ||
.MuiAlert-action { | ||
display: inline; | ||
color: ${(props) => props.theme.colors.alertMedium}; | ||
} | ||
.MuiIconButton-root:hover { | ||
background-color: ${(props) => props.theme.colors.alertLight}; | ||
} | ||
.MuiAlert-icon { | ||
.MuiSvgIcon-root { | ||
display: none; | ||
} | ||
} | ||
.MuiAlert-message { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: 0; | ||
} | ||
`; | ||
const ErrorText = styled(Text)` | ||
margin-left: 8px; | ||
`; | ||
const NavButton = styled(Button)` | ||
padding: 0; | ||
min-width: auto; | ||
margin: 0; | ||
`; | ||
const ErrorsCount = styled.span` | ||
background: ${(props) => props.theme.colors.feedbackMedium}; | ||
color: ${(props) => props.theme.colors.white}; | ||
padding: 4px; | ||
border-radius: 4px; | ||
margin: 0 4px; | ||
`; | ||
|
||
export const AlertListErrors: FC<{ | ||
errors?: compinedError[]; | ||
}> = ({ errors }) => { | ||
const [index, setIndex] = useState<number>(0); | ||
const [filteredErrors, setFilteredErrors] = useState<ListError[]>([]); | ||
const [show, setShow] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
const fErrors = sortBy( | ||
uniqBy(errors, (error) => [error.clusterName, error.message].join()), | ||
[(v) => v.clusterName, (v) => v.namespace, (v) => v.message] | ||
); | ||
setFilteredErrors(fErrors); | ||
setIndex(0); | ||
return () => { | ||
setFilteredErrors([]); | ||
}; | ||
}, [errors]); | ||
|
||
if (!errors || !errors.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<BoxWrapper id="alert-list-errors"> | ||
<Collapse in={show}> | ||
{!!filteredErrors[index] && ( | ||
<Alert severity="error" onClose={() => setShow(false)}> | ||
<Flex align center> | ||
<Icon type={IconType.ErrorIcon} size="medium" color="alertDark" /> | ||
<ErrorText data-testid="error-message" color="black"> | ||
{filteredErrors[index].clusterName}: | ||
{filteredErrors[index].message} | ||
</ErrorText> | ||
</Flex> | ||
{filteredErrors.length !== 1 && ( | ||
<Flex align center> | ||
<NavButton | ||
disabled={index === 0} | ||
data-testid="prevError" | ||
onClick={() => setIndex((currIndex) => currIndex - 1)} | ||
> | ||
<Icon | ||
type={IconType.NavigateBeforeIcon} | ||
color="alertMedium" | ||
size="medium" | ||
/> | ||
</NavButton> | ||
<ErrorsCount data-testid="errorsCount"> | ||
{filteredErrors.length} | ||
</ErrorsCount> | ||
<NavButton | ||
disabled={filteredErrors.length === index + 1} | ||
id="nextError" | ||
data-testid="nextError" | ||
onClick={() => setIndex((currIndex) => currIndex + 1)} | ||
> | ||
<Icon | ||
type={IconType.NavigateNextIcon} | ||
color="alertMedium" | ||
size="medium" | ||
/> | ||
</NavButton> | ||
</Flex> | ||
)} | ||
</Alert> | ||
)} | ||
</Collapse> | ||
</BoxWrapper> | ||
); | ||
}; |
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