- Default sorts!

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-02-20 19:07:23 -05:00
parent 6b7b34ae79
commit 83d702f12b
5 changed files with 59 additions and 14 deletions

View File

@@ -77,6 +77,7 @@ export default async function RenderTemplate(
bodyshop: bodyshop,
filters: templateObject?.filters,
sorters: templateObject?.sorters,
defaultSorters: templateObject?.defaultSorters,
offset: bodyshop.timezone, //dayjs().utcOffset(),
},
};
@@ -406,9 +407,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?.length || templateObject?.sorters?.length)) {
if (!hasFilters && !hasSorters && !hasDefaultSorters) {
let contextData = {};
if (templateQueryToExecute) {
const {data} = await client.query({

View File

@@ -87,6 +87,8 @@ export async function generateTemplate(templateQueryToExecute, templateObject, u
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);