-
Notifications
You must be signed in to change notification settings - Fork 583
/
PagesAutocomplete.js
57 lines (53 loc) · 1.55 KB
/
PagesAutocomplete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// @flow
import * as React from "react";
import { AutoComplete } from "@webiny/ui/AutoComplete";
import gql from "graphql-tag";
import { get } from "lodash";
import { Query } from "react-apollo";
import { useAutocomplete } from "@webiny/app/hooks/useAutocomplete";
// We utilize the same "listPages" GraphQL field.
const GET_PAGE = gql`
query getPublishedPage($parent: String) {
pageBuilder {
page: getPublishedPage(parent: $parent) {
data {
parent
published
title
}
}
}
}
`;
const LIST_PUBLISHED_PAGES = gql`
query listPublishedPages($search: String) {
pageBuilder {
pages: listPublishedPages(search: $search) {
data {
parent
published
title
}
}
}
}
`;
export function PagesAutocomplete(props) {
const autoComplete = useAutocomplete(LIST_PUBLISHED_PAGES);
return (
<Query skip={!props.value} variables={{ parent: props.value }} query={GET_PAGE}>
{({ data }) => {
const value = get(data, "pageBuilder.page.data");
return (
<AutoComplete
{...props}
{...autoComplete}
valueProp={"parent"}
textProp={"title"}
value={value}
/>
);
}}
</Query>
);
}