Skip to content

Commit

Permalink
Merge branch 'fix/adjustments-in-value-filtering-in-urls' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jan 25, 2025
2 parents 199db40 + c79c3e0 commit 33007c8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/helpers/shareUrlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@ 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", "parent_id"];
const IGNORED_PARAMS = ["target", "context", "domain", "fields"];
const ALLOWED_PARAMETERS = [
"model",
"views",
"title",
"initialView",
"action_id",
"action_type",
"res_id",
"limit",
"actionRawData",
"searchParams",
];

export const createShareOpenUrl = (action: ActionInfo) => {
const url = new URL(window.location.origin);
Expand All @@ -15,13 +26,10 @@ export const createShareOpenUrl = (action: ActionInfo) => {
action?.actionRawData && filterActionRawData(action.actionRawData),
};

// Add all non-null properties from action to URL
Object.entries(finalAction).forEach(([key, value]) => {
if (
!IGNORED_PARAMS.includes(key) &&
value &&
(!Array.isArray(value) || value.length > 0)
) {
// Filter allowed parameters and add them to URL
const allowedParams = filterAllowedParameters(finalAction);
Object.entries(allowedParams).forEach(([key, value]) => {
if (value && (!Array.isArray(value) || value.length > 0)) {
url.searchParams.set(key, convertToString(value));
}
});
Expand Down Expand Up @@ -84,6 +92,17 @@ const filterActionRawData = (actionRawData: ActionRawData) => {
return Object.keys(filteredData).length > 0 ? filteredData : undefined;
};

export const filterAllowedParameters = (parameters: any) => {
if (!parameters || typeof parameters !== "object") {
return {};
}
return Object.fromEntries(
Object.entries(parameters).filter(([key]) =>
ALLOWED_PARAMETERS.includes(key),
),
);
};

export const filterAllowedValues = (values: any) => {
if (!values || typeof values !== "object") {
return {};
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ import { ErpAllFeatureKeys, ErpFeatureKeys } from "./models/erpFeature";
import type { ErpFeaturesMap } from "./models/erpFeature";
import { GraphCard } from "./widgets/views/Graph";
import dayjs from "./helpers/dayjs";
import {
filterAllowedParameters,
filterAllowedValues,
} from "./helpers/shareUrlHelper";

export {
Button,
Expand Down Expand Up @@ -183,4 +187,6 @@ export {
Spinner,
Carousel,
ColorPicker,
filterAllowedParameters,
filterAllowedValues,
};

0 comments on commit 33007c8

Please sign in to comment.