@rnga/orders
Version:
## Get schema from @prisma-cms 1. yarn get-api-schema -e http://localhost:4000 2. yarn build-api-fragments
225 lines (162 loc) • 3.61 kB
JavaScript
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
// import PageLayout from '../layout/section';
// import PageLayout from "pages/layout";
// import View from './View';
// import View from "@rnga/orders";
import View from "../../../../App";
import {
orders,
services,
} from "query";
import { compose, graphql } from 'react-apollo';
import GraphqlConnector from 'graphql-connection';
export class OrdersPageConnection extends Component {
// static defaultProps = {
// ...PageLayout.defaultProps,
// }
render() {
const {
data,
...other
} = this.props;
if (!data) {
return null;
}
return (<Fragment>
<View
data={data}
addObject={(props) => {
// console.log("addObject props", props);
const {
history,
} = this.props;
history.push("/orders/create");
}}
{...other}
opened={true}
/>
</Fragment>
)
}
}
export default class OrdersPageProxy extends GraphqlConnector {
static propTypes = {
where: PropTypes.object,
archived: PropTypes.bool.isRequired,
}
static defaultProps = {
...GraphqlConnector.defaultProps,
Connector: compose(
graphql(
orders, {
options: props => {
// console.log("OrdersPageProxy", props);
return {
variables: {
orderGetItems: true,
...props,
},
}
},
// skip: props => {
// console.log("OrdersPageProxy skip", props);
// return true
// },
}
),
graphql(services, {
name: "services",
options: props => {
return {
variables: {
},
}
},
}))(OrdersPageConnection),
first: 10,
orderBy: "date_DESC",
archived: false,
};
addFilterCondition(where, key, value) {
switch (key) {
case "tabIndex":
return null;
case "number":
// key = "number_starts_with";
key = "OR";
value = [{
number: value.replace(/[^0-9]/g, ''),
}, {
User: {
fullname_contains: value,
},
}]
break;
default: ;
}
value = value || undefined;
return super.addFilterCondition(where, key, value);
}
getVariables() {
const {
where,
archived,
} = this.props;
const {
where: varsWhere,
...other
} = super.getVariables();
// console.log("getVariables", super.getVariables());
let {
query,
name,
...otherWhere
} = varsWhere || {};
let whereConditions = {
AND: [
{
...where,
},
{
...otherWhere,
},
// {
// OR: [
// {
// archived: null,
// },
// {
// archived_not: true,
// },
// ],
// },
],
}
if (archived !== undefined) {
if (archived === false) {
whereConditions.AND.push({
OR: [
{
archived: null,
},
{
archived_not: true,
},
],
});
}
else if (archived === true) {
whereConditions.AND.push({
archived: true,
});
}
}
return {
where: whereConditions,
query,
name,
...other
};
}
}