@@ -1,24 +1,12 @@
|
||||
import {Button, Card, Checkbox, Col, Form, Input, InputNumber, Row, Select} from "antd";
|
||||
import {Button, Card, Checkbox, Col, Form, Row, Select} from "antd";
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {fetchFilterData} from "../../utils/RenderTemplate";
|
||||
import {DeleteFilled} from "@ant-design/icons";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import {getOperatorsByType} from "../../utils/graphQLmodifier";
|
||||
import {getOrderOperatorsByType, getWhereOperatorsByType} from "../../utils/graphQLmodifier";
|
||||
import LoadingSkeleton from "../loading-skeleton/loading-skeleton.component";
|
||||
import {setModalContext} from "../../redux/modals/modals.actions";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors";
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser
|
||||
});
|
||||
|
||||
export function ReportCenterModalFiltersSortersComponent({form, bodyshop, currentUser}) {
|
||||
console.dir(bodyshop, {depth: null})
|
||||
console.dir(currentUser, {depth: null})
|
||||
export default function ReportCenterModalFiltersSortersComponent({form}) {
|
||||
return (
|
||||
<Form.Item style={{margin: 0, padding: 0}} dependencies={["key"]}>
|
||||
{() => {
|
||||
@@ -29,9 +17,6 @@ export function ReportCenterModalFiltersSortersComponent({form, bodyshop, curre
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ReportCenterModalFiltersSortersComponent);
|
||||
|
||||
|
||||
function RenderFilters({templateId, form}) {
|
||||
const [state, setState] = useState(null);
|
||||
const [visible, setVisible] = useState(false);
|
||||
@@ -125,7 +110,8 @@ function RenderFilters({templateId, form}) {
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Select options={getOperatorsByType(type)}/>
|
||||
<Select
|
||||
options={getWhereOperatorsByType(type)}/>
|
||||
</Form.Item>
|
||||
}
|
||||
}
|
||||
@@ -138,6 +124,7 @@ function RenderFilters({templateId, form}) {
|
||||
() => {
|
||||
const name = form.getFieldValue(['filters', field.name, "field"]);
|
||||
const type = state.filters.find(f => f.name === name)?.type;
|
||||
const reflector = state.filters.find(f => f.name === name)?.reflector;
|
||||
|
||||
return <Form.Item
|
||||
key={`${index}value`}
|
||||
@@ -150,19 +137,7 @@ function RenderFilters({templateId, form}) {
|
||||
},
|
||||
]}
|
||||
>
|
||||
{type === 'number' ?
|
||||
<InputNumber
|
||||
onChange={(value) => {
|
||||
form.setFieldsValue({[field.name]: {value: parseInt(value)}});
|
||||
}}
|
||||
/>
|
||||
:
|
||||
<Input
|
||||
onChange={(value) => {
|
||||
form.setFieldsValue({[field.name]: {value: value.toString()}});
|
||||
}}
|
||||
/>
|
||||
}
|
||||
<ReportCenterModalFiltersSortersComponent form={form} field={field} type={type} reflector={reflector}/>
|
||||
</Form.Item>
|
||||
}
|
||||
}
|
||||
@@ -245,7 +220,7 @@ function RenderFilters({templateId, form}) {
|
||||
]}
|
||||
>
|
||||
<Select
|
||||
options={getOperatorsByType()}
|
||||
options={getOrderOperatorsByType()}
|
||||
/>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import {generateReflections} from "../../utils/graphQLmodifier";
|
||||
import {Input, InputNumber, Select} from "antd";
|
||||
import React from "react";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectBodyshop, selectCurrentUser} from "../../redux/user/user.selectors";
|
||||
import {connect} from "react-redux";
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({});
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser
|
||||
});
|
||||
|
||||
export function ReportCenterModalValueSelectorComponent ({type, reflector, form, field, bodyshop, currentUser}) {
|
||||
console.log(`Entering ReportCenterModalValueSelectorComponent`);
|
||||
console.log('Type')
|
||||
console.log(type)
|
||||
console.log('Reflector')
|
||||
console.dir(reflector, {depth: null})
|
||||
console.log('Bodyshop')
|
||||
console.dir(bodyshop, {depth: null})
|
||||
console.log('CurrentUser')
|
||||
console.dir(currentUser, {depth: null})
|
||||
|
||||
if (reflector) {
|
||||
const reflections = generateReflections(reflector);
|
||||
if (reflections.length > 0) {
|
||||
return <Select options={reflections}/>
|
||||
}
|
||||
}
|
||||
|
||||
// Number Input
|
||||
if (type === "number") {
|
||||
return <InputNumber
|
||||
onChange={(value) => {form.setFieldsValue({[field.name]: {value: parseInt(value)}});
|
||||
}}
|
||||
/>
|
||||
}
|
||||
|
||||
// Default to String Input
|
||||
return <Input
|
||||
onChange={(value) => {
|
||||
form.setFieldsValue({[field.name]: {value: value.toString()}});
|
||||
}}
|
||||
/>
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(ReportCenterModalValueSelectorComponent);
|
||||
@@ -9,7 +9,7 @@ import {store} from "../redux/store";
|
||||
import client from "../utils/GraphQLClient";
|
||||
import cleanAxios from "./CleanAxios";
|
||||
import {TemplateList} from "./TemplateConstants";
|
||||
import {applyFilters, applySorters, parseQuery, printQuery, wrapFiltersInAnd} from "./graphQLmodifier";
|
||||
import {generateTemplate} from "./graphQLmodifier";
|
||||
|
||||
const server = process.env.REACT_APP_REPORTS_SERVER_URL;
|
||||
|
||||
@@ -278,7 +278,9 @@ export const GenerateDocument = async (
|
||||
sendType,
|
||||
jobid
|
||||
) => {
|
||||
|
||||
const bodyshop = store.getState().user.bodyshop;
|
||||
|
||||
if (sendType === "e") {
|
||||
store.dispatch(
|
||||
setEmailOptions({
|
||||
@@ -404,7 +406,7 @@ const fetchContextData = async (templateObject, jsrAuth) => {
|
||||
|
||||
|
||||
// We have no template filters or sorters, so we can just execute the query and return the data
|
||||
if ((!templateObject?.filters && !templateObject?.filters?.length && !templateObject?.sorters && !templateObject?.sorters?.length)) {
|
||||
if (!(templateObject?.filters?.length || templateObject?.sorters?.length)) {
|
||||
let contextData = {};
|
||||
if (templateQueryToExecute) {
|
||||
const {data} = await client.query({
|
||||
@@ -417,36 +419,11 @@ const fetchContextData = async (templateObject, jsrAuth) => {
|
||||
return {contextData, useShopSpecificTemplate};
|
||||
}
|
||||
|
||||
// Parse the query and apply the filters and sorters
|
||||
const ast = parseQuery(templateQueryToExecute);
|
||||
|
||||
let filterFields = [];
|
||||
|
||||
if (templateObject?.filters && templateObject?.filters?.length) {
|
||||
applyFilters(ast, templateObject.filters, filterFields);
|
||||
wrapFiltersInAnd(ast, filterFields);
|
||||
}
|
||||
|
||||
if (templateObject?.sorters && templateObject?.sorters?.length) {
|
||||
applySorters(ast, templateObject.sorters);
|
||||
}
|
||||
|
||||
const finalQuery = printQuery(ast);
|
||||
|
||||
// commented out for future revision debugging
|
||||
// console.log('Modified Query');
|
||||
// console.log(finalQuery);
|
||||
|
||||
let contextData = {};
|
||||
if (templateQueryToExecute) {
|
||||
const {data} = await client.query({
|
||||
query: gql(finalQuery),
|
||||
variables: {...templateObject.variables},
|
||||
});
|
||||
contextData = data;
|
||||
}
|
||||
|
||||
return {contextData, useShopSpecificTemplate};
|
||||
return await generateTemplate(
|
||||
templateQueryToExecute,
|
||||
templateObject,
|
||||
useShopSpecificTemplate
|
||||
);
|
||||
};
|
||||
|
||||
//export const displayTemplateInWindow = (html) => {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import {Kind, parse, print, visit} from "graphql";
|
||||
import client from "./GraphQLClient";
|
||||
import {gql} from "@apollo/client";
|
||||
|
||||
const STRING_OPERATORS = [
|
||||
{value: "_eq", label: "equals"},
|
||||
@@ -25,16 +27,23 @@ const ORDER_BY_OPERATORS = [
|
||||
* Get the available operators for filtering
|
||||
* @returns {[{label: string, value: string},{label: string, value: string}]}
|
||||
*/
|
||||
export function getOrderByOperators() {
|
||||
export function getOrderOperatorsByType() {
|
||||
return ORDER_BY_OPERATORS;
|
||||
}
|
||||
|
||||
export function generateReflections(reflector) {
|
||||
// const type = reflector?.type;
|
||||
// const name = reflector?.name;
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the available operators for filtering
|
||||
* @param type
|
||||
* @returns {[{label: string, value: string},{label: string, value: string},{label: string, value: string},{label: string, value: string},{label: string, value: string},null]}
|
||||
*/
|
||||
export function getOperatorsByType(type = 'string') {
|
||||
export function getWhereOperatorsByType(type = 'string') {
|
||||
const operators = {
|
||||
string: STRING_OPERATORS,
|
||||
number: NUMBER_OPERATORS
|
||||
@@ -61,6 +70,50 @@ export function parseQuery(query) {
|
||||
export function printQuery(query) {
|
||||
return print(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a template based on the query and object
|
||||
* @param templateQueryToExecute
|
||||
* @param templateObject
|
||||
* @param useShopSpecificTemplate
|
||||
* @returns {Promise<{contextData: {}, useShopSpecificTemplate}>}
|
||||
*/
|
||||
export async function generateTemplate(templateQueryToExecute, templateObject, useShopSpecificTemplate) {
|
||||
// Advanced Filtering and Sorting modifications start here
|
||||
|
||||
// Parse the query and apply the filters and sorters
|
||||
const ast = parseQuery(templateQueryToExecute);
|
||||
|
||||
let filterFields = [];
|
||||
|
||||
if (templateObject?.filters && templateObject?.filters?.length) {
|
||||
applyFilters(ast, templateObject.filters, filterFields);
|
||||
wrapFiltersInAnd(ast, filterFields);
|
||||
}
|
||||
|
||||
if (templateObject?.sorters && templateObject?.sorters?.length) {
|
||||
applySorters(ast, templateObject.sorters);
|
||||
}
|
||||
|
||||
const finalQuery = printQuery(ast);
|
||||
|
||||
// commented out for future revision debugging
|
||||
// console.log('Modified Query');
|
||||
// console.log(finalQuery);
|
||||
|
||||
let contextData = {};
|
||||
if (templateQueryToExecute) {
|
||||
const {data} = await client.query({
|
||||
query: gql(finalQuery),
|
||||
variables: {...templateObject.variables},
|
||||
});
|
||||
contextData = data;
|
||||
}
|
||||
|
||||
return {contextData, useShopSpecificTemplate};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply sorters to the AST
|
||||
* @param ast
|
||||
@@ -278,8 +331,6 @@ export function applyFilters(ast, filters) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the GraphQL kind for a value
|
||||
* @param value
|
||||
|
||||
Reference in New Issue
Block a user