Skip to content

Commit

Permalink
[GEN-1793]: display source & destination errors in drawer (#1863)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenElferink authored Nov 26, 2024
1 parent 47fa3b3 commit 9d2bcf9
Show file tree
Hide file tree
Showing 16 changed files with 146 additions and 25 deletions.
2 changes: 1 addition & 1 deletion frontend/webapp/components/main/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Flex = styled.div`
const HeaderContainer = styled(Flex)`
width: 100%;
padding: 12px 0;
background-color: ${({ theme }) => theme.colors.dark_grey};
background-color: ${({ theme }) => theme.colors.darker_grey};
border-bottom: 1px solid rgba(249, 249, 249, 0.16);
`;

Expand Down
2 changes: 1 addition & 1 deletion frontend/webapp/components/setup/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const HeaderContainer = styled.div`
justify-content: space-between;
padding: 0 24px 0 32px;
align-items: center;
background-color: ${({ theme }) => theme.colors.dark_grey};
background-color: ${({ theme }) => theme.colors.darker_grey};
border-bottom: 1px solid rgba(249, 249, 249, 0.16);
height: 80px;
`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, { useState } from 'react';
import Image from 'next/image';
import styled from 'styled-components';
import { ConfiguredFields, DeleteWarning } from '@/components';
import { IAppState, useAppStore } from '@/store';
import type { ConfiguredDestination } from '@/types';
import { Button, Divider, Text } from '@/reuseable-components';
import { ConfiguredFields, DeleteWarning } from '@/components';
import { Button, Divider, ExtendIcon, Text } from '@/reuseable-components';

const Container = styled.div`
display: flex;
Expand Down Expand Up @@ -127,8 +127,8 @@ const ConfiguredDestinationsListItem: React.FC<{ item: ConfiguredDestination; is
<Image src='/icons/common/trash.svg' alt='delete' width={16} height={16} />
</IconButton>
<Divider orientation='vertical' length='16px' />
<IconButton variant='tertiary' $expand={expand} onClick={() => setExpand(!expand)}>
<Image src='/icons/common/extend-arrow.svg' alt='show more' width={16} height={16} />
<IconButton variant='tertiary' onClick={() => setExpand(!expand)}>
<ExtendIcon extend={expand} />
</IconButton>
</IconsContainer>
</ListItemHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styled from 'styled-components';
import { useDrawerStore } from '@/store';
import { CardDetails } from '@/components';
import buildDrawerItem from './build-drawer-item';
import { ConditionDetails } from '@/reuseable-components';
import OverviewDrawer from '../../overview/overview-drawer';
import { DestinationFormBody } from '../destination-form-body';
import { OVERVIEW_ENTITY_TYPES, type ActualDestination } from '@/types';
Expand All @@ -20,6 +21,12 @@ const FormContainer = styled.div`
overflow-y: auto;
`;

const DataContainer = styled.div`
display: flex;
flex-direction: column;
gap: 12px;
`;

export const DestinationDrawer: React.FC<Props> = () => {
const { selectedItem, setSelectedItem } = useDrawerStore();
const { destinations: destinationTypes } = useDestinationTypes();
Expand Down Expand Up @@ -128,7 +135,10 @@ export const DestinationDrawer: React.FC<Props> = () => {
/>
</FormContainer>
) : (
<CardDetails data={cardData} />
<DataContainer>
<ConditionDetails conditions={item.conditions} />
<CardDetails data={cardData} />
</DataContainer>
)}
</OverviewDrawer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const SearchResults = ({ searchText, onClose }: Props) => {
{searchResults.map(({ category, label, entities }, catIdx) => (
<Fragment key={`category-list-${category}`}>
<VerticalScroll style={{ maxHeight: selectedCategory !== 'all' ? '240px' : '140px' }}>
<Text size={12} family='secondary' color={theme.text.dark_grey} style={{ marginLeft: '16px' }}>
<Text size={12} family='secondary' color={theme.text.darker_grey} style={{ marginLeft: '16px' }}>
{label}
</Text>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Image from 'next/image';
import theme from '@/styles/theme';
import styled from 'styled-components';
import { UseSourceFormDataResponse } from '@/hooks';
import { Checkbox, Divider, NoDataFound, Text, Toggle } from '@/reuseable-components';
import { Checkbox, Divider, ExtendIcon, NoDataFound, Text, Toggle } from '@/reuseable-components';

interface Props extends UseSourceFormDataResponse {
isModal?: boolean;
Expand Down Expand Up @@ -149,7 +149,7 @@ export const SourcesList: React.FC<Props> = ({
<SelectionCount size={10} color={theme.text.grey}>
{namespaceLoaded ? `${selected.length}/${sources.length}` : null}
</SelectionCount>
<ArrowIcon src='/icons/common/extend-arrow.svg' alt='open-dropdown' width={14} height={14} className={isNamespaceSelected ? 'open' : 'close'} />
<ExtendIcon extend={isNamespaceSelected} />
</FlexRow>
</NamespaceItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useDrawerStore } from '@/store';
import { CardDetails } from '@/components';
import buildDrawerItem from './build-drawer-item';
import { UpdateSourceBody } from '../update-source-body';
import { ConditionDetails } from '@/reuseable-components';
import OverviewDrawer from '../../overview/overview-drawer';
import { ACTION, getMainContainerLanguageLogo } from '@/utils';
import { OVERVIEW_ENTITY_TYPES, WorkloadId, type K8sActualSource } from '@/types';
Expand Down Expand Up @@ -121,13 +122,8 @@ export const SourceDrawer: React.FC<Props> = () => {
</FormContainer>
) : (
<DataContainer>
<ConditionDetails conditions={item.instrumentedApplicationDetails.conditions} />
<CardDetails data={cardData} />
{/* <CardDetails
title='Resource Attributes'
data={[
{ title: 'Service Name', tooltip: 'This overrides the default service name that runs in your cluster.', value: (item as K8sActualSource).reportedName || (item as K8sActualSource).name },
]}
/> */}
</DataContainer>
)}
</OverviewDrawer>
Expand Down
4 changes: 2 additions & 2 deletions frontend/webapp/hooks/compute-platform/useComputePlatform.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo } from 'react';
import { safeJsonParse } from '@/utils';
import { BACKEND_BOOLEAN, safeJsonParse } from '@/utils';
import { useQuery } from '@apollo/client';
import { useBooleanStore } from '@/store';
import type { ComputePlatform } from '@/types';
Expand Down Expand Up @@ -54,7 +54,7 @@ export const useComputePlatform = (): UseComputePlatformHook => {
k8sActualSources = k8sActualSources.filter((source) => !!filters.types.find((type) => type.id === source.kind));
}
if (!!filters.onlyErrors) {
k8sActualSources = k8sActualSources.filter((source) => !!source.instrumentedApplicationDetails?.conditions?.find((cond) => cond.status === 'False'));
k8sActualSources = k8sActualSources.filter((source) => !!source.instrumentedApplicationDetails?.conditions?.find((cond) => cond.status === BACKEND_BOOLEAN.FALSE));
}
if (!!filters.errors.length) {
k8sActualSources = k8sActualSources.filter((source) => !!filters.errors.find((error) => !!source.instrumentedApplicationDetails?.conditions?.find((cond) => cond.message === error.id)));
Expand Down
80 changes: 80 additions & 0 deletions frontend/webapp/reuseable-components/condition-details/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { useMemo, useState } from 'react';
import Image from 'next/image';
import theme from '@/styles/theme';
import styled from 'styled-components';
import type { Condition } from '@/types';
import { BACKEND_BOOLEAN, getStatusIcon } from '@/utils';
import { ExtendIcon, FadeLoader, Text } from '@/reuseable-components';

interface Props {
conditions: Condition[];
}

const Container = styled.div<{ $hasErrors: boolean }>`
border-radius: 24px;
background-color: ${({ theme, $hasErrors }) => ($hasErrors ? theme.colors.darkest_red : theme.colors.white_opacity['004'])};
cursor: pointer;
&:hover {
background-color: ${({ theme, $hasErrors }) => ($hasErrors ? theme.colors.error : theme.colors.white_opacity['008'])};
}
transition: background 0.3s;
`;

const Header = styled.div`
display: flex;
align-items: center;
gap: 12px;
padding: 12px 18px;
`;

const Body = styled.div`
display: flex;
flex-direction: column;
gap: 8px;
padding: 6px 18px 12px 18px;
`;

const Row = styled.div`
display: flex;
align-items: center;
gap: 12px;
`;

export const ConditionDetails: React.FC<Props> = ({ conditions }) => {
const [loading, setLoading] = useState(false);
const [extend, setExtend] = useState(false);

const errors = useMemo(() => conditions.filter(({ status }) => status === BACKEND_BOOLEAN.FALSE), [conditions]);
const hasErrors = !!errors.length;
const headerText = loading ? 'Loading...' : hasErrors ? 'Operation Failed' : 'Operation Successful';

return (
<Container onClick={() => setExtend((prev) => !prev)} $hasErrors={hasErrors}>
<Header>
{loading ? <FadeLoader /> : <Image src={getStatusIcon(hasErrors ? 'error' : 'success')} alt='' width={16} height={16} />}

<Text color={hasErrors ? theme.text.error : theme.text.grey} size={14}>
{headerText}
</Text>
<Text color={hasErrors ? theme.text.error_secondary : theme.text.dark_grey} size={12} family='secondary'>
({hasErrors ? errors.length : conditions.length}/{conditions.length})
</Text>

<ExtendIcon extend={extend} />
</Header>

{extend && (
<Body>
{conditions.map(({ status, message }, idx) => (
<Row key={`condition-${idx}`}>
<Image src={getStatusIcon(status === BACKEND_BOOLEAN.FALSE ? 'error' : 'success')} alt='' width={14} height={14} />
<Text color={status === BACKEND_BOOLEAN.FALSE ? theme.text.error : theme.text.darker_grey} size={12}>
{message}
</Text>
</Row>
))}
</Body>
)}
</Container>
);
};
5 changes: 3 additions & 2 deletions frontend/webapp/reuseable-components/dropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { Input } from '../input';
import { Divider } from '../divider';
import { Checkbox } from '../checkbox';
import { DropdownOption } from '@/types';
import { FieldLabel } from '../field-label';
import { useOnClickOutside } from '@/hooks';
import { FieldLabel } from '../field-label';
import { ExtendIcon } from '../extend-icon';
import { NoDataFound } from '../no-data-found';
import styled, { css } from 'styled-components';
import theme, { hexPercentValues } from '@/styles/theme';
Expand Down Expand Up @@ -95,7 +96,7 @@ export const Dropdown: React.FC<DropdownProps> = ({ options, value, onSelect, on
<DropdownPlaceholder value={value} placeholder={placeholder} onDeselect={onDeselect} />
<IconWrapper>
{isMulti && <Badge label={arrLen} filled={!!arrLen} />}
<ArrowIcon src='/icons/common/extend-arrow.svg' alt='open-dropdown' width={14} height={14} className={isOpen ? 'open' : 'close'} />
<ExtendIcon extend={isOpen} />
</IconWrapper>
</DropdownHeader>

Expand Down
24 changes: 24 additions & 0 deletions frontend/webapp/reuseable-components/extend-icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import Image from 'next/image';
import styled from 'styled-components';

interface Props {
extend: boolean;
size?: number;
align?: 'left' | 'right';
}

const Icon = styled(Image)<{ $align?: Props['align'] }>`
&.open {
transform: rotate(180deg);
}
&.close {
transform: rotate(0deg);
}
transition: transform 0.3s;
margin-${({ $align }) => ($align === 'right' ? 'left' : 'right')}: auto;
`;

export const ExtendIcon: React.FC<Props> = ({ extend, size = 14, align = 'right' }) => {
return <Icon src='/icons/common/extend-arrow.svg' alt='extend' width={size} height={size} $align={align} className={extend ? 'open' : 'close'} />;
};
2 changes: 2 additions & 0 deletions frontend/webapp/reuseable-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ export * from './drawer';
export * from './input-table';
export * from './status';
export * from './field-label';
export * from './extend-icon';
export * from './condition-details';
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const SkeletonThumbnail = styled.div`
width: 50px;
height: 50px;
border-radius: 8px;
background: ${({ theme }) => `linear-gradient(90deg, ${theme.colors.primary} 25%, ${theme.colors.primary} 50%, ${theme.colors.dark_grey} 75%)`};
background: ${({ theme }) => `linear-gradient(90deg, ${theme.colors.primary} 25%, ${theme.colors.primary} 50%, ${theme.colors.darker_grey} 75%)`};
background-size: 200% 100%;
animation: ${shimmer} 10s infinite linear;
`;
Expand All @@ -38,7 +38,7 @@ const SkeletonText = styled.div`
const SkeletonLine = styled.div<{ $width: string }>`
height: 16px;
margin-bottom: 0.5rem;
background: ${({ theme }) => `linear-gradient(90deg, ${theme.colors.primary} 25%, ${theme.colors.primary} 50%, ${theme.colors.dark_grey} 75%)`};
background: ${({ theme }) => `linear-gradient(90deg, ${theme.colors.primary} 25%, ${theme.colors.primary} 50%, ${theme.colors.darker_grey} 75%)`};
background-size: 200% 100%;
animation: ${shimmer} 1.5s infinite linear;
width: ${({ $width }) => $width};
Expand Down
6 changes: 4 additions & 2 deletions frontend/webapp/styles/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ const colors = {

orange_og: '#FE9239',
orange_soft: '#FFB160',

dark_red: '#802828',
darker_red: '#611F1F',
darkest_red: '#281515',
dark_green: '#2D4323',

warning: '#472300',
Expand Down Expand Up @@ -229,12 +229,14 @@ const text = {
secondary: '#F9F9F9',
white: '#FFFFFF',
grey: '#B8B8B8',
dark_grey: '#7A7A7A',
dark_grey: '#8F8F8F',
darker_grey: '#7A7A7A',
light_grey: '#CCD0D2',
dark_button: '#0A1824',

warning: '#E9CF35',
error: '#EF7676',
error_secondary: '#DB5151',
success: '#81AF65',
info: '#B8B8B8',
default: '#AABEF7',
Expand Down
5 changes: 5 additions & 0 deletions frontend/webapp/utils/constants/string.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ export const NOTIFICATION: {
INFO: 'info',
DEFAULT: 'default',
};

export const BACKEND_BOOLEAN = {
FALSE: 'False',
TRUE: 'True',
};
3 changes: 2 additions & 1 deletion frontend/webapp/utils/functions/get-health-status.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BACKEND_BOOLEAN } from '../constants';
import { STATUSES, type ActualDestination, type K8sActualSource } from '@/types';

export const getHealthStatus = (item: K8sActualSource | ActualDestination) => {
const conditions = (item as K8sActualSource)?.instrumentedApplicationDetails?.conditions || (item as ActualDestination)?.conditions || [];
const isUnhealthy = !conditions.length || !!conditions.find(({ status }) => status === 'False');
const isUnhealthy = !conditions.length || !!conditions.find(({ status }) => status === BACKEND_BOOLEAN.FALSE);

return isUnhealthy ? STATUSES.UNHEALTHY : STATUSES.HEALTHY;
};

0 comments on commit 9d2bcf9

Please sign in to comment.