Skip to content

Commit

Permalink
web: let users re-check resources filter when there are no tests (#4186)
Browse files Browse the repository at this point in the history
  • Loading branch information
landism committed Feb 10, 2021
1 parent b7aa617 commit b54ef19
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
45 changes: 25 additions & 20 deletions web/src/OverviewSidebarOptions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MemoryRouter } from "react-router"
import { accessorsForTesting, tiltfileKeyContext } from "./LocalStorage"
import {
TestsWithErrors,
TwoResources,
TwoResourcesTwoTests,
} from "./OverviewResourceSidebar.stories"
import {
Expand All @@ -12,15 +13,19 @@ import {
OverviewSidebarOptions,
} from "./OverviewSidebarOptions"
import PathBuilder from "./PathBuilder"
import SidebarItem from "./SidebarItem"
import SidebarItemView from "./SidebarItemView"
import { SidebarPinContextProvider } from "./SidebarPin"
import SidebarResources, { SidebarListSection } from "./SidebarResources"
import { oneResource, tiltfileResource } from "./testdata"
import { ResourceView } from "./types"
import SidebarResources, {
defaultOptions,
SidebarListSection,
} from "./SidebarResources"
import { SidebarOptions } from "./types"

let pathBuilder = PathBuilder.forTesting("localhost", "/")

const sidebarOptionsAccessor = accessorsForTesting<SidebarOptions>(
"sidebar_options"
)
const pinnedResourcesAccessor = accessorsForTesting<string[]>(
"pinned-resources"
)
Expand Down Expand Up @@ -118,28 +123,28 @@ describe("overview sidebar options", () => {
})

it("doesn't show filter options if no tests present", () => {
let items = [tiltfileResource(), oneResource()].map(
(r) => new SidebarItem(r)
)
const root = mount(TwoResources())

let sidebar = root.find(SidebarResources)
expect(sidebar).toHaveLength(1)

let filters = sidebar.find(FilterOptionList)
expect(filters).toHaveLength(0)
})

it("shows filter options when no tests are present if filter options are non-default", () => {
sidebarOptionsAccessor.set({ ...defaultOptions, showResources: false })
const root = mount(
<MemoryRouter>
<tiltfileKeyContext.Provider value="test">
<SidebarPinContextProvider>
<SidebarResources
items={items}
selected={""}
resourceView={ResourceView.Log}
pathBuilder={pathBuilder}
/>
</SidebarPinContextProvider>
</tiltfileKeyContext.Provider>
</MemoryRouter>
<tiltfileKeyContext.Provider value="test">
{TwoResources()}
</tiltfileKeyContext.Provider>
)

let sidebar = root.find(SidebarResources)
expect(sidebar).toHaveLength(1)

let filters = sidebar.find(FilterOptionList)
expect(filters).toHaveLength(0)
expect(filters).toHaveLength(1)
})

it("still displays pinned tests when tests hidden", () => {
Expand Down
12 changes: 9 additions & 3 deletions web/src/SidebarResources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type SidebarProps = {
pathBuilder: PathBuilder
}

let defaultOptions: SidebarOptions = {
export const defaultOptions: SidebarOptions = {
showResources: true,
showTests: true,
alertsOnTop: false,
Expand Down Expand Up @@ -115,7 +115,13 @@ export class SidebarResources extends React.Component<SidebarProps> {
.map((i) => i.buildAlertCount + i.runtimeAlertCount)
.reduce((sum, current) => sum + current, 0)

let testsPresent = this.props.items.some((item) => item.isTest)
// generally, only show filters if there are tests (otherwise the filters are just noise)
// however, also show filters if the filter options are non-default
// (e.g., in case there were previously tests and the user deselected resources)
const showFilters =
this.props.items.some((item) => item.isTest) ||
options.showResources !== defaultOptions.showResources ||
options.showTests !== defaultOptions.showTests

// TODO: what do we do when we filter out the selected item? Pinned item(s)?
// and what effect does this have on keyboard shortcuts? :(
Expand Down Expand Up @@ -157,7 +163,7 @@ export class SidebarResources extends React.Component<SidebarProps> {
</SidebarListSection>
<PinnedItems {...this.props} />
<OverviewSidebarOptions
showFilters={testsPresent}
showFilters={showFilters}
options={options}
setOptions={setOptions}
/>
Expand Down

0 comments on commit b54ef19

Please sign in to comment.