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

TestAddon: Refactor UI & add config options #29662

Open
wants to merge 16 commits into
base: determine-total-test-count
Choose a base branch
from

Conversation

ndelangen
Copy link
Member

@ndelangen ndelangen commented Nov 19, 2024

What I did

  • refactor the UI components structure in addon-test
  • extract the render into a component
  • add a config property to the TestProviderState
  • add isEditing state to addon test's render

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 78.4 MB 78.4 MB 4.11 kB Infinity 0%
initSize 144 MB 144 MB -193 kB -1448.68 -0.1%
diffSize 65.3 MB 65.1 MB -197 kB -1479.56 -0.3%
buildSize 7.03 MB 6.83 MB -199 kB -Infinity -2.9%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.06 MB 1.86 MB -199 kB -Infinity 🔰-10.7%
buildSbPreviewSize 271 kB 271 kB 0 B - 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.03 MB 3.83 MB -199 kB -Infinity 🔰-5.2%
buildPreviewSize 3 MB 3 MB 39 B Infinity 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 23.2s 22.9s -254ms 0.97 -1.1%
generateTime 19.4s 18.9s -483ms -1.99 -2.6%
initTime 13.1s 13.6s 560ms 1.96 4.1%
buildTime 8.6s 8.1s -493ms -1.58 🔰-6%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.2s 5.9s 692ms 1.19 11.6%
devManagerResponsive 3.4s 3.6s 134ms 0.48 3.7%
devManagerHeaderVisible 550ms 603ms 53ms 1.12 8.8%
devManagerIndexVisible 627ms 706ms 79ms 1.72 🔺11.2%
devStoryVisibleUncached 895ms 1.1s 232ms 7.59 🔺20.6%
devStoryVisible 583ms 704ms 121ms 1.44 🔺17.2%
devAutodocsVisible 486ms 494ms 8ms -0.88 1.6%
devMDXVisible 552ms 541ms -11ms -0.05 -2%
buildManagerHeaderVisible 525ms 602ms 77ms 2.5 🔺12.8%
buildManagerIndexVisible 544ms 617ms 73ms 2.74 🔺11.8%
buildStoryVisible 523ms 603ms 80ms 2.64 🔺13.3%
buildAutodocsVisible 463ms 503ms 40ms 1.96 🔺8%
buildMDXVisible 454ms 508ms 54ms 1.04 10.6%

Greptile Summary

Here's my concise summary of the pull request changes:

Refactors the Test addon UI components to improve organization and maintainability, with a focus on separating concerns and enhancing the test results display.

  • Added new Description and TestProviderRender components to handle test state rendering and UI interactions
  • Moved UI logic out of manager.tsx into dedicated component files for better separation of concerns
  • Enhanced RelativeTime component with improved time formatting using Intl.RelativeTimeFormat
  • Added styled animations and themed colors for test states (running/failed/crashed) in TestingModule
  • Made TestProviderState generic to support flexible Details types across components

@ndelangen ndelangen self-assigned this Nov 19, 2024
<TestProvider key={state.id} data-module-id={state.id}>
{Render ? <Render {...state} /> : <LegacyRender {...state} />}
<LegacyRender {...state} />
Copy link
Member Author

Choose a reason for hiding this comment

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

@ghengeveld Do you think we could drop the legacy render completely?

Copy link
Member

Choose a reason for hiding this comment

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

It's still being used by VTA right now. I haven't updated the VTA yet and people will be using the old version for a while.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

8 file(s) reviewed, 10 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +24 to +25
} else if (state.failed && !errorMessage) {
description = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Setting description to empty string when failed without error message could lead to confusing UI state. Consider showing a default failure message instead.

@@ -1,6 +1,23 @@
import { useEffect, useState } from 'react';

import { getRelativeTimeString } from '../manager';
export function getRelativeTimeString(date: Date): string {
const delta = Math.round((date.getTime() - Date.now()) / 1000);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: delta calculation will be negative for future dates, but Math.abs is only used later - could cause incorrect time displays

const divisor = unitIndex ? cutoffs[unitIndex - 1] : 1;
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
return rtf.format(Math.floor(delta / divisor), units[unitIndex]);
}

export const RelativeTime = ({ timestamp, testCount }: { timestamp: Date; testCount: number }) => {
const [relativeTimeString, setRelativeTimeString] = useState(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: initial state should be typed as useState<string | null>(null)

import { TestProviderRender } from './TestProviderRender';

type Story = StoryObj<typeof TestProviderRender>;
const managerContext: any = {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Avoid using 'any' type for managerContext. Consider creating a proper type definition based on ManagerContext requirements.

code/addons/test/src/components/TestProviderRender.tsx Outdated Show resolved Hide resolved
code/addons/test/src/constants.ts Outdated Show resolved Hide resolved
code/addons/test/src/constants.ts Outdated Show resolved Hide resolved
import { Title } from './components/Title';
import { ADDON_ID, PANEL_ID, TEST_PROVIDER_ID } from './constants';
import type { TestResult } from './node/reporter';
import { ADDON_ID, type Details, PANEL_ID, TEST_PROVIDER_ID } from './constants';

const statusMap: Record<any['status'], API_StatusValue> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

style: statusMap uses 'any' type for status key which could be more strictly typed

@@ -4,7 +4,8 @@ type DateNow = number;

export type TestProviderId = Addon_TestProviderType['id'];
export type TestProviderConfig = Addon_TestProviderType;
export type TestProviderState = Addon_TestProviderState;
export type TestProviderState<Details extends { [key: string]: any } = NonNullable<unknown>> =
Addon_TestProviderState<Details>;

export type TestProviders = Record<TestProviderId, TestProviderConfig & TestProviderState>;
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: TestProviders type needs to be updated to use the generic parameter, should be Record<TestProviderId, TestProviderConfig & TestProviderState>

@ndelangen ndelangen changed the title TestAddon: Refactor UI TestAddon: Refactor UI & add config options Nov 19, 2024
Copy link

nx-cloud bot commented Nov 20, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 29f1b77. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@ndelangen ndelangen changed the base branch from next to determine-total-test-count November 21, 2024 09:19
@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Nov 21, 2024

Package Benchmarks

Commit: 29f1b77, ran on 22 November 2024 at 11:23:45 UTC

No significant changes detected, all good. 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants