Skip to content

Commit

Permalink
Merge pull request #847 from gisce/sync/v2-to-v2-develop-20250124-144903
Browse files Browse the repository at this point in the history
fix: sync changes from v2 to v2-develop
  • Loading branch information
mguellsegarra authored Jan 24, 2025
2 parents ff26ccd + df5d64c commit 973f435
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 40 deletions.
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.1",
"version": "2.57.4",
"engines": {
"node": "20.5.0"
},
Expand Down
4 changes: 2 additions & 2 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).getValues(),
values: (formRef.current as any).getPlainValues(),
fields: (formRef.current as any).getFields(),
context: (formRef.current as any).getContext(),
onRefreshParentValues: () => (formRef.current as any).fetchValues(),
Expand Down Expand Up @@ -329,7 +329,7 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
if (result.succeed) {
openRelate({
relateData: relate,
values: (formRef.current as any).getValues(),
values: (formRef.current as any).getPlainValues(),
fields: (formRef.current as any).getFields(),
action_id: relate.id,
action_type: relate.type,
Expand Down
14 changes: 13 additions & 1 deletion src/context/TabManagerContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ActionInfo, Tab, View, ViewType } from "@/types";
import { ShortcutApi } from "@/ui/FavouriteButton";
import React, { useState, useContext, useMemo } from "react";
import React, { useState, useContext, useMemo, useEffect } from "react";
import { useConfigContext } from "./ConfigContext";

export type TabManagerContextType = {
openAction: (action: ActionInfo) => void;
Expand Down Expand Up @@ -69,6 +70,17 @@ const TabManagerProvider = (props: TabManagerProviderProps): any => {
const currentTab = useMemo(() => {
return tabs.find((t) => t.key === activeKey);
}, [tabs, activeKey]);
const { title } = useConfigContext();

const noTabs = useMemo(() => {
return !(tabs?.length > 0);
}, [tabs]);

useEffect(() => {
if (noTabs) {
document.title = title;
}
}, [noTabs, title]);

return (
<TabManagerContext.Provider
Expand Down
35 changes: 19 additions & 16 deletions src/helpers/shareUrlHelper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ActionInfo, ActionRawData } from "@/types";

const OPEN_ACTION_PATH = "action";
// Parameters to exclude from the URL
const ALLOWED_VALUES_KEYS = ["active_id", "active_ids", "id"];
const IGNORED_PARAMS = ["target", "context", "domain", "fields"];

export const createShareOpenUrl = (action: ActionInfo) => {
const url = new URL(window.location.origin);
url.pathname = OPEN_ACTION_PATH;

// Parameters to exclude from the URL
const ignoredParams = ["target", "context", "domain"];

const finalAction = {
...action,
actionRawData:
Expand All @@ -18,7 +18,7 @@ export const createShareOpenUrl = (action: ActionInfo) => {
// Add all non-null properties from action to URL
Object.entries(finalAction).forEach(([key, value]) => {
if (
!ignoredParams.includes(key) &&
!IGNORED_PARAMS.includes(key) &&
value &&
(!Array.isArray(value) || value.length > 0)
) {
Expand All @@ -37,7 +37,7 @@ const convertToString = (value: any): string => {
};

const filterActionRawData = (actionRawData: ActionRawData) => {
const { context, domain, values, fields } = actionRawData;
const { context, domain, values } = actionRawData;

const filteredData: Partial<ActionRawData> = {};

Expand Down Expand Up @@ -67,25 +67,28 @@ const filterActionRawData = (actionRawData: ActionRawData) => {
}
}

// Include values and fields only if they are non-empty objects
// Include values only if they are non-empty objects
if (
(filteredData.domain || filteredData.context) &&
values &&
typeof values === "object" &&
Object.keys(values).length > 0
) {
const { arch, ...restValues } = values; // ignore arch if exists
filteredData.values = restValues;
}
if (
(filteredData.domain || filteredData.context) &&
fields &&
typeof fields === "object" &&
Object.keys(fields).length > 0
) {
filteredData.fields = fields;
// Only include allowed keys from values
const filteredValues = filterAllowedValues(values);
filteredData.values =
Object.keys(filteredValues).length > 0 ? filteredValues : undefined;
}

// Return undefined if no properties were added to filteredData
return Object.keys(filteredData).length > 0 ? filteredData : undefined;
};

export const filterAllowedValues = (values: any) => {
if (!values || typeof values !== "object") {
return {};
}
return Object.fromEntries(
Object.entries(values).filter(([key]) => ALLOWED_VALUES_KEYS.includes(key)),
);
};
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ type GetViewRequest = {

type GetFieldsRequest = {
model: string;
fields: string[];
fields?: string[];
context?: any;
};

Expand Down
53 changes: 40 additions & 13 deletions src/views/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { nanoid } from "nanoid";
import { useLocale } from "@gisce/react-formiga-components";
import { useConfigContext } from "@/context/ConfigContext";
import { DEFAULT_SEARCH_LIMIT } from "@/models/constants";
import { filterAllowedValues } from "@/helpers/shareUrlHelper";

type RootViewProps = {
children: ReactNode;
Expand Down Expand Up @@ -75,7 +76,28 @@ function RootView(props: RootViewProps, ref: any) {
}

async function handleOpenActionUrl(action: ActionInfo) {
const { actionRawData } = action;
const { actionRawData, res_id, initialView } = action;

const fields = await ConnectionProvider.getHandler().getFields({
model: action.model,
context: rootContext,
});

let values: Record<string, any> = filterAllowedValues(
actionRawData?.values,
);

const finalIdToRead: number | undefined =
res_id || values.active_id || values.id;

if (finalIdToRead) {
const readObjects = await ConnectionProvider.getHandler().readObjects({
model: action.model,
context: rootContext,
ids: [finalIdToRead],
});
values = { ...values, ...readObjects[0] };
}

let parsedContext;
if (
Expand All @@ -84,14 +106,16 @@ function RootView(props: RootViewProps, ref: any) {
actionRawData.context !== null
) {
parsedContext = actionRawData;
} else {
} else if (actionRawData && actionRawData.context) {
parsedContext =
actionRawData &&
parseContext({
context: actionRawData.context,
fields: actionRawData.fields || {},
values: { ...globalValues, ...(actionRawData.values || {}) },
fields,
values: { ...globalValues, ...(values || {}) },
});
} else {
parsedContext = {};
}

const parsedDomain = await (async () => {
Expand All @@ -102,17 +126,16 @@ function RootView(props: RootViewProps, ref: any) {
actionRawData.domain.length > 0
) {
return actionRawData.domain;
} else if (actionRawData && !Array.isArray(actionRawData.domain)) {
} else if (
actionRawData &&
actionRawData.domain &&
!Array.isArray(actionRawData.domain)
) {
return await ConnectionProvider.getHandler().evalDomain({
domain: actionRawData.domain,
values: actionRawData.fields
? transformPlainMany2Ones({
fields: actionRawData.fields,
values: { ...(actionRawData.values || {}), ...globalValues },
})
: {},
values: { ...(values || {}), ...globalValues },
context: { ...rootContext, ...parsedContext },
fields: actionRawData.fields,
fields,
});
}
return [];
Expand All @@ -126,7 +149,11 @@ function RootView(props: RootViewProps, ref: any) {
...action,
context: { ...rootContext, ...parsedContext },
domain: parsedDomain,
actionRawData,
actionRawData: {
...actionRawData,
values,
fields,
},
});
}

Expand Down
11 changes: 7 additions & 4 deletions src/widgets/views/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,13 @@ function Form(props: FormProps, ref: any) {
);
};

const getCurrentValues = (fields: any) => {
const currentValues = antForm.getFieldsValue(true);
return processValues(currentValues, fields);
};
const getCurrentValues = useCallback(
(fields: any) => {
const currentValues = antForm.getFieldsValue(true);
return processValues(currentValues, fields);
},
[antForm],
);

const setFieldValue = (field: string, value?: string) => {
assignNewValuesToForm({
Expand Down

0 comments on commit 973f435

Please sign in to comment.