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

web: update the document title and favicon when Tilt UI disconnects #5678

Merged
merged 3 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions web/src/HUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ResourceSelectionProvider } from "./ResourceSelectionContext"
import ShareSnapshotModal from "./ShareSnapshotModal"
import { TiltSnackbarProvider } from "./Snackbar"
import { SnapshotActionProvider } from "./snapshot"
import SocketBar from "./SocketBar"
import SocketBar, { isSocketConnected } from "./SocketBar"
import { StarredResourcesContextProvider } from "./StarredResourcesContext"
import { ShowErrorModal, ShowFatalErrorModal, SocketState } from "./types"

Expand Down Expand Up @@ -198,10 +198,6 @@ export default class HUD extends Component<HudProps, HudState> {
}

let tiltfileKey = session?.tiltfileKey
let runningBuild = session?.runningTiltBuild
let suggestedVersion = session?.suggestedTiltVersion
const versionSettings = session?.versionSettings
const checkUpdates = versionSettings?.checkUpdates ?? true
let shareSnapshotModal = this.renderShareSnapshotModal(view)
let fatalErrorModal = this.renderFatalErrorModal(view)
let errorModal = this.renderErrorModal()
Expand Down Expand Up @@ -239,6 +235,7 @@ export default class HUD extends Component<HudProps, HudState> {
}

renderOverviewSwitch() {
const tiltConnected = isSocketConnected(this.state.socketState)
return (
<FeaturesProvider
featureFlags={this.state.view.uiSession?.status?.featureFlags || null}
Expand All @@ -253,12 +250,18 @@ export default class HUD extends Component<HudProps, HudState> {
<Route
path={this.path("/r/:name/overview")}
render={(props: RouteComponentProps<any>) => (
<OverviewResourcePane view={this.state.view} />
<OverviewResourcePane
view={this.state.view}
tiltConnected={tiltConnected}
/>
)}
/>
<Route
render={() => (
<OverviewTablePane view={this.state.view} />
<OverviewTablePane
view={this.state.view}
tiltConnected={tiltConnected}
/>
)}
/>
</Switch>
Expand Down
34 changes: 29 additions & 5 deletions web/src/HeaderBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,41 @@ export default {
}

export const TwoResources = () => (
<HeaderBar view={twoResourceView()} currentPage={AnalyticsType.Detail} />
<HeaderBar
view={twoResourceView()}
currentPage={AnalyticsType.Detail}
tiltConnected={true}
/>
)

export const TenResources = () => (
<HeaderBar view={tenResourceView()} currentPage={AnalyticsType.Detail} />
<HeaderBar
view={tenResourceView()}
currentPage={AnalyticsType.Detail}
tiltConnected={true}
/>
)

export const TenResourcesErrorsAndWarnings = () => {
let view = tenResourceView() as any
view.uiResources[0].status.updateStatus = UpdateStatus.Error
view.uiResources[1].status.buildHistory[0].warnings = ["warning time"]
view.uiResources[5].status.updateStatus = UpdateStatus.Error
return <HeaderBar view={view} currentPage={AnalyticsType.Grid} />
return (
<HeaderBar
view={view}
currentPage={AnalyticsType.Grid}
tiltConnected={true}
/>
)
}

export const OneHundredResources = () => (
<HeaderBar view={nResourceView(100)} currentPage={AnalyticsType.Grid} />
<HeaderBar
view={nResourceView(100)}
currentPage={AnalyticsType.Grid}
tiltConnected={true}
/>
)

export const UpgradeAvailable = () => {
Expand All @@ -44,5 +62,11 @@ export const UpgradeAvailable = () => {
status!.suggestedTiltVersion = "0.18.1"
status!.runningTiltBuild = { version: "0.18.0", dev: false }
status!.versionSettings = { checkUpdates: true }
return <HeaderBar view={view} currentPage={AnalyticsType.Detail} />
return (
<HeaderBar
view={view}
currentPage={AnalyticsType.Detail}
tiltConnected={true}
/>
)
}
8 changes: 7 additions & 1 deletion web/src/HeaderBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ const ViewLinkSection = styled.div`

type HeaderBarProps = {
view: Proto.webviewView
tiltConnected: boolean
currentPage?: AnalyticsType.Detail | AnalyticsType.Grid
}

export default function HeaderBar({ view, currentPage }: HeaderBarProps) {
export default function HeaderBar({
view,
currentPage,
tiltConnected,
}: HeaderBarProps) {
let isSnapshot = usePathBuilder().isSnapshot()
let snapshot = useSnapshotAction()
let session = view?.uiSession?.status
Expand Down Expand Up @@ -164,6 +169,7 @@ export default function HeaderBar({ view, currentPage }: HeaderBarProps) {
displayText="Resources"
labelText="Status summary for all resources"
resources={resources}
tiltConnected={tiltConnected}
/>
<CustomNav view={view} />
<GlobalNav {...globalNavProps} />
Expand Down
2 changes: 1 addition & 1 deletion web/src/OverviewResourcePane.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function OverviewResourcePaneHarness(props: {
return (
<MemoryRouter initialEntries={[entry]}>
<ResourceNavProvider validateResource={validateResource}>
<OverviewResourcePane view={view} />
<OverviewResourcePane view={view} tiltConnected={true} />
</ResourceNavProvider>
</MemoryRouter>
)
Expand Down
7 changes: 6 additions & 1 deletion web/src/OverviewResourcePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ResourceName } from "./types"
type UIResource = Proto.v1alpha1UIResource
type OverviewResourcePaneProps = {
view: Proto.webviewView
tiltConnected: boolean
}

let OverviewResourcePaneRoot = styled.div`
Expand Down Expand Up @@ -93,7 +94,11 @@ export default function OverviewResourcePane(props: OverviewResourcePaneProps) {

return (
<OverviewResourcePaneRoot>
<HeaderBar view={props.view} currentPage={AnalyticsType.Detail} />
<HeaderBar
view={props.view}
currentPage={AnalyticsType.Detail}
tiltConnected={props.tiltConnected}
/>
<StarredResourceBar
{...starredResourcePropsFromView(props.view, selectedTab)}
/>
Expand Down
16 changes: 10 additions & 6 deletions web/src/OverviewTablePane.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,25 @@ export default {
},
}

export const TwoResources = () => <OverviewTablePane view={twoResourceView()} />
export const TwoResources = () => (
<OverviewTablePane view={twoResourceView()} tiltConnected={true} />
)

export const TenResources = () => <OverviewTablePane view={tenResourceView()} />
export const TenResources = () => (
<OverviewTablePane view={tenResourceView()} tiltConnected={true} />
)

export const TenResourcesWithLabels = () => (
<OverviewTablePane view={nResourceWithLabelsView(10)} />
<OverviewTablePane view={nResourceWithLabelsView(10)} tiltConnected={true} />
)

export const OneHundredResources = () => (
<OverviewTablePane view={nResourceView(100)} />
<OverviewTablePane view={nResourceView(100)} tiltConnected={true} />
)

export const OneHundredResourcesOneStar = () => (
<StarredResourceMemoryProvider initialValueForTesting={["vigoda_2"]}>
<OverviewTablePane view={nResourceView(100)} />
<OverviewTablePane view={nResourceView(100)} tiltConnected={true} />
</StarredResourceMemoryProvider>
)

Expand All @@ -91,7 +95,7 @@ export const OneHundredResourcesTenStars = () => {
]
return (
<StarredResourceMemoryProvider initialValueForTesting={items}>
<OverviewTablePane view={nResourceView(100)} />
<OverviewTablePane view={nResourceView(100)} tiltConnected={true} />
</StarredResourceMemoryProvider>
)
}
7 changes: 6 additions & 1 deletion web/src/OverviewTablePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Color, SizeUnit, Width } from "./style-helpers"

type OverviewTablePaneProps = {
view: Proto.webviewView
tiltConnected: boolean
}

let OverviewTablePaneStyle = styled.div`
Expand Down Expand Up @@ -56,7 +57,11 @@ export default function OverviewTablePane(props: OverviewTablePaneProps) {
return (
<OverviewTablePaneStyle>
<OverviewTableStickyNav>
<HeaderBar view={props.view} currentPage={AnalyticsType.Grid} />
<HeaderBar
view={props.view}
currentPage={AnalyticsType.Grid}
tiltConnected={props.tiltConnected}
/>
<StarredResourceBar {...starredResourcePropsFromView(props.view, "")} />
<OverviewTableMenu aria-label="Resource menu">
<OverviewTableResourceNameFilter />
Expand Down
19 changes: 15 additions & 4 deletions web/src/ResourceStatusSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,18 @@ function statusCounts(statuses: ResourceStatus[]): StatusCounts {
}
}

function ResourceMetadata(props: { counts: StatusCounts }) {
function ResourceMetadata(props: {
counts: StatusCounts
tiltConnected?: boolean
lizzthabet marked this conversation as resolved.
Show resolved Hide resolved
}) {
let { totalEnabled, healthy, pending, unhealthy } = props.counts
useEffect(() => {
let favicon: any = document.head.querySelector("#favicon")
let faviconHref = ""
if (unhealthy > 0) {
if (props.tiltConnected === false) {
document.title = `… disconnected ┊ Tilt`
lizzthabet marked this conversation as resolved.
Show resolved Hide resolved
faviconHref = "/static/ico/favicon-gray.ico"
lizzthabet marked this conversation as resolved.
Show resolved Hide resolved
} else if (unhealthy > 0) {
document.title = `✖︎ ${unhealthy} ┊ Tilt`
faviconHref = "/static/ico/favicon-red.ico"
} else if (pending || totalEnabled === 0) {
Expand All @@ -317,7 +323,7 @@ function ResourceMetadata(props: { counts: StatusCounts }) {
if (favicon) {
favicon.href = faviconHref
}
}, [totalEnabled, healthy, pending, unhealthy])
}, [totalEnabled, healthy, pending, unhealthy, props.tiltConnected])
return <></>
}

Expand All @@ -330,6 +336,7 @@ type ResourceStatusSummaryOptions = {

type ResourceStatusSummaryProps = {
statuses: ResourceStatus[]
tiltConnected?: boolean
} & ResourceStatusSummaryOptions

function ResourceStatusSummary(props: ResourceStatusSummaryProps) {
Expand All @@ -341,7 +348,10 @@ function ResourceStatusSummary(props: ResourceStatusSummaryProps) {
return (
<ResourceStatusSummaryRoot aria-label={labelText}>
{updateMetadata && (
<ResourceMetadata counts={statusCounts(props.statuses)} />
<ResourceMetadata
counts={statusCounts(props.statuses)}
tiltConnected={props.tiltConnected}
/>
)}
<ResourceGroupStatus
counts={statusCounts(props.statuses)}
Expand All @@ -362,6 +372,7 @@ function ResourceStatusSummary(props: ResourceStatusSummaryProps) {

type StatusSummaryProps<T> = {
resources: readonly T[]
tiltConnected?: boolean
} & ResourceStatusSummaryOptions

export function SidebarGroupStatusSummary(
Expand Down
12 changes: 12 additions & 0 deletions web/src/SocketBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ let Bar = styled.div`
animation: ${pulse} 3s ease infinite;
`

export function isSocketConnected(state: SocketState) {
if (
state === SocketState.Reconnecting ||
state === SocketState.Closed ||
state === SocketState.Loading
) {
return false
}

return true
}

export default function SocketBar(props: SocketBarProps) {
let state = props.state
let message = ""
Expand Down