Skip to content

Commit

Permalink
feat: allow offline results (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 authored Oct 5, 2023
1 parent 8437f63 commit 88325f4
Show file tree
Hide file tree
Showing 76 changed files with 456 additions and 228 deletions.
6 changes: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {useUpdate} from 'react-use';

import {config} from '@constants/config';

import {DashboardContext, MainContext} from '@contexts';
import {DashboardContext} from '@contexts';

import {SystemAccess, useSystemAccess} from '@hooks/useSystemAccess';

import {useModal} from '@modal/hooks';

Expand Down Expand Up @@ -43,8 +45,8 @@ export interface AppProps {}
const App: React.FC<AppProps> = () => {
const location = useLocation();
const apiEndpoint = useApiEndpoint();
const {isClusterAvailable} = useContext(MainContext);
const {showTestkubeCloudBanner} = useContext(DashboardContext);
const isClusterAvailable = useSystemAccess(SystemAccess.agent);

const [LogOutputProvider] = initializeLogOutputStore(undefined, [location.pathname]);

Expand Down
1 change: 1 addition & 0 deletions src/AppRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const AppRoot: React.FC = () => {
() => ({
clusterConfig,
isClusterAvailable: Boolean(clusterConfig),
isSystemAvailable: Boolean(clusterConfig),
}),
[clusterConfig]
);
Expand Down
7 changes: 4 additions & 3 deletions src/components/atoms/Dots/Dots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ type DotsProps = {
color?: Colors;
direction?: 'column' | 'row';
withPadding?: boolean;
disabled?: boolean;
};

const Dots: React.FC<DotsProps> = props => {
const {dotNumber = 3, color = Colors.purple, direction = 'column', withPadding = true} = props;
const {dotNumber = 3, color = Colors.purple, direction = 'column', withPadding = true, disabled} = props;

const dots = Array.from({length: dotNumber}).map((_, index) => {
const key = `dot_${index}`;

return <Dot key={key} color={color} />;
return <Dot key={key} color={disabled ? Colors.grey800 : color} />;
});

return (
<Button $customType="transparent" $withPadding={withPadding}>
<Button $customType="transparent" $withPadding={withPadding} disabled={disabled}>
<DotsContainer $direction={direction}>{dots}</DotsContainer>
</Button>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/atoms/Tag/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const Tag: FC<TagProps> = ({title, type = '', tooltipMessage, icon}) => {
<TagContainer className={`${type}`}>
{tooltipMessage ? (
<Tooltip title={tooltipMessage}>
<Text className="regular small">{title}</Text>
<Text className="regular small nowrap">{title}</Text>
</Tooltip>
) : (
<>
{icon}
<Text className="regular small">{title}</Text>
<Text className="regular small nowrap">{title}</Text>
</>
)}
</TagContainer>
Expand Down
12 changes: 10 additions & 2 deletions src/components/atoms/UploadWithInput/UploadWithInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ type UploadWithInputProps = {
fileName: string;
};
fieldInstance?: boolean;
disabled?: boolean;
} & Pick<UploadProps, 'beforeUpload'>;

const defaultBeforeUpload = () => false;

const UploadWithInput: FC<UploadWithInputProps> = props => {
const {onFileChange, beforeUpload = defaultBeforeUpload, value} = props;
const {onFileChange, beforeUpload = defaultBeforeUpload, value, disabled} = props;
const uploadRef = useRef<any>();
const onInputClick = useCallback(() => uploadRef.current?.upload.uploader.fileInput.click(), []);
const clear = useCallback(() => onFileChange(null), [onFileChange]);
Expand All @@ -42,7 +43,14 @@ const UploadWithInput: FC<UploadWithInputProps> = props => {
onChange={clear}
placeholder="Choose a file"
/>
<Upload ref={uploadRef} maxCount={1} onChange={onFileChange} showUploadList={false} beforeUpload={beforeUpload} />
<Upload
ref={uploadRef}
maxCount={1}
onChange={onFileChange}
showUploadList={false}
beforeUpload={beforeUpload}
disabled={disabled}
/>
</StyledUploadWithInputContainer>
);
};
Expand Down
4 changes: 4 additions & 0 deletions src/components/custom-antd/Typography/Text/Text.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ export const StyledText = styled(Typography.Text)<{$color?: string}>`
font-size: 12px;
line-height: 16px;
}
&.nowrap {
white-space: nowrap;
}
}
`;
2 changes: 1 addition & 1 deletion src/components/molecules/ArtifactsList/ArtifactsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ArtifactsList: React.FC<ArtifactsListProps> = props => {
if (!artifacts || !artifacts.length) {
return (
<Text className="semibold middle" color={Colors.whitePure}>
No artifacts
This test generated no artifacts.
</Text>
);
}
Expand Down
34 changes: 23 additions & 11 deletions src/components/molecules/Definition/Definition.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {PropsWithChildren, Suspense, useContext, useEffect, useState} from 'react';
import React, {PropsWithChildren, Suspense, useEffect, useState} from 'react';

import {MutationDefinition, QueryDefinition} from '@reduxjs/toolkit/dist/query';
import {UseMutation, UseQuery} from '@reduxjs/toolkit/dist/query/react/buildHooks';
Expand All @@ -8,16 +8,16 @@ import {capitalize} from 'lodash';

import {Pre} from '@atoms';

import {MainContext} from '@contexts';

import {FullWidthSpace} from '@custom-antd';

import useClusterVersionMatch from '@hooks/useClusterVersionMatch';
import {SystemAccess, useSystemAccess} from '@hooks/useSystemAccess';

import {InlineNotification, notificationCall} from '@molecules';

import {CardForm} from '@organisms';

import {safeRefetch} from '@utils/fetchUtils';
import {displayDefaultNotificationFlow} from '@utils/notification';

import KubernetesResourceEditor from '../KubernetesResourceEditor';
Expand All @@ -32,12 +32,24 @@ type DefinitionProps = {
label: string;
crdUrl?: string;
overrideSchema?: (schema: JSONSchema4) => JSONSchema4;
readPermissions?: SystemAccess;
readOnly?: boolean;
};

const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
const {name, onUpdate, useGetDefinitionQuery, useUpdateDefinitionMutation, crdUrl, label, overrideSchema} = props;

const {isClusterAvailable} = useContext(MainContext);
const {
name,
onUpdate,
useGetDefinitionQuery,
useUpdateDefinitionMutation,
crdUrl,
label,
overrideSchema,
readPermissions = SystemAccess.agent,
readOnly = false,
} = props;

const isReadable = useSystemAccess(readPermissions);
const isSupported = useClusterVersionMatch('>=1.13.0', true);

const [value, setValue] = useState('');
Expand All @@ -49,11 +61,11 @@ const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
isLoading: isDefinitionLoading,
refetch,
} = useGetDefinitionQuery(name, {
skip: !isClusterAvailable,
skip: !isReadable,
});

useEffect(() => {
refetch();
safeRefetch(refetch);
}, []);

useEffect(() => {
Expand Down Expand Up @@ -87,7 +99,7 @@ const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
.then(res => {
notificationCall('passed', `${capitalize(label)} was successfully updated.`);
onUpdate?.(res.data);
refetch();
safeRefetch(refetch);
});
};

Expand All @@ -114,7 +126,7 @@ const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
setValue(definition);
setWasTouched(false);
}}
readOnly={!isSupported}
readOnly={!isSupported || readOnly}
wasTouched={wasTouched}
>
{isDefinitionLoading ? (
Expand All @@ -123,7 +135,7 @@ const Definition: React.FC<PropsWithChildren<DefinitionProps>> = props => {
<Suspense fallback={<DefinitionSkeleton />}>
<KubernetesResourceEditor
value={value}
disabled={!isSupported}
disabled={!isSupported || readOnly}
onChange={newValue => {
setValue(newValue);
setWasTouched(true);
Expand Down
5 changes: 4 additions & 1 deletion src/components/molecules/DotsDropdown/DotsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface DotsDropdownProps {
wrapperStyle?: React.CSSProperties;
trigger?: ('click' | 'hover' | 'contextMenu')[];
overlayClassName?: string;
disabled?: boolean;
}

const DotsDropdown: React.FC<DotsDropdownProps> = ({
Expand All @@ -32,6 +33,7 @@ const DotsDropdown: React.FC<DotsDropdownProps> = ({
wrapperStyle = {},
trigger = ['click'],
overlayClassName = 'light-dropdown',
disabled,
}) => {
return (
<Dropdown
Expand All @@ -41,9 +43,10 @@ const DotsDropdown: React.FC<DotsDropdownProps> = ({
items,
}}
placement={placement}
disabled={disabled}
>
<DotsWrapper style={wrapperStyle} onClick={event => event.stopPropagation()}>
<Dots color={Colors.grey450} withPadding={withPadding} />
<Dots color={Colors.grey450} withPadding={withPadding} disabled={disabled} />
</DotsWrapper>
</Dropdown>
);
Expand Down
14 changes: 9 additions & 5 deletions src/components/molecules/EmptyListContent/EmptyListContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {ReactComponent as CreateTestIcon} from '@assets/create-test.svg';

import {ExternalLink} from '@atoms';

import {ConfigContext, MainContext} from '@contexts';
import {ConfigContext} from '@contexts';

import {Button, Text, Title} from '@custom-antd';

import {SystemAccess, useSystemAccess} from '@hooks/useSystemAccess';

import {HelpCard} from '@molecules';
import {StyledHelpCardsContainer, StyledLastHelpCardContainer} from '@molecules/HelpCard/HelpCard.styled';

Expand Down Expand Up @@ -45,7 +47,7 @@ const EmptyListContent: React.FC<PropsWithChildren<EmptyListContentProps>> = pro
} = props;

const {discordUrl} = useContext(ConfigContext);
const {isClusterAvailable} = useContext(MainContext);
const isClusterAvailable = useSystemAccess(SystemAccess.agent);
const isActionAvailable = usePermission(actionTypeToPermission[actionType]);

return (
Expand All @@ -57,9 +59,11 @@ const EmptyListContent: React.FC<PropsWithChildren<EmptyListContentProps>> = pro
<Text className="regular middle text-center" color={Colors.slate400}>
{description}
</Text>
<Button $customType="primary" onClick={onButtonClick} disabled={!isClusterAvailable}>
{buttonText}
</Button>
{isClusterAvailable ? (
<Button $customType="primary" onClick={onButtonClick}>
{buttonText}
</Button>
) : null}
<StyledHelpCardsContainer>
{children}
<StyledLastHelpCardContainer>
Expand Down
20 changes: 17 additions & 3 deletions src/components/molecules/EntityGrid/EntityGridItemPure.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {FC, forwardRef, memo, useCallback} from 'react';

import {ExecutorIcon, StatusIcon} from '@atoms';
import {ExecutorIcon, StatusIcon, Tag} from '@atoms';

import {Text} from '@custom-antd';

Expand Down Expand Up @@ -47,6 +47,8 @@ interface EntityGridItemPureProps {
onClick: (item: Item) => void;
onAbort: (item: Item) => void;
dataTest: string;
outOfSync?: boolean;
isAgentAvailable?: boolean;
}

const EntityGridItemTestIcon: FC<{item: Item}> = memo(({item}) => {
Expand All @@ -57,7 +59,7 @@ const EntityGridItemTestIcon: FC<{item: Item}> = memo(({item}) => {
const isRunningStatus = (status: string) => ['running', 'queued'].includes(status);

const EntityGridItemPure = forwardRef<HTMLDivElement, EntityGridItemPureProps>((props, ref) => {
const {item, latestExecution, onClick, onAbort, dataTest, metrics} = props;
const {item, latestExecution, onClick, onAbort, dataTest, metrics, outOfSync, isAgentAvailable} = props;

const status =
(latestExecution as Execution)?.executionResult?.status ||
Expand Down Expand Up @@ -85,17 +87,29 @@ const EntityGridItemPure = forwardRef<HTMLDivElement, EntityGridItemPureProps>((
<ItemColumn $isStretch>
<StatusIcon status={status} />
<EntityGridItemTestIcon item={item} />
<div style={{overflow: 'hidden', flex: 1, display: 'flex'}}>
<div style={{overflow: 'hidden', flex: 1, display: 'flex', alignItems: 'center', gap: '10px'}}>
<Text className="regular big" ellipsis title={item.name}>
{item.name}
</Text>
{outOfSync ? (
<Tag
title="read-only"
type="warning"
tooltipMessage={
isAgentAvailable
? 'This test is not currently present on your agent. You are only able to see historical data.'
: 'This test is potentially not in sync with the data on your local cluster. You are only able to see historical data.'
}
/>
) : null}
</div>
</ItemColumn>
<ExecutionTimeItemColumn>
<EntityGridItemExecutionTime time={latestExecution?.startTime} />
{isRunning ? (
<DotsDropdown
placement="bottomRight"
disabled={outOfSync}
items={[{key: 1, label: <span onClick={abort}>Abort all executions</span>}]}
/>
) : null}
Expand Down
5 changes: 3 additions & 2 deletions src/components/molecules/GitFormItems/Branch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {TooltipStatus, getValidationTooltip} from './tooltipUtils';
type BranchProps = {
status?: TooltipStatus;
message?: string;
disabled?: boolean;
};

const Branch: React.FC<BranchProps> = props => {
const {status = TooltipStatus.None, message} = props;
const {status = TooltipStatus.None, message, disabled} = props;

return (
<FormItem
Expand All @@ -24,7 +25,7 @@ const Branch: React.FC<BranchProps> = props => {
tooltip={getValidationTooltip(status, message)}
key="branch"
>
<Input placeholder="e.g.: main" />
<Input placeholder="e.g.: main" disabled={disabled} />
</FormItem>
);
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/molecules/GitFormItems/Commit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import {TooltipStatus, getValidationTooltip} from './tooltipUtils';
type CommitProps = {
status?: TooltipStatus;
message?: string;
disabled?: boolean;
};

const Commit: React.FC<CommitProps> = props => {
const {status = TooltipStatus.None, message} = props;
const {status = TooltipStatus.None, message, disabled} = props;

return (
<FormItem
Expand All @@ -24,7 +25,7 @@ const Commit: React.FC<CommitProps> = props => {
tooltip={getValidationTooltip(status, message)}
key="commit"
>
<Input placeholder="Enter commit id..." />
<Input placeholder="Enter commit id..." disabled={disabled} />
</FormItem>
);
};
Expand Down
Loading

0 comments on commit 88325f4

Please sign in to comment.