FN-6119: open CE docs in built-in file viewer
Expose the dashboard file viewer to plugin views and wire Compound Engineering artifacts to it. - add an openFile callback to the dashboard plugin view context and pass through the app host implementation - switch Compound Engineering artifact Open actions to the built-in file viewer with matching styling and coverage - document the new plugin context capability and add a published changeset for the CLI package Files changed: .changeset/ce-docs-built-in-viewer.md | 5 +++ docs/PLUGIN_AUTHORING.md | 2 +- packages/dashboard/app/App.tsx | 1 + packages/dashboard/app/plugins/types.ts | 2 ++ .../src/dashboard-interop.d.ts | 1 + .../src/dashboard/CompoundEngineeringView.css | 16 +++++++++ .../src/dashboard/CompoundEngineeringView.tsx | 24 +++++++------- .../__tests__/CompoundEngineeringView.test.tsx | 38 ++++++++++++++++++++++ 8 files changed, 76 insertions(+), 13 deletions(-) Fusion-Task-Id: FN-6119 Fusion-Task-Lineage: 8feb461c-b1d2-4059-9aa1-ffc756d15196
This commit is contained in:
5
.changeset/ce-docs-built-in-viewer.md
Normal file
5
.changeset/ce-docs-built-in-viewer.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@runfusion/fusion": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Expose the dashboard file viewer to plugin views and use it for Compound Engineering artifact documents.
|
||||||
@@ -769,7 +769,7 @@ Bundled workspace plugin pattern:
|
|||||||
|
|
||||||
Runtime host context contract:
|
Runtime host context contract:
|
||||||
- Registered views receive a `context` object from the dashboard host (`PluginDashboardViewContext`).
|
- Registered views receive a `context` object from the dashboard host (`PluginDashboardViewContext`).
|
||||||
- Context includes the active `projectId`, current visible `tasks`, optional `workflowSteps`, and `openTaskDetail` for launching the native task detail flow.
|
- Context includes the active `projectId`, current visible `tasks`, optional `workflowSteps`, `openTaskDetail` for launching the native task detail flow, and `openFile(path, options?)` for opening project-relative files in the dashboard's built-in file viewer.
|
||||||
- Keep view-specific UI behavior in the plugin; treat host context as service/data injection only.
|
- Keep view-specific UI behavior in the plugin; treat host context as service/data injection only.
|
||||||
|
|
||||||
Placement guidance:
|
Placement guidance:
|
||||||
|
|||||||
@@ -1446,6 +1446,7 @@ function AppInner() {
|
|||||||
workflowSteps,
|
workflowSteps,
|
||||||
subscribePluginEvents,
|
subscribePluginEvents,
|
||||||
openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => openDetailTask(task, initialTab),
|
openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => openDetailTask(task, initialTab),
|
||||||
|
openFile: openFileInBrowser,
|
||||||
renderTaskCard: (task: Task | TaskDetail) => (
|
renderTaskCard: (task: Task | TaskDetail) => (
|
||||||
<TaskCard
|
<TaskCard
|
||||||
task={task}
|
task={task}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ export interface PluginDashboardViewContext {
|
|||||||
tasks: Task[];
|
tasks: Task[];
|
||||||
workflowSteps: WorkflowStep[];
|
workflowSteps: WorkflowStep[];
|
||||||
openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => void;
|
openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => void;
|
||||||
|
/** Open a project-relative file in the dashboard's built-in file viewer. */
|
||||||
|
openFile: (path: string, options?: { workspace?: string; line?: number; col?: number }) => void;
|
||||||
renderTaskCard?: (task: Task | TaskDetail) => ReactNode;
|
renderTaskCard?: (task: Task | TaskDetail) => ReactNode;
|
||||||
addToast?: (message: string, type?: PluginToastType) => void;
|
addToast?: (message: string, type?: PluginToastType) => void;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ declare module "@fusion/dashboard/app/plugins/types" {
|
|||||||
tasks: Task[];
|
tasks: Task[];
|
||||||
workflowSteps: WorkflowStep[];
|
workflowSteps: WorkflowStep[];
|
||||||
openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => void;
|
openTaskDetail: (task: Task | TaskDetail, initialTab?: DetailTaskTab) => void;
|
||||||
|
openFile: (path: string, options?: { workspace?: string; line?: number; col?: number }) => void;
|
||||||
renderTaskCard?: (task: Task | TaskDetail) => ReactNode;
|
renderTaskCard?: (task: Task | TaskDetail) => ReactNode;
|
||||||
addToast?: (message: string, type?: PluginToastType) => void;
|
addToast?: (message: string, type?: PluginToastType) => void;
|
||||||
subscribePluginEvents?: (
|
subscribePluginEvents?: (
|
||||||
|
|||||||
@@ -135,6 +135,22 @@
|
|||||||
opacity: 0.55;
|
opacity: 0.55;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ce-artifact-open {
|
||||||
|
appearance: none;
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
color: var(--color-primary, #2563eb);
|
||||||
|
cursor: pointer;
|
||||||
|
font: inherit;
|
||||||
|
padding: 0;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ce-artifact-open:hover,
|
||||||
|
.ce-artifact-open:focus-visible {
|
||||||
|
color: var(--color-primary-hover, #1d4ed8);
|
||||||
|
}
|
||||||
|
|
||||||
.ce-artifact-error .ce-artifact-error-msg {
|
.ce-artifact-error .ce-artifact-error-msg {
|
||||||
color: var(--color-danger, #d23);
|
color: var(--color-danger, #d23);
|
||||||
font-size: 0.78rem;
|
font-size: 0.78rem;
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { useArtifacts } from "./hooks/useArtifacts.js";
|
|||||||
import { useViewportMode } from "./hooks/useViewportMode.js";
|
import { useViewportMode } from "./hooks/useViewportMode.js";
|
||||||
import { useCeSession, type CeSessionSubscribe } from "./hooks/useCeSession.js";
|
import { useCeSession, type CeSessionSubscribe } from "./hooks/useCeSession.js";
|
||||||
import { useCeSessions, type CeSessionsSubscribe } from "./hooks/useCeSessions.js";
|
import { useCeSessions, type CeSessionsSubscribe } from "./hooks/useCeSessions.js";
|
||||||
import { getArtifactPreviewUrl } from "./hooks/api.js";
|
|
||||||
import { CeFlow } from "./CeFlow.js";
|
import { CeFlow } from "./CeFlow.js";
|
||||||
import { getStage, listStages, type CeStageDefinition } from "../session/stage-registry.js";
|
import { getStage, listStages, type CeStageDefinition } from "../session/stage-registry.js";
|
||||||
import type { CeArtifactEntry, CeArtifactGroup } from "../artifacts/discovery.js";
|
import type { CeArtifactEntry, CeArtifactGroup } from "../artifacts/discovery.js";
|
||||||
@@ -170,14 +169,14 @@ function EmptyState({ onStart }: { onStart: () => void }) {
|
|||||||
|
|
||||||
function ArtifactRow({
|
function ArtifactRow({
|
||||||
entry,
|
entry,
|
||||||
projectId,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
selected,
|
selected,
|
||||||
|
openFile,
|
||||||
}: {
|
}: {
|
||||||
entry: CeArtifactEntry;
|
entry: CeArtifactEntry;
|
||||||
projectId?: string;
|
|
||||||
onSelect: (id: string) => void;
|
onSelect: (id: string) => void;
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
|
openFile?: PluginDashboardViewContext["openFile"];
|
||||||
}) {
|
}) {
|
||||||
if (entry.kind === "error") {
|
if (entry.kind === "error") {
|
||||||
return (
|
return (
|
||||||
@@ -196,28 +195,28 @@ function ArtifactRow({
|
|||||||
<span className="ce-artifact-name">{entry.name}</span>
|
<span className="ce-artifact-name">{entry.name}</span>
|
||||||
<span className="ce-artifact-path">{entry.path}</span>
|
<span className="ce-artifact-path">{entry.path}</span>
|
||||||
</button>
|
</button>
|
||||||
<a
|
<button
|
||||||
|
type="button"
|
||||||
className="ce-artifact-open"
|
className="ce-artifact-open"
|
||||||
href={getArtifactPreviewUrl(entry.id, projectId)}
|
data-testid="ce-artifact-open"
|
||||||
target="_blank"
|
onClick={() => openFile?.(entry.path)}
|
||||||
rel="noreferrer"
|
|
||||||
>
|
>
|
||||||
Open
|
Open
|
||||||
</a>
|
</button>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function StageGroup({
|
function StageGroup({
|
||||||
group,
|
group,
|
||||||
projectId,
|
|
||||||
onSelect,
|
onSelect,
|
||||||
selectedId,
|
selectedId,
|
||||||
|
openFile,
|
||||||
}: {
|
}: {
|
||||||
group: CeArtifactGroup;
|
group: CeArtifactGroup;
|
||||||
projectId?: string;
|
|
||||||
onSelect: (id: string) => void;
|
onSelect: (id: string) => void;
|
||||||
selectedId?: string;
|
selectedId?: string;
|
||||||
|
openFile?: PluginDashboardViewContext["openFile"];
|
||||||
}) {
|
}) {
|
||||||
const empty = group.entries.length === 0;
|
const empty = group.entries.length === 0;
|
||||||
return (
|
return (
|
||||||
@@ -236,9 +235,9 @@ function StageGroup({
|
|||||||
<ArtifactRow
|
<ArtifactRow
|
||||||
key={entry.id}
|
key={entry.id}
|
||||||
entry={entry}
|
entry={entry}
|
||||||
projectId={projectId}
|
|
||||||
onSelect={onSelect}
|
onSelect={onSelect}
|
||||||
selected={selectedId === entry.id}
|
selected={selectedId === entry.id}
|
||||||
|
openFile={openFile}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -261,6 +260,7 @@ export function CompoundEngineeringView(props: CompoundEngineeringViewProps) {
|
|||||||
// host doesn't supply it, the hook falls back to polling.
|
// host doesn't supply it, the hook falls back to polling.
|
||||||
const subscribePluginEvents = (props.context as PluginDashboardViewContext | undefined)
|
const subscribePluginEvents = (props.context as PluginDashboardViewContext | undefined)
|
||||||
?.subscribePluginEvents;
|
?.subscribePluginEvents;
|
||||||
|
const openFile = props.context?.openFile;
|
||||||
const subscribe = useMemo<CeSessionSubscribe | undefined>(() => {
|
const subscribe = useMemo<CeSessionSubscribe | undefined>(() => {
|
||||||
if (!subscribePluginEvents) return undefined;
|
if (!subscribePluginEvents) return undefined;
|
||||||
return (sessionId, _projectId, onSessionEvent) =>
|
return (sessionId, _projectId, onSessionEvent) =>
|
||||||
@@ -415,9 +415,9 @@ export function CompoundEngineeringView(props: CompoundEngineeringViewProps) {
|
|||||||
<StageGroup
|
<StageGroup
|
||||||
key={group.stage}
|
key={group.stage}
|
||||||
group={group}
|
group={group}
|
||||||
projectId={projectId}
|
|
||||||
onSelect={setSelectedId}
|
onSelect={setSelectedId}
|
||||||
selectedId={selectedId}
|
selectedId={selectedId}
|
||||||
|
openFile={openFile}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -119,6 +119,44 @@ describe("CompoundEngineeringView", () => {
|
|||||||
expect(screen.getAllByTestId("ce-group-empty").length).toBeGreaterThan(0);
|
expect(screen.getAllByTestId("ce-group-empty").length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("opens an artifact in the built-in file viewer via context.openFile", async () => {
|
||||||
|
const openFile = vi.fn();
|
||||||
|
listArtifacts.mockResolvedValue(
|
||||||
|
makeResult({
|
||||||
|
strategy: [
|
||||||
|
{ kind: "artifact", id: "strategy:STRATEGY.md", stage: "strategy", path: "STRATEGY.md", name: "STRATEGY.md", size: 10, updatedAt: 1 },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
render(
|
||||||
|
<CompoundEngineeringView
|
||||||
|
projectId="p1"
|
||||||
|
enabledOverride
|
||||||
|
context={{ openFile, tasks: [], workflowSteps: [], openTaskDetail: vi.fn() }}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
await screen.findByTestId("ce-artifact");
|
||||||
|
fireEvent.click(screen.getByTestId("ce-artifact-open"));
|
||||||
|
expect(openFile).toHaveBeenCalledWith("STRATEGY.md");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders artifact open button without crashing when openFile is not in context", async () => {
|
||||||
|
listArtifacts.mockResolvedValue(
|
||||||
|
makeResult({
|
||||||
|
strategy: [
|
||||||
|
{ kind: "artifact", id: "strategy:STRATEGY.md", stage: "strategy", path: "STRATEGY.md", name: "STRATEGY.md", size: 10, updatedAt: 1 },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
render(<CompoundEngineeringView projectId="p1" enabledOverride />);
|
||||||
|
|
||||||
|
await screen.findByTestId("ce-artifact");
|
||||||
|
const open = screen.getByTestId("ce-artifact-open");
|
||||||
|
expect(open).toBeInTheDocument();
|
||||||
|
fireEvent.click(open);
|
||||||
|
});
|
||||||
|
|
||||||
it("renders an error entry for an unreadable artifact (not a crash or silent drop)", async () => {
|
it("renders an error entry for an unreadable artifact (not a crash or silent drop)", async () => {
|
||||||
listArtifacts.mockResolvedValue(
|
listArtifacts.mockResolvedValue(
|
||||||
makeResult({
|
makeResult({
|
||||||
|
|||||||
Reference in New Issue
Block a user