- Merge release

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-02-09 13:21:09 -05:00
parent c1a97c44a0
commit 653f6e0ebb
2 changed files with 30 additions and 10 deletions

View File

@@ -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 = {};

View File

@@ -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