IO-888 Sorted Speedprint

This commit is contained in:
Patrick Fic
2021-04-13 08:22:41 -07:00
parent b09b2be34a
commit 4c0cde23b2
11 changed files with 51 additions and 20 deletions

View File

@@ -8,6 +8,7 @@ import { setEmailOptions } from "../redux/email/email.actions";
import { store } from "../redux/store";
import client from "../utils/GraphQLClient";
import { TemplateList } from "./TemplateConstants";
import _ from "lodash";
const server = process.env.REACT_APP_REPORTS_SERVER_URL;
jsreport.serverUrl = server;
@@ -63,7 +64,7 @@ export async function RenderTemplates(
renderAsHtml = false
) {
//Query assets that match the template name. Must be in format <<templateName>>.query
let templateAndData = [];
let unsortedTemplatesAndData = [];
let proms = [];
templateObjects.forEach((template) => {
proms.push(
@@ -71,7 +72,7 @@ export async function RenderTemplates(
let { contextData, useShopSpecificTemplate } = await fetchContextData(
template
);
templateAndData.push({
unsortedTemplatesAndData.push({
templateObject: template,
contextData,
useShopSpecificTemplate,
@@ -80,6 +81,22 @@ export async function RenderTemplates(
);
});
await Promise.all(proms);
//Re-order list to follow speedprint.
// var templateAndData = _.sortBy(unsortedTemplatesAndData, function (item) {
// return templateObjects.findIndex(
// (template) => template.name === item.templateObject.name
// );
// });
unsortedTemplatesAndData.sort(function (a, b) {
return (
templateObjects.findIndex((x) => x.name === a.templateObject.name) -
templateObjects.findIndex((x) => x.name === b.templateObject.name)
);
});
const templateAndData = unsortedTemplatesAndData;
let rootTemplate = templateAndData.shift();
let reportRequest = {