Skip to content

Commit 894133b

Browse files
committed
fix ordering key was not translated to server keys
1 parent bc81edb commit 894133b

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

package-lock.json

+7-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils/listPaginatedTools.ts

+23-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import isEqual from "lodash.isequal";
99
import {GenericDictionnary, VDUSDatatableOptions, VDUSFormSchema} from "./VDUSTypes"
1010

1111
const getDefaultValueForParam = (param: string, schema?: VDUSFormSchema): any => {
12-
if (schema && schema[param]) {
12+
if (schema?.[param]) {
1313
// if there is a defautl value we change the condition to is non equality
1414
if (schema[param].default) {
1515
// TODO default value for array need to be stringify ?
@@ -31,7 +31,7 @@ const isValueDefault = (value: any, param: string, schema?: VDUSFormSchema): boo
3131
// Default is string
3232
let isValueDefault: boolean = value === "";
3333

34-
if (schema && schema[param]) {
34+
if (schema?.[param]) {
3535
// if there is a defautl value we change the condition to is non equality
3636
if (typeof(schema[param].default) !== "undefined") {
3737
// We have a special case for nullBoolean because we can have null value that is not the default
@@ -79,18 +79,36 @@ const generateQueryFromObject = (object: GenericDictionnary, schema?: VDUSFormSc
7979

8080
// by default the quey key is the same that the form key
8181
let queryKey = key;
82+
let queryValue = value;
8283
// But this can be overrided if name attribute is defined in the param schema
83-
if (!localName && schema && schema[key] && schema[key].name) {
84+
if (!localName && schema?.[key]?.name) {
8485
queryKey = (schema[key].name as string); // typescript error because .name can be undefined but if check it before
8586
}
8687

87-
queryUrl[queryKey] = value;
88+
// As ordering key is a special key where other key can be specified inside its value we need to check for each ordernig key if there is a different server name
89+
if (key === 'ordering' && !localName && value && Array.isArray(value)) {
90+
queryValue = value.map((orderItem: string) => {
91+
let prefix = ""
92+
// If we have a desc order we need to remove the - to match with the schema
93+
if (orderItem.startsWith("-")) {
94+
orderItem = orderItem.replace("-", "");
95+
prefix = "-"
96+
}
97+
// Look if we have a specific server name for this attribute in the schema.
98+
if(schema?.[orderItem]?.name) {
99+
orderItem = (schema[orderItem].name as string)
100+
}
101+
// Do not forget to add the prefix to have the correct ordering
102+
return `${prefix}${orderItem}`;
103+
})
104+
}
105+
queryUrl[queryKey] = queryValue;
88106
}
89107
return queryUrl;
90108
}
91109

92110
const convertParamIfTypeInSchema = (query: GenericDictionnary, param: string, schema?: VDUSFormSchema, prefix = ""): any => {
93-
if (!schema || !schema[param] || !schema[param].type) {
111+
if (!schema?.[param]?.type) {
94112
return query[prefix + param];
95113
}
96114
if (schema[param].type === "boolean") {

0 commit comments

Comments
 (0)