From 0b323a72f774a3c030c05e178999f65548fbb96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Mon, 27 Jan 2025 13:09:30 +0100 Subject: [PATCH 1/4] fix: format search date parameters when resuming from URL actions (#845) [skip ci] https://github.com/gisce/webclient/issues/1696 https://github.com/gisce/webclient/issues/1699 --- src/context/ActionViewContext.tsx | 9 ++- src/helpers/searchHelper.ts | 69 +++++++++++++++++++ .../views/searchFilter/SideSearchFilter.tsx | 30 +------- 3 files changed, 76 insertions(+), 32 deletions(-) diff --git a/src/context/ActionViewContext.tsx b/src/context/ActionViewContext.tsx index 7641ddfa6..fc09645d6 100644 --- a/src/context/ActionViewContext.tsx +++ b/src/context/ActionViewContext.tsx @@ -1,6 +1,6 @@ +import { convertParamsToValues } from "@/helpers/searchHelper"; import { DEFAULT_SEARCH_LIMIT } from "@/models/constants"; -import { View } from "@/types"; -import { convertParamsToValues } from "@/widgets/views/searchFilter/SideSearchFilter"; +import { TreeView, View } from "@/types"; import { ColumnState } from "@gisce/react-formiga-table"; import { createContext, useContext, useEffect, useState } from "react"; @@ -132,7 +132,10 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => { const [graphIsLoading, setGraphIsLoading] = useState(true); const [previousView, setPreviousView] = useState(); const [searchValues, setSearchValues] = useState( - convertParamsToValues(initialSearchParams || []), + convertParamsToValues( + initialSearchParams || [], + (currentView as TreeView).fields, + ), ); const [treeFirstVisibleRow, setTreeFirstVisibleRow] = useState(0); const [searchQuery, setSearchQuery] = useState(); diff --git a/src/helpers/searchHelper.ts b/src/helpers/searchHelper.ts index 49f06892b..aac6f96f7 100644 --- a/src/helpers/searchHelper.ts +++ b/src/helpers/searchHelper.ts @@ -1,3 +1,5 @@ +import dayjs from "@/helpers/dayjs"; + const convertBooleanParamIfNeeded = (value: any) => { if ((typeof value === "string" && value === "true") || value === "false") { return value === "true"; @@ -194,3 +196,70 @@ export const mergeParams = (searchParams: any[], domainParams: any[]) => { return finalParams; }; + +export const normalizeValues = (values: any) => { + // values object should be converted: fields that are empty strings should be undefined + return Object.keys(values).reduce((acc: any, key) => { + const value = values[key]; + if (value !== "" && value !== undefined) { + acc[key] = value; + } + return acc; + }, {}); +}; + +export const convertParamsToValues = (params: any[], fields?: any) => { + if (!params || !Array.isArray(params) || !fields) return {}; + + const values = params.reduce((acc: any, param) => { + // Handle array format [field, operator, value] + if (Array.isArray(param)) { + const [field, operator, value] = param; + const baseField = field.split("#")[0]; + const type = fields?.[baseField]?.type; + + if (type === "date") { + // Initialize array if not exists + if (!acc[baseField]) { + acc[baseField] = [null, null]; + } + // Set the appropriate value in the array based on operator + if (operator === ">=") { + acc[baseField][0] = dayjs(value); + } else if (operator === "<=") { + acc[baseField][1] = dayjs(value); + } + } else if (type === "datetime") { + // For datetime, we need to split into date and time components + const dateObj = dayjs(value); + const baseKey = field.split("#")[0]; + + // Initialize arrays if they don't exist + if (!acc[baseKey + "#date"]) { + acc[baseKey + "#date"] = [null, null]; + } + if (!acc[baseKey + "#time"]) { + acc[baseKey + "#time"] = [null, null]; + } + + // Set the appropriate values based on operator + if (operator === ">=") { + acc[baseKey + "#date"][0] = dateObj; + acc[baseKey + "#time"][0] = dateObj; + } else if (operator === "<=") { + acc[baseKey + "#date"][1] = dateObj; + acc[baseKey + "#time"][1] = dateObj; + } + } else { + // For other types, just set the value + acc[field] = value; + } + } else { + // Keep existing object format support + acc[param.id] = param.value; + } + return acc; + }, {}); + + return normalizeValues(values); +}; diff --git a/src/widgets/views/searchFilter/SideSearchFilter.tsx b/src/widgets/views/searchFilter/SideSearchFilter.tsx index 0399ec2d6..94660dbdb 100644 --- a/src/widgets/views/searchFilter/SideSearchFilter.tsx +++ b/src/widgets/views/searchFilter/SideSearchFilter.tsx @@ -20,7 +20,7 @@ import { import { SearchField } from "./SearchField"; import { SearchFields } from "@/types"; -import { getParamsForFields } from "@/helpers/searchHelper"; +import { getParamsForFields, normalizeValues } from "@/helpers/searchHelper"; import { useLocale } from "@gisce/react-formiga-components"; import { FloatingDrawer } from "@/ui/FloatingDrawer"; import debounce from "lodash.debounce"; @@ -255,31 +255,3 @@ export const SideSearchFooter = ({ ); }; - -const normalizeValues = (values: any) => { - // values object should be converted: fields that are empty strings should be undefined - return Object.keys(values).reduce((acc: any, key) => { - const value = values[key]; - if (value !== "" && value !== undefined) { - acc[key] = value; - } - return acc; - }, {}); -}; - -export const convertParamsToValues = (params: any[]) => { - if (!params || !Array.isArray(params)) return undefined; - return normalizeValues( - params.reduce((acc: any, param) => { - // Handle array format [field, operator, value] - if (Array.isArray(param)) { - const [field, , value] = param; - acc[field] = value; - } else { - // Keep existing object format support - acc[param.id] = param.value; - } - return acc; - }, {}), - ); -}; From 2fb5d11213afeb4373deca21c469c300b5c33fa3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Mon, 27 Jan 2025 13:10:04 +0100 Subject: [PATCH 2/4] fix: add unsaved changes check for hotkey navigation actions in form (#850) [skip ci] https://github.com/gisce/webclient/issues/1717 --- src/actionbar/FormActionBar.tsx | 38 ++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/actionbar/FormActionBar.tsx b/src/actionbar/FormActionBar.tsx index 48097b16d..deb76d798 100644 --- a/src/actionbar/FormActionBar.tsx +++ b/src/actionbar/FormActionBar.tsx @@ -163,15 +163,25 @@ function FormActionBar({ toolbar }: { toolbar: any }) { useHotkeys( "pagedown", - () => isActive && tryAction(onNextClick), + async () => { + if (!isActive) return; + const canWeClose = await (formRef.current as any).cancelUnsavedChanges(); + if (!canWeClose) return; + onNextClick(); + }, { enableOnFormTags: true, preventDefault: true }, - [isActive, tryAction, onNextClick], + [isActive, onNextClick, formRef], ); useHotkeys( "pageup", - () => isActive && tryAction(onPreviousClick), + async () => { + if (!isActive) return; + const canWeClose = await (formRef.current as any).cancelUnsavedChanges(); + if (!canWeClose) return; + onPreviousClick(); + }, { enableOnFormTags: true, preventDefault: true }, - [isActive, tryAction, onPreviousClick], + [isActive, onPreviousClick, formRef], ); useHotkeys( "ctrl+s,command+s", @@ -181,14 +191,22 @@ function FormActionBar({ toolbar }: { toolbar: any }) { ); useHotkeys( "ctrl+l,command+l", - () => { - if (isActive && previousView) { - setPreviousView?.(currentView); - setCurrentView?.(previousView); - } + async () => { + if (!isActive || !previousView) return; + const canWeClose = await (formRef.current as any).cancelUnsavedChanges(); + if (!canWeClose) return; + setPreviousView?.(currentView); + setCurrentView?.(previousView); }, { enableOnFormTags: true, preventDefault: true }, - [isActive, previousView, currentView, setPreviousView, setCurrentView], + [ + isActive, + previousView, + currentView, + setPreviousView, + setCurrentView, + formRef, + ], ); if (!currentView) return null; From b95b2206c0392f1753b115fa28c005b2a6faebf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20G=C3=BCell=20Segarra?= Date: Mon, 27 Jan 2025 13:26:17 +0100 Subject: [PATCH 3/4] fix: revert back to getValues() in openRelate and processAction (#851) https://github.com/gisce/webclient/issues/1713 --- src/actionbar/FormActionBar.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/actionbar/FormActionBar.tsx b/src/actionbar/FormActionBar.tsx index deb76d798..d6f92e227 100644 --- a/src/actionbar/FormActionBar.tsx +++ b/src/actionbar/FormActionBar.tsx @@ -152,7 +152,7 @@ function FormActionBar({ toolbar }: { toolbar: any }) { (actionData: any) => { processAction?.({ actionData, - values: (formRef.current as any).getPlainValues(), + values: (formRef.current as any).getValues(), fields: (formRef.current as any).getFields(), context: (formRef.current as any).getContext(), onRefreshParentValues: () => (formRef.current as any).fetchValues(), @@ -347,7 +347,7 @@ function FormActionBar({ toolbar }: { toolbar: any }) { if (result.succeed) { openRelate({ relateData: relate, - values: (formRef.current as any).getPlainValues(), + values: (formRef.current as any).getValues(), fields: (formRef.current as any).getFields(), action_id: relate.id, action_type: relate.type, From 071daf7f0323dcf5a334b2509a65816e6b77ac2e Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 27 Jan 2025 12:27:46 +0000 Subject: [PATCH 4/4] chore(release): 2.57.5 [skip ci] ## [2.57.5](https://github.com/gisce/react-ooui/compare/v2.57.4...v2.57.5) (2025-01-27) ### Bug Fixes * add unsaved changes check for hotkey navigation actions in form ([#850](https://github.com/gisce/react-ooui/issues/850)) [skip ci] ([2fb5d11](https://github.com/gisce/react-ooui/commit/2fb5d11213afeb4373deca21c469c300b5c33fa3)) * format search date parameters when resuming from URL actions ([#845](https://github.com/gisce/react-ooui/issues/845)) [skip ci] ([0b323a7](https://github.com/gisce/react-ooui/commit/0b323a72f774a3c030c05e178999f65548fbb96d)) * revert back to getValues() in openRelate and processAction ([#851](https://github.com/gisce/react-ooui/issues/851)) ([b95b220](https://github.com/gisce/react-ooui/commit/b95b2206c0392f1753b115fa28c005b2a6faebf7)) --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f2dfdb9a0..12538c0d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/react-ooui", - "version": "2.57.4", + "version": "2.57.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@gisce/react-ooui", - "version": "2.57.4", + "version": "2.57.5", "dependencies": { "@ant-design/colors": "^7.2.0", "@ant-design/plots": "^1.0.9", diff --git a/package.json b/package.json index 49aa265e2..6bbc8bdd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/react-ooui", - "version": "2.57.4", + "version": "2.57.5", "engines": { "node": "20.5.0" },