Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show loader skeleton in result view for running workflows #705

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/components/pretty-json-skeleton/pretty-json-skeleton.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { type Theme } from 'baseui';
import { type SkeletonOverrides } from 'baseui/skeleton/types';
import { type StyleObject } from 'styletron-react';

export const overrides = {
borderSkeleton: {
Row: {
style: ({ $theme }: { $theme: Theme }): StyleObject => ({
height: $theme.sizing.scale600,
borderRadius: $theme.borders.radius500,
}),
},
} satisfies SkeletonOverrides,
centralSkeleton: {
Root: {
style: ({ $theme }: { $theme: Theme }): StyleObject => ({
marginLeft: $theme.sizing.scale550,
marginTop: $theme.sizing.scale400,
marginBottom: $theme.sizing.scale400,
}),
},
Row: {
style: ({ $theme }: { $theme: Theme }): StyleObject => ({
height: $theme.sizing.scale600,
borderRadius: $theme.borders.radius500,
}),
},
} satisfies SkeletonOverrides,
};
30 changes: 30 additions & 0 deletions src/components/pretty-json-skeleton/pretty-json-skeleton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';
import { Skeleton } from 'baseui/skeleton';

import { overrides } from './pretty-json-skeleton.styles';
import { type Props } from './pretty-json-skeleton.types';

export default function PrettyJsonSkeleton({ width }: Props) {
return (
<div>
<Skeleton
width="20px"
rows={1}
overrides={overrides.borderSkeleton}
animation
/>
<Skeleton
width={width}
rows={3}
overrides={overrides.centralSkeleton}
animation
/>
<Skeleton
width="20px"
rows={1}
overrides={overrides.borderSkeleton}
animation
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type Props = {
width: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ import WorkflowSummaryTabJsonView from '../workflow-summary-tab-json-view';
jest.mock('copy-to-clipboard', jest.fn);
jest.mock(
'@/components/segmented-control-rounded/segmented-control-rounded',
() => jest.fn(() => <div>SegmentedControlRounded Mock</div>)
() =>
jest.fn(({ onChange }) => (
<div onClick={() => onChange({ activeKey: 'result' })}>
SegmentedControlRounded Mock
</div>
))
);
jest.mock('@/components/pretty-json/pretty-json', () =>
jest.fn(() => <div>PrettyJson Mock</div>)
);
jest.mock('@/components/pretty-json-skeleton/pretty-json-skeleton', () =>
jest.fn(() => <div>Mock JSON skeleton</div>)
);

describe('WorkflowSummaryTabJsonView Component', () => {
const inputJson = { input: 'inputJson' };
Expand All @@ -25,6 +33,7 @@ describe('WorkflowSummaryTabJsonView Component', () => {
<WorkflowSummaryTabJsonView
inputJson={inputJson}
resultJson={resultJson}
isWorkflowRunning={false}
/>
);

Expand All @@ -37,6 +46,7 @@ describe('WorkflowSummaryTabJsonView Component', () => {
<WorkflowSummaryTabJsonView
inputJson={inputJson}
resultJson={resultJson}
isWorkflowRunning={false}
/>
);

Expand All @@ -46,11 +56,27 @@ describe('WorkflowSummaryTabJsonView Component', () => {
expect(segmentedControl).toBeInTheDocument();
});

it('renders loading state correctly', () => {
const { getByText } = render(
<WorkflowSummaryTabJsonView
inputJson={inputJson}
resultJson={resultJson}
isWorkflowRunning={true}
/>
);

// Mock the onChange event for SegmentedControlRounded
const segmentedControl = screen.getByText('SegmentedControlRounded Mock');
fireEvent.click(segmentedControl);
expect(getByText('Mock JSON skeleton')).toBeInTheDocument();
});

it('copies JSON to clipboard', () => {
render(
<WorkflowSummaryTabJsonView
inputJson={inputJson}
resultJson={resultJson}
isWorkflowRunning={false}
/>
);

Expand All @@ -67,6 +93,7 @@ describe('WorkflowSummaryTabJsonView Component', () => {
<WorkflowSummaryTabJsonView
inputJson={inputJson}
resultJson={resultJson}
isWorkflowRunning={false}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
const cssStylesObj = {
jsonViewContainer: (theme) => ({
padding: theme.sizing.scale600,
backgroundColor: theme.colors.backgroundSecondary,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please correct the tertiaryBackground color in the theme and use it. Keeping both web and design inconsistent would make moving forward much harder

backgroundColor: '#F8F8F8',
borderRadius: theme.borders.radius300,
}),
jsonViewHeader: (theme) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { MdCopyAll } from 'react-icons/md';

import PrettyJson from '@/components/pretty-json/pretty-json';
import { type JsonValue } from '@/components/pretty-json/pretty-json.types';
import PrettyJsonSkeleton from '@/components/pretty-json-skeleton/pretty-json-skeleton';
import SegmentedControlRounded from '@/components/segmented-control-rounded/segmented-control-rounded';
import useStyletronClasses from '@/hooks/use-styletron-classes';

Expand All @@ -18,6 +19,7 @@ import type { Props } from './workflow-summary-tab-json-view.types';
export default function WorkflowSummaryTabJsonView({
inputJson,
resultJson,
isWorkflowRunning,
}: Props) {
const { cls } = useStyletronClasses(cssStyles);
const [showTooltip, setShowTooltip] = useState(false);
Expand Down Expand Up @@ -67,7 +69,11 @@ export default function WorkflowSummaryTabJsonView({
</Button>
</Tooltip>
</div>
<PrettyJson json={jsonMap[activeTab]} />
{activeTab === 'result' && isWorkflowRunning ? (
<PrettyJsonSkeleton width="200px" />
) : (
<PrettyJson json={jsonMap[activeTab]} />
)}
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { type JsonValue } from '@/components/pretty-json/pretty-json.types';
export type Props = {
inputJson: JsonValue;
resultJson: JsonValue;
isWorkflowRunning: boolean;
};
7 changes: 7 additions & 0 deletions src/views/workflow-summary-tab/workflow-summary-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import request from '@/utils/request';
import { type RequestError } from '@/utils/request/request-error';
import type { WorkflowPageTabContentProps } from '@/views/workflow-page/workflow-page-tab-content/workflow-page-tab-content.types';

import getWorkflowIsCompleted from '../workflow-page/helpers/get-workflow-is-completed';
import useDescribeWorkflow from '../workflow-page/hooks/use-describe-workflow';

import WorkflowSummaryTabDetails from './workflow-summary-tab-details/workflow-summary-tab-details';
Expand Down Expand Up @@ -62,6 +63,11 @@ export default function WorkflowSummaryTab({
? formattedCloseEvent.result
: undefined;

const isWorkflowRunning =
!closeEvent ||
!closeEvent.attributes ||
!getWorkflowIsCompleted(closeEvent.attributes);

return (
<PageSection>
<div className={cls.pageContainer}>
Expand All @@ -84,6 +90,7 @@ export default function WorkflowSummaryTab({
: []
}
resultJson={resultJson}
isWorkflowRunning={isWorkflowRunning}
/>
</div>
</div>
Expand Down
Loading