fix: transform handlers don't auto-open bottom panel unnecessarily
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
buildBlogmarkTransformOutputEntries,
|
buildBlogmarkTransformOutputEntries,
|
||||||
buildBlogmarkTransformToastNotifications,
|
buildBlogmarkTransformToastNotifications,
|
||||||
parseBlogmarkCreatedEventPayload,
|
parseBlogmarkCreatedEventPayload,
|
||||||
|
shouldAutoOpenPanelForOutputEntries,
|
||||||
} from './navigation/blogmarkTransformOutput';
|
} from './navigation/blogmarkTransformOutput';
|
||||||
import { createDeferredEventGate } from './navigation/deferredEventGate';
|
import { createDeferredEventGate } from './navigation/deferredEventGate';
|
||||||
import { createAndFocusPost } from './navigation/postCreation';
|
import { createAndFocusPost } from './navigation/postCreation';
|
||||||
@@ -288,11 +289,13 @@ const App: React.FC = () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (shouldAutoOpenPanelForOutputEntries(outputEntries)) {
|
||||||
useAppStore.setState({
|
useAppStore.setState({
|
||||||
panelVisible: true,
|
panelVisible: true,
|
||||||
panelActiveTab: 'output',
|
panelActiveTab: 'output',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
blogmarkEventGateRef.current.push(created, processBlogmarkCreated);
|
blogmarkEventGateRef.current.push(created, processBlogmarkCreated);
|
||||||
}) || (() => {})
|
}) || (() => {})
|
||||||
|
|||||||
@@ -142,6 +142,12 @@ export function buildBlogmarkTransformOutputEntries(
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function shouldAutoOpenPanelForOutputEntries(
|
||||||
|
entries: Array<Omit<PanelOutputEntry, 'id' | 'createdAt'>>,
|
||||||
|
): boolean {
|
||||||
|
return entries.some((entry) => entry.kind === 'error' || entry.kind === 'stdout');
|
||||||
|
}
|
||||||
|
|
||||||
export function buildBlogmarkTransformToastNotifications(
|
export function buildBlogmarkTransformToastNotifications(
|
||||||
transform: BlogmarkTransformDebugInfo | undefined,
|
transform: BlogmarkTransformDebugInfo | undefined,
|
||||||
t: (key: string, values?: Record<string, string | number>) => string,
|
t: (key: string, values?: Record<string, string | number>) => string,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
buildBlogmarkTransformOutputEntries,
|
buildBlogmarkTransformOutputEntries,
|
||||||
buildBlogmarkTransformToastNotifications,
|
buildBlogmarkTransformToastNotifications,
|
||||||
parseBlogmarkCreatedEventPayload,
|
parseBlogmarkCreatedEventPayload,
|
||||||
|
shouldAutoOpenPanelForOutputEntries,
|
||||||
} from '../../../src/renderer/navigation/blogmarkTransformOutput';
|
} from '../../../src/renderer/navigation/blogmarkTransformOutput';
|
||||||
|
|
||||||
describe('parseBlogmarkCreatedEventPayload', () => {
|
describe('parseBlogmarkCreatedEventPayload', () => {
|
||||||
@@ -123,3 +124,42 @@ describe('buildBlogmarkTransformToastNotifications', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shouldAutoOpenPanelForOutputEntries', () => {
|
||||||
|
it('returns false for empty entries', () => {
|
||||||
|
expect(shouldAutoOpenPanelForOutputEntries([])).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when all entries are result kind', () => {
|
||||||
|
expect(shouldAutoOpenPanelForOutputEntries([
|
||||||
|
{ kind: 'result', message: 'summary:2:0' },
|
||||||
|
{ kind: 'result', message: 'applied:alpha, beta' },
|
||||||
|
])).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when entries contain an error', () => {
|
||||||
|
expect(shouldAutoOpenPanelForOutputEntries([
|
||||||
|
{ kind: 'result', message: 'summary:1:1' },
|
||||||
|
{ kind: 'error', message: 'failed:broken:boom' },
|
||||||
|
])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when entries contain stdout', () => {
|
||||||
|
expect(shouldAutoOpenPanelForOutputEntries([
|
||||||
|
{ kind: 'result', message: 'summary:1:0' },
|
||||||
|
{ kind: 'stdout', message: 'hello from python' },
|
||||||
|
])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when entries contain only errors', () => {
|
||||||
|
expect(shouldAutoOpenPanelForOutputEntries([
|
||||||
|
{ kind: 'error', message: 'uncaught exception' },
|
||||||
|
])).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns true when entries contain only stdout', () => {
|
||||||
|
expect(shouldAutoOpenPanelForOutputEntries([
|
||||||
|
{ kind: 'stdout', message: 'debug output' },
|
||||||
|
])).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user