generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #196 from chromaui/ghengeveld/ap-4234-vta-when-ses…
…sion-is-closed-theres-no-indication-why-the-vta Show notification when connection to server is lost
- Loading branch information
Showing
2 changed files
with
36 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,55 @@ | ||
import { addons, types } from "@storybook/manager-api"; | ||
import { addons, type API } from "@storybook/manager-api"; | ||
import { color } from "@storybook/theming"; | ||
import { Addon_TypesEnum } from "@storybook/types"; | ||
import React from "react"; | ||
|
||
import { ADDON_ID, PANEL_ID, SIDEBAR_BOTTOM_ID, SIDEBAR_TOP_ID } from "./constants"; | ||
import { Panel } from "./Panel"; | ||
import { SidebarBottom } from "./SidebarBottom"; | ||
import { SidebarTop } from "./SidebarTop"; | ||
|
||
let heartbeatTimeout: NodeJS.Timeout; | ||
const expectHeartbeat = (api: API) => { | ||
heartbeatTimeout = setTimeout(() => expectHeartbeat(api), 30000); | ||
}; | ||
|
||
addons.register(ADDON_ID, (api) => { | ||
addons.add(PANEL_ID, { | ||
type: types.PANEL, | ||
type: Addon_TypesEnum.PANEL, | ||
title: "Visual Tests", | ||
match: ({ viewMode }) => viewMode === "story", | ||
render: ({ active }) => <Panel active={!!active} api={api} />, | ||
}); | ||
|
||
addons.add(SIDEBAR_TOP_ID, { | ||
type: types.experimental_SIDEBAR_TOP, | ||
type: Addon_TypesEnum.experimental_SIDEBAR_TOP, | ||
render: () => <SidebarTop api={api} />, | ||
}); | ||
|
||
addons.add(SIDEBAR_BOTTOM_ID, { | ||
type: types.experimental_SIDEBAR_BOTTOM, | ||
type: Addon_TypesEnum.experimental_SIDEBAR_BOTTOM, | ||
render: () => <SidebarBottom api={api} />, | ||
}); | ||
|
||
const channel = api.getChannel(); | ||
if (!channel) return; | ||
|
||
channel.on(`${ADDON_ID}/heartbeat`, () => { | ||
clearTimeout(heartbeatTimeout); | ||
heartbeatTimeout = setTimeout(() => { | ||
api.addNotification({ | ||
id: `${ADDON_ID}/connection-lost`, | ||
content: { | ||
headline: "Connection lost", | ||
subHeadline: "Lost connection to the Storybook server. Try refreshing the page.", | ||
}, | ||
icon: { | ||
name: "failed", | ||
color: color.negative, | ||
}, | ||
// @ts-expect-error SB needs a proper API for no link | ||
link: undefined, | ||
}); | ||
}, 3000); | ||
}); | ||
}); |