@@ -1,5 +1,4 @@
|
||||
import {gql} from "@apollo/client";
|
||||
import {parse, print} from "graphql";
|
||||
import jsreport from "@jsreport/browser-client";
|
||||
import {notification} from "antd";
|
||||
import axios from "axios";
|
||||
@@ -10,7 +9,7 @@ import {store} from "../redux/store";
|
||||
import client from "../utils/GraphQLClient";
|
||||
import cleanAxios from "./CleanAxios";
|
||||
import {TemplateList} from "./TemplateConstants";
|
||||
import {applyFilters, applySorters, wrapFiltersInAnd} from "./graphQLmodifier";
|
||||
import {applyFilters, applySorters, parseQuery, printQuery, wrapFiltersInAnd} from "./graphQLmodifier";
|
||||
|
||||
const server = process.env.REACT_APP_REPORTS_SERVER_URL;
|
||||
|
||||
@@ -25,7 +24,6 @@ export default async function RenderTemplate(
|
||||
renderAsExcel = false,
|
||||
renderAsText = false
|
||||
) {
|
||||
console.log(' RENDER TEMPLATE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
if (window.jsr3) {
|
||||
jsreport.serverUrl = "https://reports3.test.imex.online/";
|
||||
}
|
||||
@@ -391,13 +389,13 @@ const fetchContextData = async (templateObject, jsrAuth) => {
|
||||
templateQueryToExecute = atob(generalTemplate.content);
|
||||
}
|
||||
|
||||
// TODO: REPORT UPDATE
|
||||
//TemplateQueryToExecute needs to get modified based on sorters/filters set by user from modal.
|
||||
console.log(' RENDER TEMPLATE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
|
||||
console.dir(templateQueryToExecute);
|
||||
console.log('Template Object');
|
||||
console.dir(templateObject);
|
||||
console.log('Unmodified Query');
|
||||
console.dir(templateQueryToExecute);
|
||||
|
||||
|
||||
// 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)) {
|
||||
console.log('No filters or sorters');
|
||||
let contextData = {};
|
||||
@@ -412,7 +410,9 @@ const fetchContextData = async (templateObject, jsrAuth) => {
|
||||
return {contextData, useShopSpecificTemplate};
|
||||
}
|
||||
|
||||
const ast = parse(templateQueryToExecute);
|
||||
// Parse the query and apply the filters and sorters
|
||||
const ast = parseQuery(templateQueryToExecute);
|
||||
|
||||
let filterFields = [];
|
||||
|
||||
if (templateObject?.filters && templateObject?.filters?.length) {
|
||||
@@ -420,12 +420,15 @@ const fetchContextData = async (templateObject, jsrAuth) => {
|
||||
applyFilters(ast, templateObject.filters, filterFields);
|
||||
wrapFiltersInAnd(ast, filterFields);
|
||||
}
|
||||
|
||||
if (templateObject?.sorters && templateObject?.sorters?.length) {
|
||||
console.log('Applying sorters')
|
||||
applySorters(ast, templateObject.sorters);
|
||||
}
|
||||
|
||||
const finalQuery = print(ast);
|
||||
const finalQuery = printQuery(ast);
|
||||
|
||||
console.log('Modified Query');
|
||||
console.log(finalQuery);
|
||||
|
||||
let contextData = {};
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
import {Kind, visit} from "graphql";
|
||||
import {Kind, visit, parse, print} from "graphql";
|
||||
|
||||
/* eslint-disable no-loop-func */
|
||||
|
||||
/**
|
||||
* Parse a GraphQL query into an AST
|
||||
* @param query
|
||||
* @returns {DocumentNode}
|
||||
*/
|
||||
export function parseQuery(query) {
|
||||
return parse(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print an AST back into a GraphQL query
|
||||
* @param query
|
||||
* @returns {string}
|
||||
*/
|
||||
export function printQuery(query) {
|
||||
return print(query);
|
||||
}
|
||||
/**
|
||||
* Apply sorters to the AST
|
||||
* @param ast
|
||||
|
||||
Reference in New Issue
Block a user