Skip to content

Add prod example to sandbox #1138

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 2 additions & 10 deletions examples/sandbox/.codesandbox/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,19 @@
},
{
"name": "Build App",
"command": "yarn build"
"command": "VITE_IS_SANDBOX=true yarn build"
}
],

// These tasks can be run from CodeSandbox. Running one will open a log in the app.
"tasks": {
"start": {
"name": "start",
"command": "yarn start",
"command": "VITE_IS_SANDBOX=true yarn start & node src/pages/elasticsearch-production-ready/server/index.js",
"runAtStart": true,
"preview": {
"port": 4173
}
},
"start-api-server": {
"name": "Start API Server",
"command": "node src/pages/elasticsearch-production-ready/server/index.js",
"runAtStart": true,
"preview": {
"port": 3001
}
}
}
}
1 change: 1 addition & 0 deletions examples/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.13.0",
"sass-embedded": "^1.86.2",
"typescript": "^5.8.2",
"vite": "^6.0.3"
}
Expand Down
7 changes: 3 additions & 4 deletions examples/sandbox/src/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Router() {
const isHomePage = location.pathname === "/";

return (
<div className={`${isHomePage ? "App" : "text-black bg-white"}`}>
<div className={`${isHomePage ? "App" : "ExampleApp mx-auto"}`}>
<Switch>
<Route exact path="/" component={Root} />

Expand All @@ -29,12 +29,11 @@ export default function Router() {
path="/elasticsearch-basic"
component={ElasticsearchBasic}
/>
{/* TODO: Add back in when we have a production-ready connector */}
{/* <Route
<Route
exact
path="/elasticsearch-production-ready"
component={ElasticsearchProductionReady}
/> */}
/>
<Route exact path="/site-search" component={SiteSearch} />
<Route exact path="/engines" component={Engines} />

Expand Down
4 changes: 2 additions & 2 deletions examples/sandbox/src/pages/ecommerce/Category.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const BrowseHeader = ({ category }) => {
export default function CategoryPage(props) {
const category = props?.match?.params.category;
return (
<>
<div className="ecommerce-container">
<Navigation />
<BrowseHeader category={category} />
<SearchProvider config={categoryPageconfig(category)}>
Expand Down Expand Up @@ -114,6 +114,6 @@ export default function CategoryPage(props) {
</ErrorBoundary>
</div>
</SearchProvider>
</>
</div>
);
}
4 changes: 2 additions & 2 deletions examples/sandbox/src/pages/ecommerce/ListingPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const categoryItems = {

export default () => {
return (
<>
<div className="ecommerce-container">
<Navigation />
<div className="max-w-screen-xl mx-auto py-12 px-4 sm:px-6 lg:px-8 grid md:grid-cols-4 gap-4 grid-cols-2">
{Object.keys(categoryItems).map((category) => (
Expand All @@ -86,6 +86,6 @@ export default () => {
</div>
))}
</div>
</>
</div>
);
};
4 changes: 2 additions & 2 deletions examples/sandbox/src/pages/ecommerce/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ const Search = () => {
};
export default function App() {
return (
<>
<div className="ecommerce-container">
<Navigation />
<SearchProvider config={config}>
<Search />
</SearchProvider>
</>
</div>
);
}
6 changes: 3 additions & 3 deletions examples/sandbox/src/pages/ecommerce/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import * as React from "react";
import Navigation from "./components/Navigation";
import ProductCarousel from "./components/ProductCarousel";
import "./styles.css";
import "./styles.scss";

export default function Ecommerce() {
return (
<>
<div className="ecommerce-container">
<Navigation />
<div className="max-w-screen-xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
<ProductCarousel
Expand All @@ -19,6 +19,6 @@ export default function Ecommerce() {
filters={[{ field: "parent_category", values: ["Monitors"] }]}
/>
</div>
</>
</div>
);
}
29 changes: 0 additions & 29 deletions examples/sandbox/src/pages/ecommerce/styles.css

This file was deleted.

31 changes: 31 additions & 0 deletions examples/sandbox/src/pages/ecommerce/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@tailwind base;
@tailwind components;
@tailwind utilities;

.ecommerce-container {
.sui-layout-header.sui-layout-header {
padding: 0;
}

.sui-layout-main-header {
margin-bottom: 1rem;
}

.sui-layout-header {
border: none;
}

.navigation {
position: sticky;
top: 0;
z-index: 40;
background-color: #000;
transition-property: all;
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition-duration: 0.15s;
}

.sui-search-box__suggestion-list {
width: 200px;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from "react";
import "@elastic/eui/dist/eui_theme_light.css";

import { ApiProxyConnector } from "@elastic/search-ui-elasticsearch-connector";
import moment from "moment";

import { SearchProvider } from "@elastic/react-search-ui";
import "@elastic/react-search-ui-views/lib/styles/styles.css";
import { ElasticsearchProdReady } from "./elasticsearchProdReady";
import { ElasticsearchProdReady } from "./ElasticsearchProdReady";

const isSandbox = import.meta.env.VITE_IS_SANDBOX === "true";
const apiHost = isSandbox
? window.location.origin.replace("4173", "3001")
: "http://localhost:3001";

const connector = new ApiProxyConnector({
basePath: "http://localhost:3001/api"
basePath: `${apiHost}/api`
});

const config = {
Expand Down
13 changes: 6 additions & 7 deletions examples/sandbox/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import { useMemo } from "react";
export default function SearchUISandbox() {
const apiCards = useMemo(
() => [
// TODO: Add back in when we have a production-ready connector
// {
// title: "Elasticsearch Connector",
// description: "Production-ready, Proxy connector",
// href: "/elasticsearch-production-ready",
// recommended: true
// },
{
title: "Elasticsearch Connector",
description: "Production-ready, Proxy connector",
href: "/elasticsearch-production-ready",
recommended: true
},
{
title: "Elasticsearch Connector (Basic)",
description: "Browser-only implementation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function Header() {
fontSize: "40px"
}}
>
🚀 Acme Inc.
🌲 National Parks
</div>
<SearchProvider
config={{
Expand Down
20 changes: 18 additions & 2 deletions examples/sandbox/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,35 @@
/* Light theme variables */
--background: #ffffff;
--foreground: #213547;
--scroll-bar-color: #000;
--scroll-bar-background: #fff;
}

/* Dark theme variables */
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
--background: #242424;
--foreground: rgba(255, 255, 255, 0.87);
--foreground: #ffffffde;
--scroll-bar-color: #ffffff40;
--scroll-bar-background: #0000;
--text-secondary: #ffffff40;
}
}

body {
place-items: center;
font-family: var(--font-family);
background-color: var(--background);
color: var(--foreground);
scrollbar-color: var(--scroll-bar-color) var(--scroll-bar-background);
}

.ExampleApp {
background-color: #ffffff;
color: #213547;
color-scheme: auto;
}

.sui-layout-main-header {
margin-bottom: 1rem;
}
6 changes: 1 addition & 5 deletions packages/react-search-ui-views/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type {
FacetValue,
FieldValue,
FilterType,
} from "@elastic/search-ui";
import type { FacetValue, FieldValue, FilterType } from "@elastic/search-ui";

export interface BaseContainerProps {
children?: React.ReactNode;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-search-ui/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { useSearch } from "./use_search";
export { useSearch } from "./useSearch";
Loading