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

fix: sync changes from v2 to v2-develop #853

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.57.5",
"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
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);
};
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