Skip to content

Commit

Permalink
tilt: show snapshot creator username in snapshot (#2134)
Browse files Browse the repository at this point in the history
  • Loading branch information
landism authored Aug 28, 2019
1 parent 52e5f3a commit 376480a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 1 deletion.
6 changes: 6 additions & 0 deletions web/src/HUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class HUD extends Component<HudProps, HudState> {
}
let showSnapshot =
features.isEnabled("snapshots") && !this.pathBuilder.isSnapshot()
let snapshotOwner: string | null = null
if (features.isEnabled("snapshots") && this.state.View) {
snapshotOwner = this.state.View.TiltCloudUsername
}

let sidebarRoute = (t: ResourceView, props: RouteComponentProps<any>) => {
let name = props.match.params.name
Expand Down Expand Up @@ -229,6 +233,7 @@ class HUD extends Component<HudProps, HudState> {
sailUrl={sailUrl}
numberOfAlerts={numAlerts}
showSnapshotButton={showSnapshot}
snapshotOwner={snapshotOwner}
handleOpenModal={handleOpenModal}
/>
)
Expand All @@ -251,6 +256,7 @@ class HUD extends Component<HudProps, HudState> {
sailUrl={sailUrl}
numberOfAlerts={numAlerts}
showSnapshotButton={showSnapshot}
snapshotOwner={snapshotOwner}
handleOpenModal={handleOpenModal}
/>
)
Expand Down
26 changes: 26 additions & 0 deletions web/src/TopBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ it("shows sail share button", () => {
sailUrl=""
numberOfAlerts={0}
showSnapshotButton={false}
snapshotOwner={null}
handleOpenModal={fakeHandleOpenModal}
/>
</MemoryRouter>
Expand All @@ -41,6 +42,7 @@ it("shows sail url", () => {
sailUrl="www.sail.dev/xyz"
numberOfAlerts={1}
showSnapshotButton={false}
snapshotOwner={null}
handleOpenModal={fakeHandleOpenModal}
/>
</MemoryRouter>
Expand All @@ -63,6 +65,30 @@ it("shows snapshot url", () => {
sailUrl="www.sail.dev/xyz"
numberOfAlerts={1}
showSnapshotButton={true}
snapshotOwner={null}
handleOpenModal={fakeHandleOpenModal}
/>
</MemoryRouter>
)
.toJSON()

expect(tree).toMatchSnapshot()
})

it("shows snapshot owner", () => {
const tree = renderer
.create(
<MemoryRouter>
<TopBar
logUrl="/r/foo"
previewUrl="/r/foo/preview"
alertsUrl="/r/foo/alerts"
resourceView={ResourceView.Alerts}
sailEnabled={false}
sailUrl="www.sail.dev/xyz"
numberOfAlerts={1}
showSnapshotButton={false}
snapshotOwner="foo"
handleOpenModal={fakeHandleOpenModal}
/>
</MemoryRouter>
Expand Down
17 changes: 16 additions & 1 deletion web/src/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type TopBarProps = {
sailUrl: string
numberOfAlerts: number
showSnapshotButton: boolean
snapshotOwner: string | null
handleOpenModal: () => void
}

Expand All @@ -28,7 +29,9 @@ class TopBar extends PureComponent<TopBarProps> {
numberOfAlerts={this.props.numberOfAlerts}
/>
<section className="TopBar-tools">
{this.props.showSnapshotButton && this.renderSnapshotModal()}
{this.props.showSnapshotButton
? this.renderSnapshotModal()
: this.renderSnapshotOwner()}
<SailInfo
sailEnabled={this.props.sailEnabled}
sailUrl={this.props.sailUrl}
Expand All @@ -45,6 +48,18 @@ class TopBar extends PureComponent<TopBarProps> {
</section>
)
}

renderSnapshotOwner() {
if (this.props.snapshotOwner) {
return (
<section className="TopBar-snapshotUrlWrap">
Snapshot shared by {this.props.snapshotOwner}
</section>
)
} else {
return null
}
}
}

export default TopBar
60 changes: 60 additions & 0 deletions web/src/__snapshots__/TopBar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,66 @@ exports[`shows sail url 1`] = `
</div>
`;

exports[`shows snapshot owner 1`] = `
<div
className="TopBar"
>
<nav
className="TabNav"
>
<ul>
<li>
<a
className="tabLink "
href="/r/foo"
onClick={[Function]}
>
Logs
</a>
</li>
<li>
<a
className="tabLink "
href="/r/foo/preview"
onClick={[Function]}
>
Preview
</a>
</li>
<li>
<a
className="tabLink tabLink--errors tabLink--is-selected"
href="/r/foo/alerts"
onClick={[Function]}
>
Alerts
<span
className="tabLink-alertBadge"
>
1
</span>
</a>
</li>
</ul>
</nav>
<section
className="TopBar-tools"
>
<section
className="TopBar-snapshotUrlWrap"
>
Snapshot shared by
foo
</section>
<span
className="sail-url"
>
 
</span>
</section>
</div>
`;

exports[`shows snapshot url 1`] = `
<div
className="TopBar"
Expand Down

0 comments on commit 376480a

Please sign in to comment.