Skip to content

Commit

Permalink
fix: warnings and errors count
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Oct 28, 2021
1 parent b6d2bf3 commit 3a33207
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import MonoIcon, {MonoIconTypes} from '@components/atoms/MonoIcon';
import {useAppSelector} from '@redux/hooks';
import {ResourceRefType} from '@models/k8sresource';
import Colors from '@styles/Colors';
import {isInPreviewModeSelector} from '@redux/selectors';
import {PREVIEW_PREFIX} from '@constants/constants';

const Container = styled.span`
width: 100%;
Expand All @@ -25,18 +27,27 @@ const Label = styled.span`

function WarningsAndErrorsDisplay() {
const resourceMap = useAppSelector(state => state.main.resourceMap);
const isInPreviewMode = useAppSelector(isInPreviewModeSelector);

const warningsCount = useMemo(() => {
return Object.values(resourceMap).reduce<number>((acc, resource) => {
return acc + (resource.refs ? resource.refs.filter(ref => ref.type === ResourceRefType.Unsatisfied).length : 0);
}, 0);
}, [resourceMap]);
return Object.values(resourceMap)
.filter(resource =>
isInPreviewMode ? resource.filePath.startsWith(PREVIEW_PREFIX) : !resource.filePath.startsWith(PREVIEW_PREFIX)
)
.reduce<number>((acc, resource) => {
return acc + (resource.refs ? resource.refs.filter(ref => ref.type === ResourceRefType.Unsatisfied).length : 0);
}, 0);
}, [resourceMap, isInPreviewMode]);

const errorsCount = useMemo(() => {
return Object.values(resourceMap).reduce<number>((acc, resource) => {
return acc + (resource.validation && !resource.validation.isValid ? resource.validation.errors.length : 0);
}, 0);
}, [resourceMap]);
return Object.values(resourceMap)
.filter(resource =>
isInPreviewMode ? resource.filePath.startsWith(PREVIEW_PREFIX) : !resource.filePath.startsWith(PREVIEW_PREFIX)
)
.reduce<number>((acc, resource) => {
return acc + (resource.validation && !resource.validation.isValid ? resource.validation.errors.length : 0);
}, 0);
}, [resourceMap, isInPreviewMode]);

return (
<Container>
Expand All @@ -46,7 +57,7 @@ function WarningsAndErrorsDisplay() {
<Label>{warningsCount}</Label>
</WarningContainer>
)}
{errorsCount && (
{errorsCount > 0 && (
<ErrorContainer>
<MonoIcon type={MonoIconTypes.Error} />
<Label>{errorsCount}</Label>
Expand Down

0 comments on commit 3a33207

Please sign in to comment.