@uncinc/uncinc-react-kitchen-sink 2.1.12 → 2.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo } from 'react';
|
|
1
|
+
import React, { useMemo, useState, useEffect } from 'react';
|
|
2
2
|
import { gql, useQuery } from '@apollo/client';
|
|
3
3
|
import { useSearchkitVariables } from '@searchkit/client';
|
|
4
4
|
import SearchPage from '../SearchPage';
|
|
@@ -21,13 +21,21 @@ function Query({
|
|
|
21
21
|
loading
|
|
22
22
|
} = useQuery(graphQuery, {
|
|
23
23
|
variables
|
|
24
|
-
});
|
|
24
|
+
}); // In between searches, Searchkit will empty it's results, resulting
|
|
25
|
+
// in a re-render with an empty screen. Use a local state to prevent this.
|
|
26
|
+
|
|
27
|
+
const [dataLoaded, setDataLoaded] = useState(null);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (data) {
|
|
30
|
+
setDataLoaded(data);
|
|
31
|
+
}
|
|
32
|
+
}, [data]);
|
|
25
33
|
|
|
26
34
|
if (!useRouting) {
|
|
27
|
-
return /*#__PURE__*/React.createElement("div", null, children(
|
|
35
|
+
return /*#__PURE__*/React.createElement("div", null, children(dataLoaded, loading));
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
return /*#__PURE__*/React.createElement(SearchPage, null, children(
|
|
38
|
+
return /*#__PURE__*/React.createElement(SearchPage, null, children(dataLoaded, loading));
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
export default Query;
|
|
@@ -26,7 +26,8 @@ const SearchField = ({
|
|
|
26
26
|
initialValues: {
|
|
27
27
|
query: query
|
|
28
28
|
},
|
|
29
|
-
displayRequiredIndicator: "required"
|
|
29
|
+
displayRequiredIndicator: "required",
|
|
30
|
+
enableReinitialize: true
|
|
30
31
|
}, /*#__PURE__*/React.createElement(TextField, {
|
|
31
32
|
fieldName: "query",
|
|
32
33
|
title: "Search",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect, useState, useMemo } from 'react';
|
|
2
2
|
import Query from './Query';
|
|
3
3
|
import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client';
|
|
4
4
|
import { SearchkitProvider, SearchkitClient } from '@searchkit/client';
|
|
@@ -24,19 +24,39 @@ const defaultChildren = (data, loading) => /*#__PURE__*/React.createElement(Reac
|
|
|
24
24
|
const SearchKit = ({
|
|
25
25
|
query,
|
|
26
26
|
uri,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
pageSize = 10,
|
|
28
|
+
useRouting = true,
|
|
29
|
+
defaultFilters = {},
|
|
30
|
+
defaultQuery = '',
|
|
31
|
+
children
|
|
30
32
|
}) => {
|
|
31
|
-
const client =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const client = useMemo(() => {
|
|
34
|
+
return new ApolloClient({
|
|
35
|
+
uri: uri,
|
|
36
|
+
cache: new InMemoryCache()
|
|
37
|
+
});
|
|
38
|
+
}, [uri]);
|
|
39
|
+
const skClient = useMemo(() => {
|
|
40
|
+
const skClient = new SearchkitClient();
|
|
41
|
+
|
|
42
|
+
if (!useRouting) {
|
|
43
|
+
skClient.updateBaseSearchState({
|
|
44
|
+
filters: defaultFilters,
|
|
45
|
+
query: defaultQuery,
|
|
46
|
+
page: {
|
|
47
|
+
size: pageSize,
|
|
48
|
+
from: 0
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return skClient;
|
|
54
|
+
}, [useRouting, defaultFilters, defaultQuery, pageSize]);
|
|
36
55
|
return /*#__PURE__*/React.createElement(ApolloProvider, {
|
|
37
56
|
client: client
|
|
38
57
|
}, /*#__PURE__*/React.createElement(SearchkitProvider, {
|
|
39
|
-
client: skClient
|
|
58
|
+
client: skClient,
|
|
59
|
+
key: `${defaultQuery}-${defaultFilters.toString()}`
|
|
40
60
|
}, /*#__PURE__*/React.createElement(Query, {
|
|
41
61
|
query: query,
|
|
42
62
|
useRouting: useRouting
|
|
@@ -45,6 +65,10 @@ const SearchKit = ({
|
|
|
45
65
|
|
|
46
66
|
SearchKit.propTypes = {
|
|
47
67
|
queryString: PropTypes.string,
|
|
48
|
-
uri: PropTypes.string
|
|
68
|
+
uri: PropTypes.string,
|
|
69
|
+
pageSize: PropTypes.number,
|
|
70
|
+
useRouting: PropTypes.bool,
|
|
71
|
+
defaultFilters: PropTypes.object,
|
|
72
|
+
defaultQuery: PropTypes.string
|
|
49
73
|
};
|
|
50
74
|
export default SearchKit;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
2
|
import { useSearchkit } from '@searchkit/client';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import SearchKit from '.';
|
|
@@ -46,7 +46,7 @@ const query = `
|
|
|
46
46
|
}
|
|
47
47
|
query
|
|
48
48
|
}
|
|
49
|
-
hits(page: $page
|
|
49
|
+
hits(page: $page) {
|
|
50
50
|
sortedBy
|
|
51
51
|
page {
|
|
52
52
|
total
|
|
@@ -178,4 +178,41 @@ export const CustomFacets = () => {
|
|
|
178
178
|
}), /*#__PURE__*/React.createElement(SearchPagination, {
|
|
179
179
|
data: data
|
|
180
180
|
})));
|
|
181
|
+
};
|
|
182
|
+
export const Test = () => {
|
|
183
|
+
const [q, setQ] = useState(null);
|
|
184
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("input", {
|
|
185
|
+
onChange: e => setQ(e.target.value),
|
|
186
|
+
value: q
|
|
187
|
+
}), /*#__PURE__*/React.createElement(SearchKit, {
|
|
188
|
+
uri: "http://localhost:4000/api/graphql",
|
|
189
|
+
query: query,
|
|
190
|
+
useRouting: false,
|
|
191
|
+
filters: [{
|
|
192
|
+
identifier: 'type',
|
|
193
|
+
value: 'article'
|
|
194
|
+
}],
|
|
195
|
+
searchQuery: q
|
|
196
|
+
}, (data, loading) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchResults, {
|
|
197
|
+
data: data,
|
|
198
|
+
renderItem: SearchItem,
|
|
199
|
+
renderHeader: SearchHeader
|
|
200
|
+
}), /*#__PURE__*/React.createElement(SearchPagination, {
|
|
201
|
+
data: data
|
|
202
|
+
}))), /*#__PURE__*/React.createElement(SearchKit, {
|
|
203
|
+
uri: "http://localhost:4000/api/graphql",
|
|
204
|
+
query: query,
|
|
205
|
+
useRouting: false,
|
|
206
|
+
filters: [{
|
|
207
|
+
identifier: 'type',
|
|
208
|
+
value: 'landing_page'
|
|
209
|
+
}],
|
|
210
|
+
searchQuery: q
|
|
211
|
+
}, (data, loading) => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchResults, {
|
|
212
|
+
data: data,
|
|
213
|
+
renderItem: SearchItem,
|
|
214
|
+
renderHeader: SearchHeader
|
|
215
|
+
}), /*#__PURE__*/React.createElement(SearchPagination, {
|
|
216
|
+
data: data
|
|
217
|
+
}))));
|
|
181
218
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uncinc/uncinc-react-kitchen-sink",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.13",
|
|
4
4
|
"description": "Default React components that are easily extended.",
|
|
5
5
|
"author": "uncinc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,30 +35,13 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@apollo/client": "^3.4.16",
|
|
38
|
-
"@babel/cli": "^7.0.0-beta.44",
|
|
39
|
-
"@babel/helper-define-map": "^7.14.5",
|
|
40
|
-
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
41
|
-
"@babel/runtime": "^7.9.6",
|
|
42
38
|
"@elastic/datemath": "^5.0.3",
|
|
43
39
|
"@elastic/eui": "^40.0.0",
|
|
44
40
|
"@loadable/component": "^5.15.0",
|
|
45
41
|
"@searchkit/client": "^3.0.0-canary.45",
|
|
46
42
|
"@searchkit/elastic-ui": "^3.0.0-canary.45",
|
|
47
|
-
"@storybook/addon-actions": "^6.2.8",
|
|
48
|
-
"@storybook/addon-info": "^5.3.21",
|
|
49
|
-
"@storybook/addon-links": "^6.2.8",
|
|
50
|
-
"@storybook/addons": "^6.2.8",
|
|
51
|
-
"@storybook/react": "^6.2.8",
|
|
52
|
-
"@storybook/theming": "^6.2.8",
|
|
53
|
-
"@testing-library/jest-dom": "^4.2.4",
|
|
54
|
-
"@testing-library/react": "^9.3.2",
|
|
55
|
-
"@testing-library/user-event": "^7.1.2",
|
|
56
43
|
"apollo-server-micro": "^3.4.0",
|
|
57
44
|
"bootstrap": "^4.3.1",
|
|
58
|
-
"chai": "^4.2.0",
|
|
59
|
-
"cross-env": "^7.0.2",
|
|
60
|
-
"enzyme": "^3.11.0",
|
|
61
|
-
"enzyme-adapter-react-16": "^1.15.2",
|
|
62
45
|
"fork-ts-checker-webpack-plugin-alt": "0.4.14",
|
|
63
46
|
"formik": "^2.2.6",
|
|
64
47
|
"graphql": "^15.7.0",
|
|
@@ -84,11 +67,9 @@
|
|
|
84
67
|
"react-redux": "^7.2.4",
|
|
85
68
|
"react-router": "5.2.0",
|
|
86
69
|
"react-router-dom": "5.2.0",
|
|
87
|
-
"react-scripts": "3.4.1",
|
|
88
70
|
"react-select": "^3.1.0",
|
|
89
71
|
"react-share": "^4.3.1",
|
|
90
72
|
"react-slick": "^0.27.14",
|
|
91
|
-
"react-test-renderer": "^16.13.1",
|
|
92
73
|
"redux": "^4.0.5",
|
|
93
74
|
"sass-loader": "^8.0.2",
|
|
94
75
|
"slick-carousel": "^1.8.1"
|
|
@@ -115,7 +96,6 @@
|
|
|
115
96
|
"react-test-renderer": "^16.13.1",
|
|
116
97
|
"sinon": "^9.0.2",
|
|
117
98
|
"sinon-chai": "^3.5.0",
|
|
118
|
-
"slick-carousel": "^1.8.1",
|
|
119
99
|
"storybook-addon-export-stories": "^1.0.0"
|
|
120
100
|
},
|
|
121
101
|
"eslintConfig": {
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ApolloServer, gql } from 'apollo-server-micro';
|
|
2
|
-
export const config = {
|
|
3
|
-
api: {
|
|
4
|
-
bodyParser: false
|
|
5
|
-
}
|
|
6
|
-
};
|
|
7
|
-
const typeDefs = [gql`
|
|
8
|
-
type Query {
|
|
9
|
-
root: String
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type Mutation {
|
|
13
|
-
root: String
|
|
14
|
-
}
|
|
15
|
-
`];
|
|
16
|
-
const server = new ApolloServer({
|
|
17
|
-
typeDefs,
|
|
18
|
-
resolvers: {},
|
|
19
|
-
introspection: true,
|
|
20
|
-
playground: true,
|
|
21
|
-
context: {}
|
|
22
|
-
});
|
|
23
|
-
export default server.createHandler({
|
|
24
|
-
path: '/api/graphql'
|
|
25
|
-
});
|