Skip to content

Commit ec3a026

Browse files
authored
Merge pull request #20 from swiftype/updates-after-elastic-co
Updated core files
2 parents 34fc15d + 50d46b5 commit ec3a026

34 files changed

+1183
-503
lines changed

README.md

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# App Search Reference UI
22

33
The Reference UI is a configurable, generic UI meant to work with
4-
any [App Search](https://www.elastic.co/cloud/app-search-service) Engine. It
4+
any [App Search](https://www.elastic.co/cloud/search-lib-service) Engine. It
55
can serve as a simple demo, a functional test for your Engine data,
66
or as a code reference when building out your own App Search
77
UI.
@@ -27,7 +27,7 @@ Run the following commands to start this application:
2727
# Run the `cd` command to change the current directory to the
2828
# location of your downloaded Reference UI. Replace the path
2929
# below with the actual path of your project.
30-
cd ~/Downloads/app-search-reference-ui
30+
cd ~/Downloads/search-lib-reference-ui
3131

3232
# Run this to set everything up
3333
npm install
@@ -57,7 +57,7 @@ The following is a complete list of options available for configuration in [engi
5757
| `urlField` | String | optional | A field with a url to use as a link in results. |
5858
| `urlFieldTemplate` | String | optional | Instead of urlField, you can provide a URL "template" here, which lets you build a URL from other fields. ex: "https://www.example.com/{{id}}". |
5959
| `sortFields` | Array[String] | required | A list of fields that will be used for sort options. |
60-
| `facets` | Array[String] | required | A list of fields that will be available as "facet" filters. Read more about facets within the [App Search documentation](https://swiftype.com/documentation/app-search/guides/facets). |
60+
| `facets` | Array[String] | required | A list of fields that will be available as "facet" filters. Read more about facets within the [App Search documentation](https://swiftype.com/documentation/search-lib/guides/facets). |
6161

6262
### External configuration
6363

@@ -71,7 +71,7 @@ You can follow the previous steps, but then you will need to configure
7171
[engine.json](src/config/engine.json).
7272

7373
To do so, make a copy of [engine.json.example](src/config/engine.json.example),
74-
rename it to `engine.json` and configure with your Engine's specific details.
74+
rename it to `engine.json` and configure it with your Engine's specific details.
7575

7676
```bash
7777
cp src/config/engine.json.example src/config/engine.json
@@ -92,13 +92,13 @@ Logically, the pieces of this application fit together like this:
9292
|
9393
( State manager ) ( Syncs state with URL )
9494
------------------- --------------
95-
| AppSearchDriver | <--> | URLManager |
95+
| SearchDriver | <--> | URLManager |
9696
------------------- --------------
9797
|
9898
| actions / state
9999
v
100100
---------------------
101-
| AppSearchProvider | ( Driver to React glue )
101+
| SearchProvider | ( Driver to React glue )
102102
---------------------
103103
|
104104
| context
@@ -115,9 +115,16 @@ Logically, the pieces of this application fit together like this:
115115

116116
That corresponds to the code and file structure in the following way:
117117

118-
**src/app-search**
118+
**src/search-lib**
119119

120-
This holds the `AppSearchDriver`, the `URLManager`, and `AppSearchProvider`
120+
Everything in this directory for now should be thought of as a separate library.
121+
The goal eventually is to actually separate this out into a library of its own,
122+
so when composing a UI you'd simply need to focus on creating components
123+
from actions and state, and not all of the plumbing that goes into managing
124+
that state. For now though, it's included in this reference as a pattern
125+
that can be followed.
126+
127+
This holds the `SearchDriver`, the `URLManager`, and `SearchProvider`
121128
from the diagram above. This is where all of the core application logic lives.
122129
The interface to all of this logic is a set of "actions" and "state" that are
123130
passed down in a React [Context](https://reactjs.org/docs/context.html). Those
@@ -158,20 +165,13 @@ So, for instance, a `SearchBox` component might be wired up to call the
158165
value. A `Results` component could then simply iterate through the `results`
159166
from state to render search results.
160167

161-
Everything in this directory for now should be thought of as a separate library.
162-
The goal eventually is to actually separate this out into a library of it's own,
163-
so when composing a UI you'd simply need to focus on creating components
164-
from actions and state, and not all of the plumbing that goes into managing
165-
that state. For now though, it's included in this reference as a pattern
166-
that can be followed.
167-
168168
**src/containers**
169169

170170
Components in this UI are separated into "Containers" and "Components". These
171171
can be thought of as "Logic" and "View", respectively.
172172

173173
"Containers" are "connected" to the "context" via a "Higher Order Component"
174-
(HOC) `withAppSearch`. This HOC simply exposes all state and actions as `props`.
174+
(HOC) `withSearch`. This HOC simply exposes all state and actions as `props`.
175175
A consuming Container simply accesses those actions and state, composes
176176
appropriate handlers and data as props and passes them to the appropriate
177177
Component.
@@ -195,18 +195,30 @@ It should be feasible to use this project as a starting point for your
195195
own implementation. Here are a few places to look to make changes:
196196

197197
- The styles for the entire project can be found in [src/styles](src/styles).
198-
Simple style tweaks changes can be made here, or you could replace these styles
199-
with your own.
198+
Simple style tweaks can be made here, or you could replace these styles
199+
entirely with your own.
200200
- [src/components](src/components) contains the view templates for
201201
components. Structural HTML changes can be made here.
202202
- If you find that you have different data or behavior requirements for
203203
existing components, you can customize the component Containers in
204204
[src/containers](src/containers).
205205
- If you find you have requirements that none of the existing components
206206
satisfy, you could create an entirely new component and/or container. Use the
207-
`withAppSearch` HOC in order to access any action or state.
207+
[withSearch.js](src/search-lib/withSearch.js) HOC in order to access any action or state.
208+
- The SearchDriver can be configured directly in [App.js](src/App.js) to do things like:
209+
210+
- Optimize your API calls
211+
- Add additional facets and customize facet behavior
212+
- Disable URL State management
213+
214+
A full list of configuration options can be found in [SearchDriver.js](src/search-lib/SearchDriver.js)
215+
216+
- Eject from 'configuration'. You may choose to to delete the entire [src/config](src/config) directory, which holds the configuration logic that makes this a
217+
generic UI. If you're using this as your own, production application, you likely
218+
won't need this.
219+
208220
- Lastly, if you find there is a core action or state missing, you may
209-
consider updating the core logic in [src/app-search](src/app-search).
221+
consider updating the core logic in [src/search-lib](src/search-lib).
210222

211223
Lastly, we accept PRs! If you make a customization that you think would benefit
212224
others, please feel free to contribute it back.

package-lock.json

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
"license": "MIT",
55
"private": true,
66
"dependencies": {
7+
"date-fns": "^1.29.0",
78
"history": "^4.7.2",
89
"prop-types": "^15.6.2",
910
"qs": "^6.5.2",
1011
"rc-pagination": "^1.16.5",
1112
"react": "^16.4.1",
1213
"react-dom": "^16.4.1",
1314
"react-scripts": "1.1.4",
14-
"swiftype-app-search-javascript": "^1.4.0"
15+
"swiftype-app-search-javascript": "^2.0.0"
1516
},
1617
"scripts": {
1718
"build-css": "node-sass-chokidar src/ -o src/",

src/App.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
import React, { Component } from "react";
22

33
import { Body, Header } from "./components";
4-
import AppSearchProvider from "./app-search/AppSearchProvider";
5-
import AppSearchDriver from "./app-search/AppSearchDriver";
64
import {
5+
SearchProvider,
6+
SearchDriver,
7+
AppSearchAPIConnector
8+
} from "./search-lib";
9+
10+
import {
11+
buildFacetConfigFromConfig,
712
buildSearchOptionsFromConfig,
813
getConfig
914
} from "./config/config-helper";
1015

1116
function createDriver() {
1217
const { hostIdentifier, searchKey, endpointBase, engineName } = getConfig();
13-
return new AppSearchDriver({
14-
hostIdentifier,
15-
searchKey,
16-
endpointBase,
17-
engineName,
18+
return new SearchDriver({
19+
apiConnector: new AppSearchAPIConnector({
20+
hostIdentifier,
21+
searchKey,
22+
endpointBase,
23+
engineName
24+
}),
25+
facetConfig: buildFacetConfigFromConfig(),
1826
searchOptions: buildSearchOptionsFromConfig()
1927
});
2028
}
@@ -33,7 +41,7 @@ class App extends Component {
3341
}
3442

3543
return (
36-
<AppSearchProvider driver={createDriver()}>
44+
<SearchProvider driver={createDriver()}>
3745
{({ searchTerm, results }) => (
3846
<div
3947
className={`reference-ui${
@@ -44,7 +52,7 @@ class App extends Component {
4452
<Body />
4553
</div>
4654
)}
47-
</AppSearchProvider>
55+
</SearchProvider>
4856
);
4957
}
5058
}

src/app-search/AppSearchConsumer.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/app-search/AppSearchContext.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)