improvements

This commit is contained in:
Norbert de Langen 2024-11-13 12:05:10 +01:00
parent b20b07cfa8
commit 7ad41a75b1
4 changed files with 30 additions and 26 deletions

View File

@ -109,8 +109,7 @@ const ContextMenuItem: FC<{
const onClick = useCallback(
(event: SyntheticEvent) => {
event.stopPropagation();
// TODO - actually send along a sub-set based on `context` to test.
api.getChannel().emit(TESTING_MODULE_RUN_ALL_REQUEST, { providerId: TEST_PROVIDER_ID });
api.runTestprovider(TEST_PROVIDER_ID, { selection: [context.id] });
},
[api]
);

View File

@ -42,7 +42,6 @@ export type Link = CustomLink | NormalLink;
*/
interface CustomLink {
id: string;
icon?: any;
content: ReactNode;
}
@ -68,7 +67,7 @@ export interface TooltipLinkListProps extends ComponentProps<typeof List> {
export const TooltipLinkList = ({ links, LinkWrapper, ...props }: TooltipLinkListProps) => {
const groups = Array.isArray(links[0]) ? (links as Link[][]) : [links as Link[]];
const isIndented = groups.some((group) => group.some((link) => link.icon));
const isIndented = groups.some((group) => group.some((link) => 'icon' in link && link.icon));
return (
<List {...props}>
{groups

View File

@ -14,8 +14,6 @@ export type SubState = {
testProviders: TestProviders;
};
const STORAGE_KEY = '@storybook/manager/test-providers';
const initialTestProviderState: TestProviderState = {
details: {} as { [key: string]: any },
cancellable: false,
@ -39,15 +37,8 @@ export type SubAPI = {
};
export const init: ModuleFn = ({ store, fullAPI }) => {
let sessionState: TestProviders = {};
try {
sessionState = JSON.parse(sessionStorage.getItem(STORAGE_KEY) || '{}');
} catch (_) {
//
}
const state: SubState = {
testProviders: sessionState,
testProviders: store.getState().testProviders,
};
const api: SubAPI = {
@ -81,7 +72,17 @@ export const init: ModuleFn = ({ store, fullAPI }) => {
},
runTestprovider(id, options) {
if (options?.selection) {
const listOfFiles = [];
const listOfFiles: string[] = [];
// TODO: get actual list and emit, this notification is for development purposes
fullAPI.addNotification({
id: 'testing-module',
content: {
headline: 'Running tests',
subHeadline: `Running tests for ${listOfFiles} stories`,
},
});
// fullAPI.emit(TESTING_MODULE_RUN_REQUEST, { providerId: id, selection: [] });
} else {
fullAPI.emit(TESTING_MODULE_RUN_ALL_REQUEST, { providerId: id });
@ -96,9 +97,16 @@ export const init: ModuleFn = ({ store, fullAPI }) => {
};
const initModule = async () => {
const initialState = Object.fromEntries(
const initialState: TestProviders = Object.fromEntries(
Object.entries(fullAPI.getElements(Addon_TypesEnum.experimental_TEST_PROVIDER)).map(
([id, config]) => [id, { ...config, ...initialTestProviderState, ...sessionState[id] }]
([id, config]) => [
id,
{
...config,
...initialTestProviderState,
...state.testProviders[id],
} as TestProviders[0],
]
)
);

View File

@ -1,4 +1,4 @@
import type { ComponentProps, FC, MutableRefObject } from 'react';
import type { ComponentProps, FC, MutableRefObject, SyntheticEvent } from 'react';
import React, { useCallback, useMemo, useRef, useState } from 'react';
import {
@ -445,7 +445,7 @@ const useContextMenu = (context: API_HashEntry, links: Link[], api: API) => {
onMouseLeave: () => {
setIsItemHovered(false);
},
onOpen: (event: any) => {
onOpen: (event: SyntheticEvent) => {
event.stopPropagation();
setIsOpen(true);
},
@ -470,8 +470,8 @@ const useContextMenu = (context: API_HashEntry, links: Link[], api: API) => {
closeOnOutsideClick
onClick={handlers.onOpen}
placement="bottom-end"
onVisibleChange={(visisble) => {
if (!visisble) {
onVisibleChange={(visible) => {
if (!visible) {
handlers.onClose();
} else {
setIsOpen(true);
@ -749,21 +749,19 @@ export const Tree = React.memo<{
function generateTestProviderLinks(testProviders: TestProviders, context: API_HashEntry): Link[] {
return Object.entries(testProviders)
.map(([k, e]) => {
const state = e;
.map(([testProviderId, state]) => {
if (!state) {
return null;
}
const content = e.contextMenu?.({ context, state }, ContextMenu);
const content = state.contextMenu?.({ context, state }, ContextMenu);
if (!content) {
return null;
}
return {
id: k,
id: testProviderId,
content,
};
})