- Merge release and adjust due to version differences
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
@@ -57,6 +57,16 @@ const range = [
|
||||
label: 'Last 90 Days',
|
||||
value: [dayjs().add(-90, "day"), dayjs()],
|
||||
}
|
||||
]
|
||||
];
|
||||
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
range.push({
|
||||
label: 'Last Year',
|
||||
value: [
|
||||
dayjs().subtract(1, "year"),
|
||||
dayjs(),
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
export default range;
|
||||
|
||||
@@ -9,7 +9,8 @@ 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;
|
||||
|
||||
jsreport.serverUrl = server;
|
||||
@@ -74,7 +75,10 @@ export default async function RenderTemplate(
|
||||
headerpath: `/${bodyshop.imexshopid}/header.html`,
|
||||
footerpath: `/${bodyshop.imexshopid}/footer.html`,
|
||||
bodyshop: bodyshop,
|
||||
filters: templateObject?.filters,
|
||||
sorters: templateObject?.sorters,
|
||||
offset: bodyshop.timezone, //dayjs().utcOffset(),
|
||||
defaultSorters: templateObject?.defaultSorters,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -402,9 +406,12 @@ const fetchContextData = async (templateObject, jsrAuth) => {
|
||||
// console.log('Unmodified Query');
|
||||
// console.dir(templateQueryToExecute);
|
||||
|
||||
const hasFilters = templateObject?.filters?.length > 0;
|
||||
const hasSorters = templateObject?.sorters?.length > 0;
|
||||
const hasDefaultSorters = templateObject?.defaultSorters?.length > 0;
|
||||
|
||||
// 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 (!hasFilters && !hasSorters && !hasDefaultSorters) {
|
||||
let contextData = {};
|
||||
if (templateQueryToExecute) {
|
||||
const {data} = await client.query({
|
||||
@@ -416,36 +423,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"},
|
||||
@@ -16,8 +18,26 @@ const NUMBER_OPERATORS = [
|
||||
{value: "_gte", label: "greater than or equal"},
|
||||
{value: "_lte", label: "less than or equal"}
|
||||
];
|
||||
const ORDER_BY_OPERATORS = [
|
||||
{value: "asc", label: "ascending"},
|
||||
{value: "desc", label: "descending"}
|
||||
];
|
||||
|
||||
export function getOperatorsByType(type = 'string') {
|
||||
/**
|
||||
* Get the available operators for filtering
|
||||
* @returns {[{label: string, value: string},{label: string, value: string}]}
|
||||
*/
|
||||
export function getOrderOperatorsByType() {
|
||||
return ORDER_BY_OPERATORS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 getWhereOperatorsByType(type = 'string') {
|
||||
const operators = {
|
||||
string: STRING_OPERATORS,
|
||||
number: NUMBER_OPERATORS
|
||||
@@ -45,6 +65,51 @@ 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);
|
||||
} else if (templateObject?.defaultSorters && templateObject?.defaultSorters?.length) {
|
||||
applySorters(ast, templateObject.defaultSorters);
|
||||
}
|
||||
|
||||
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
|
||||
@@ -262,7 +327,6 @@ export function applyFilters(ast, filters) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the GraphQL kind for a value
|
||||
* @param value
|
||||
|
||||
Reference in New Issue
Block a user