diff --git a/app/javascript/components/ProductsDashboardPage.tsx b/app/javascript/components/ProductsDashboardPage.tsx index eb8158b35a..09356a655d 100644 --- a/app/javascript/components/ProductsDashboardPage.tsx +++ b/app/javascript/components/ProductsDashboardPage.tsx @@ -36,6 +36,7 @@ export const ProductsDashboardPage = ({ }: ProductsDashboardPageProps) => { const [enableArchiveTab, setEnableArchiveTab] = React.useState(archivedProductsCount > 0); const [query, setQuery] = React.useState(""); + const hadInitialItems = React.useRef(products.length > 0 || memberships.length > 0); return ( - {products.length > 0 ? : null} + {hadInitialItems.current || !!query ? ( + + ) : null} New product @@ -52,11 +55,11 @@ export const ProductsDashboardPage = ({ } >
- {memberships.length === 0 && products.length === 0 ? ( + {memberships.length === 0 && products.length === 0 && !hadInitialItems.current ? ( -

We’ve never met an idea we didn’t like.

-

Your first product doesn’t need to be perfect. Just put it out there, and see if it sticks.

+

We've never met an idea we didn't like.

+

Your first product doesn't need to be perfect. Just put it out there, and see if it sticks.

New product diff --git a/app/javascript/components/ProductsPage.tsx b/app/javascript/components/ProductsPage.tsx index 5633549d4d..805db16ba0 100644 --- a/app/javascript/components/ProductsPage.tsx +++ b/app/javascript/components/ProductsPage.tsx @@ -28,30 +28,35 @@ const ProductsPage = ({ query: string | null; setEnableArchiveTab?: (enable: boolean) => void; type?: Tab; -}) => ( -
- {memberships.length > 0 ? ( - - ) : null} +}) => { + const hadInitialMemberships = React.useRef(memberships.length > 0); + const hadInitialProducts = React.useRef(products.length > 0); - {products.length > 0 ? ( - - ) : null} -
-); + return ( +
+ {hadInitialMemberships.current ? ( + + ) : null} + + {hadInitialProducts.current ? ( + + ) : null} +
+ ); +}; export default ProductsPage; diff --git a/spec/requests/products/index_spec.rb b/spec/requests/products/index_spec.rb index 466267d014..38d45f8ce4 100644 --- a/spec/requests/products/index_spec.rb +++ b/spec/requests/products/index_spec.rb @@ -577,6 +577,25 @@ def find_product_row(product, hover: false) end expect(page).to have_alert(text: "Product deleted!") end + + it "keeps the search bar visible when no products match" do + product = create(:product, user: seller, name: "Digital Art Pack") + visit(products_path) + + select_disclosure "Toggle Search" do + expect(page).to have_field("Search products") + end + fill_in "Search products", with: "nonexistentproduct" + wait_for_ajax + + expect(page).to have_field("Search products") + expect(page).not_to have_content("Digital Art Pack") + + fill_in "Search products", with: "" + wait_for_ajax + + expect(page).to have_content("Digital Art Pack") + end end describe "dashboard stats" do