diff --git a/.circleci/config.yml b/.circleci/config.yml index 9f019cd..eb5d575 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 jobs: test: docker: - - image: cimg/node:18.15 + - image: cimg/node:20.11.1 steps: - checkout - run: npm install @@ -10,7 +10,7 @@ jobs: release: docker: - - image: cimg/node:18.15 + - image: cimg/node:20.11.1 steps: - checkout - run: npm install diff --git a/README.md b/README.md index 23756d5..921ec18 100644 --- a/README.md +++ b/README.md @@ -147,4 +147,4 @@ Here is the description of the type for the configuration of each params ([Param # Local dev You can use vue3-example to test local dev. You just have to go to vue3-example/src/components/HelloWorld.vue and uncomment the relative import of VDUS. -Do not forget to launch `npm install` in both root directory AND vue3-example directory \ No newline at end of file +Do not forget to launch `npm install` in both root directory AND vue3-example directory diff --git a/package-lock.json b/package-lock.json index b99e6bb..ed22ba2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5676,9 +5676,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001469", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001469.tgz", - "integrity": "sha512-Rcp7221ScNqQPP3W+lVOYDyjdR6dC+neEQCttoNr5bAyz54AboB4iwpnWgyi8P4YUsPybVzT4LgWiBbI3drL4g==", + "version": "1.0.30001597", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001597.tgz", + "integrity": "sha512-7LjJvmQU6Sj7bL0j5b5WY/3n7utXUJvAe1lxhsHDbLmwX9mdL86Yjtr+5SRCyf8qME4M7pU2hswj0FpyBVCv9w==", "dev": true, "funding": [ { @@ -5688,6 +5688,10 @@ { "type": "tidelift", "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" } ] }, diff --git a/src/utils/listPaginatedTools.ts b/src/utils/listPaginatedTools.ts index fe8e92d..8f7cb5d 100644 --- a/src/utils/listPaginatedTools.ts +++ b/src/utils/listPaginatedTools.ts @@ -9,7 +9,7 @@ import isEqual from "lodash.isequal"; import {GenericDictionnary, VDUSDatatableOptions, VDUSFormSchema} from "./VDUSTypes" const getDefaultValueForParam = (param: string, schema?: VDUSFormSchema): any => { - if (schema && schema[param]) { + if (schema?.[param]) { // if there is a defautl value we change the condition to is non equality if (schema[param].default) { // TODO default value for array need to be stringify ? @@ -31,7 +31,7 @@ const isValueDefault = (value: any, param: string, schema?: VDUSFormSchema): boo // Default is string let isValueDefault: boolean = value === ""; - if (schema && schema[param]) { + if (schema?.[param]) { // if there is a defautl value we change the condition to is non equality if (typeof(schema[param].default) !== "undefined") { // 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 // by default the quey key is the same that the form key let queryKey = key; + let queryValue = value; // But this can be overrided if name attribute is defined in the param schema - if (!localName && schema && schema[key] && schema[key].name) { + if (!localName && schema?.[key]?.name) { queryKey = (schema[key].name as string); // typescript error because .name can be undefined but if check it before } - queryUrl[queryKey] = value; + // 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 + if (key === 'ordering' && !localName && value && Array.isArray(value)) { + queryValue = value.map((orderItem: string) => { + let prefix = "" + // If we have a desc order we need to remove the - to match with the schema + if (orderItem.startsWith("-")) { + orderItem = orderItem.replace("-", ""); + prefix = "-" + } + // Look if we have a specific server name for this attribute in the schema. + if(schema?.[orderItem]?.name) { + orderItem = (schema[orderItem].name as string) + } + // Do not forget to add the prefix to have the correct ordering + return `${prefix}${orderItem}`; + }) + } + queryUrl[queryKey] = queryValue; } return queryUrl; } const convertParamIfTypeInSchema = (query: GenericDictionnary, param: string, schema?: VDUSFormSchema, prefix = ""): any => { - if (!schema || !schema[param] || !schema[param].type) { + if (!schema?.[param]?.type) { return query[prefix + param]; } if (schema[param].type === "boolean") {