Skip to content

Commit

Permalink
Fixed pages auto-complete and related GQL fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Mar 1, 2019
1 parent 28a6cb9 commit 9d48741
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 81 deletions.
1 change: 1 addition & 0 deletions packages/demo-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"webiny-plugins": "0.0.0"
},
"devDependencies": {
"inquirer": "^6.2.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/plugin-external-helpers": "^7.0.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/webiny-api-cms/src/plugins/graphql/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
resolveGet,
resolveList
} from "webiny-api/graphql";
import { Response } from "webiny-api/graphql/responses";
import UserType from "webiny-api-security/plugins/graphql/User";
import createRevisionFrom from "./pageResolvers/createRevisionFrom";
import listPages from "./pageResolvers/listPages";
Expand Down Expand Up @@ -138,7 +137,7 @@ export default {
sort: String
): PageResponse
getPublishedPage(id: String, url: String): PageResponse
getPublishedPage(id: String, url: String, parent: String): PageResponse
# Returns page set as home page (managed in CMS settings).
getHomePage: PageResponse
Expand All @@ -158,7 +157,9 @@ export default {
): PageListResponse
listPublishedPages(
search: String
category: String
parent: String
tags: [String]
tagsRule: TagsRule
sort: PageSortInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import get from "lodash/get";
export const listPublishedPages = async ({ args, Page, Category }: Object) => {
const {
page = 1,
search,
perPage = 10,
category = null,
parent = null,
Expand Down Expand Up @@ -41,6 +42,10 @@ export const listPublishedPages = async ({ args, Page, Category }: Object) => {
}
}

if (search) {
baseFilters.push({ title: { $regex: `.*${search}.*`, $options: "i" } });
}

if (category) {
if (Category.isId(category)) {
baseFilters.push({ category });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { Query } from "react-apollo";

// We utilize the same "listPages" GraphQL field.
const getPage = gql`
query listPages($parent: String) {
query getPublishedPage($parent: String) {
cms {
pages: listPages(parent: $parent) {
page: getPublishedPage(parent: $parent) {
data {
parent
published
Expand All @@ -23,9 +23,9 @@ const getPage = gql`
`;

const listPages = gql`
query listPages($search: String) {
query listPublishedPages($search: String) {
cms {
pages: listPages(search: $search) {
pages: listPublishedPages(search: $search) {
data {
parent
published
Expand All @@ -39,15 +39,9 @@ const listPages = gql`
const PagesAutoComplete = props => (
<Query skip={!props.value} variables={{ parent: props.value }} query={getPage}>
{({ data }) => {
const value = get(data, "cms.pages.data.0");
const value = get(data, "cms.page.data");
return (
<AutoComplete
{...props}
description={value && !value.published && "Warning: page is not published."}
valueProp={"parent"}
textProp={"title"}
value={value}
/>
<AutoComplete {...props} valueProp={"parent"} textProp={"title"} value={value} />
);
}}
</Query>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Input } from "webiny-ui/Input";
import { Typography } from "webiny-ui/Typography";
import { Grid, Cell } from "webiny-ui/Grid";
import { ButtonSecondary, ButtonPrimary } from "webiny-ui/Button";
import PagesAutoComplete from "./PagesAutoComplete";
import PagesAutoComplete from "webiny-app-cms/admin/components/PagesAutoComplete";
import { Elevation } from "webiny-ui/Elevation";

const LinkForm = ({ data, onSubmit, onCancel }: Object) => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ButtonPrimary } from "webiny-ui/Button";
import { Query, Mutation } from "react-apollo";
import { withSnackbar } from "webiny-admin/components";
import graphql from "./graphql";
import PagesAutoComplete from "./PagesAutoComplete";
import PagesAutoComplete from "webiny-app-cms/admin/components/PagesAutoComplete";
import { CircularProgress } from "webiny-ui/Progress";
import Image from "./Image";

Expand Down

0 comments on commit 9d48741

Please sign in to comment.