/
Filters.js
104 lines (98 loc) · 2.61 KB
/
Filters.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React from "react";
import PropTypes from "prop-types";
import StyledSelect from "../../components/select";
import { translate } from "react-i18next";
import { graphql } from "@apollo/react-hoc";
import { GET_TAXONOMIES } from "../../../shared/queries/Queries";
const Filters = ({ query, t, tags, categories, changeFilter }) => {
return (
<div>
<StyledSelect
bold
onChange={status => changeFilter("status", status)}
selected={query.get("status") || null}
options={[
{
name: t("common.all"),
value: null,
},
{
name: t("common.published"),
value: "publish",
},
{
name: t("common.drafts"),
value: "draft",
},
{
name: t("common.deleted"),
value: "trash",
},
]}
/>
{!tags.loading && (
<StyledSelect
bold
onChange={status => changeFilter("tag", status)}
selected={query.get("tag")}
options={[
{
name: "Select Tag",
value: null,
},
...tags.taxonomies.map(tag => {
return { name: tag.name, value: tag.name };
}),
]}
/>
)}
{!categories.loading && (
<StyledSelect
bold
onChange={status => changeFilter("category", status)}
selected={query.get("category")}
options={[
{
name: "Select Category",
value: null,
},
...categories.taxonomies.map(category => {
return { name: category.name, value: category.name };
}),
]}
/>
)}
<StyledSelect
bold
onChange={sort => changeFilter("sortBy", sort)}
selected={query.get("sortBy") || "newest"}
options={[
{
name: "Newest",
value: "newest",
},
{
name: "Oldest",
value: "oldest",
},
]}
/>
</div>
);
};
Filters.propTypes = {
query: PropTypes.object.isRequired,
tags: PropTypes.object,
categories: PropTypes.object,
t: PropTypes.func,
changeFilter: PropTypes.func.isRequired,
};
const CategoriesData = graphql(GET_TAXONOMIES, {
name: "categories",
options: () => ({ variables: { type: "post_category" } }),
});
const TagsData = graphql(GET_TAXONOMIES, {
name: "tags",
options: () => ({ variables: { type: "post_tag" } }),
});
export default translate("translations")(TagsData(CategoriesData(Filters)));