Skip to content

Commit

Permalink
web: styling and accessibility of new starred resources view (#6074)
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks authored Mar 13, 2023
1 parent fea33f1 commit 448b120
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 19 deletions.
3 changes: 3 additions & 0 deletions web/src/OverviewResourcePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ export default function OverviewResourcePane(props: OverviewResourcePaneProps) {
let name = nav.invalidResource || nav.selectedResource || ""
let r: UIResource | undefined
let all = name === "" || name === ResourceName.all
let starred = name === ResourceName.starred
if (!all) {
r = resources.find((r) => r.metadata?.name === name)
}
let selectedTab = ""
if (all) {
selectedTab = ResourceName.all
} else if (starred) {
selectedTab = ResourceName.starred
} else if (r?.metadata?.name) {
selectedTab = r.metadata.name
}
Expand Down
10 changes: 8 additions & 2 deletions web/src/SidebarResources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ import SidebarItemView, {
import SidebarKeyboardShortcuts from "./SidebarKeyboardShortcuts"
import { AnimDuration, Color, Font, FontSize, SizeUnit } from "./style-helpers"
import { startBuild } from "./trigger"
import { ResourceStatus, ResourceView } from "./types"
import { ResourceName, ResourceStatus, ResourceView } from "./types"
import { useStarredResources } from "./StarredResourcesContext"

export type SidebarProps = {
items: SidebarItem[]
Expand Down Expand Up @@ -203,7 +204,12 @@ function StarredResourcesLink(props: {
pathBuilder: PathBuilder
selected: string
}) {
const isSelectedClass = props.selected === "" ? "isSelected" : ""
const starContext = useStarredResources()
if (!starContext.starredResources.length) {
return null
}
const isSelectedClass =
props.selected === ResourceName.starred ? "isSelected" : ""
return (
<BuiltinResourceLinkRoot
className={isSelectedClass}
Expand Down
4 changes: 3 additions & 1 deletion web/src/StarredResourceBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe("StarredResourceBar", () => {
})

it("renders starred logs link", () => {
expect(screen.getByText("Logs")).toBeInTheDocument()
expect(
screen.getByRole("button", { name: "All Starred" })
).toBeInTheDocument()
})

it("calls unstar", () => {
Expand Down
50 changes: 34 additions & 16 deletions web/src/StarredResourceBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
SizeUnit,
} from "./style-helpers"
import TiltTooltip from "./Tooltip"
import { ResourceStatus } from "./types"
import { ResourceName, ResourceStatus } from "./types"

export const StarredResourceLabel = styled.div`
max-width: ${SizeUnit(4.5)};
Expand Down Expand Up @@ -156,6 +156,9 @@ const StarredResourceRoot = styled.div`
${ResourceButton} {
padding-left: ${SizeUnit(0.25)};
}
&.isStarredAggregate ${ResourceButton} {
padding-right: ${SizeUnit(0.25)};
}
`
const StarredResourceBarRoot = styled.section`
padding-left: ${SizeUnit(0.5)};
Expand Down Expand Up @@ -229,26 +232,41 @@ export function StarredResource(props: {
)
}

export default function StarredResourceBar(props: StarredResourceBarProps) {
function StarredResourceAggregate(props: { isSelected: boolean }) {
const pb = usePathBuilder()
const href = pb.encpath`/r/${ResourceName.starred}/overview`
const history = useHistory()
let classes = [
ClassNameFromResourceStatus(ResourceStatus.Healthy),
"isStarredAggregate",
]
if (props.isSelected) {
classes.push("isSelected")
}

return (
<TiltTooltip title={"View starred resource logs"}>
<StarredResourceRoot className={classes.join(" ")}>
<ResourceButton
onClick={() => {
history.push(href)
}}
analyticsName="ui.web.starredResourcesAggregatedLogs"
>
<StarredResourceLabel>All Starred</StarredResourceLabel>
</ResourceButton>
</StarredResourceRoot>
</TiltTooltip>
)
}

export default function StarredResourceBar(props: StarredResourceBarProps) {
return (
<StarredResourceBarRoot aria-label="Starred resources">
{props.resources.length ? (
<TiltTooltip title={"View starred resource logs"}>
<StarredResourceRoot className={""}>
<StarButton
name="starredLogs"
onClick={() => {
history.push(pb.encpath`/r/(starred)/overview`)
}}
analyticsName="ui.web.starredResourcesAggregatedLogs"
>
<StarIcon style={{ marginRight: 10 }} />
Logs
</StarButton>
</StarredResourceRoot>
</TiltTooltip>
<StarredResourceAggregate
isSelected={ResourceName.starred === props.selectedResource}
/>
) : null}
{props.resources.map((r) => (
<StarredResource
Expand Down

0 comments on commit 448b120

Please sign in to comment.