Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sync changes from v2 to v2-develop #855

Merged
merged 7 commits into from
Jan 27, 2025
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gisce/react-ooui",
"version": "2.58.0-rc.2",
"version": "2.58.0",
"engines": {
"node": "20.5.0"
},
Expand Down
42 changes: 30 additions & 12 deletions src/actionbar/FormActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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",
Expand All @@ -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;
Expand Down Expand Up @@ -329,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,
Expand Down
9 changes: 6 additions & 3 deletions src/context/ActionViewContext.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -132,7 +132,10 @@ const ActionViewProvider = (props: ActionViewProviderProps): any => {
const [graphIsLoading, setGraphIsLoading] = useState<boolean>(true);
const [previousView, setPreviousView] = useState<View>();
const [searchValues, setSearchValues] = useState<any>(
convertParamsToValues(initialSearchParams || []),
convertParamsToValues(
initialSearchParams || [],
(currentView as TreeView).fields,
),
);
const [treeFirstVisibleRow, setTreeFirstVisibleRow] = useState<number>(0);
const [searchQuery, setSearchQuery] = useState<SearchQueryParams>();
Expand Down
8 changes: 6 additions & 2 deletions src/context/ContentRootContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const ContentRootProvider = (

useImperativeHandle(ref, () => ({
openActionModal,
processAction,
}));

// Action modal state
Expand Down Expand Up @@ -177,7 +178,9 @@ const ContentRootProvider = (
onRefreshParentValues?: any;
}) {
const { type } = actionData;
onRefreshParentValues.current.push(onRefreshParentValuesFn);
if (onRefreshParentValuesFn) {
onRefreshParentValues.current.push(onRefreshParentValuesFn);
}

if (type === "ir.actions.report.xml") {
return await generateReport({
Expand Down Expand Up @@ -230,7 +233,7 @@ const ContentRootProvider = (
fields,
values: { ...values, ...globalValues },
})
: actionData.context;
: actionData?.context || {};

const mergedContext = {
...context,
Expand Down Expand Up @@ -290,6 +293,7 @@ const ContentRootProvider = (
initialView,
action_id: actionData.id,
action_type: actionData.type,
res_id: actionData.res_id,
actionRawData: {
context: rawContext,
domain: rawDomain,
Expand Down
69 changes: 69 additions & 0 deletions src/helpers/searchHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dayjs from "@/helpers/dayjs";

const convertBooleanParamIfNeeded = (value: any) => {
if ((typeof value === "string" && value === "true") || value === "false") {
return value === "true";
Expand Down Expand Up @@ -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);
};
1 change: 1 addition & 0 deletions src/views/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function RootView(props: RootViewProps, ref: any) {
useImperativeHandle(ref, () => ({
retrieveAndOpenAction,
openShortcut,
processAction: (contentRootProvider.current as any).processAction,
handleOpenActionUrl,
handleOpenActionResourceUrl,
}));
Expand Down
30 changes: 1 addition & 29 deletions src/widgets/views/searchFilter/SideSearchFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -255,31 +255,3 @@ export const SideSearchFooter = ({
</div>
);
};

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;
}, {}),
);
};
Loading