From 728661850282a8540eaa597b8c653a33d84cc1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Fri, 17 Jan 2025 11:22:33 +0100 Subject: [PATCH] feat: add new handleOpenResourceAction url feature https://github.com/gisce/webclient/issues/1612 --- src/context/TabManagerContext.tsx | 2 +- src/helpers/shareUrlHelper.ts | 6 +++++- src/views/RootView.tsx | 35 +++++++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/context/TabManagerContext.tsx b/src/context/TabManagerContext.tsx index 8cd0065b8..c68a679e9 100644 --- a/src/context/TabManagerContext.tsx +++ b/src/context/TabManagerContext.tsx @@ -1,4 +1,4 @@ -import { ActionInfo, InitialViewData, Tab, View, ViewType } from "@/types"; +import { ActionInfo, Tab, View, ViewType } from "@/types"; import { ShortcutApi } from "@/ui/FavouriteButton"; import React, { useState, useContext, useMemo } from "react"; diff --git a/src/helpers/shareUrlHelper.ts b/src/helpers/shareUrlHelper.ts index 79ace7156..175b2fa3a 100644 --- a/src/helpers/shareUrlHelper.ts +++ b/src/helpers/shareUrlHelper.ts @@ -1,8 +1,12 @@ import { ActionInfo, ActionRawData } from "@/types"; +const OPEN_ACTION_PATH = "openAction"; + export const createShareOpenUrl = (action: ActionInfo) => { const url = new URL(window.location.href); - url.pathname += url.pathname.endsWith("/") ? "open" : "/open"; + url.pathname += url.pathname.endsWith("/") + ? OPEN_ACTION_PATH + : `/${OPEN_ACTION_PATH}`; // Parameters to exclude from the URL const ignoredParams = ["target", "context", "domain"]; diff --git a/src/views/RootView.tsx b/src/views/RootView.tsx index e58efe0c2..d996d8b60 100644 --- a/src/views/RootView.tsx +++ b/src/views/RootView.tsx @@ -43,8 +43,9 @@ function RootView(props: RootViewProps, ref: any) { useImperativeHandle(ref, () => ({ retrieveAndOpenAction, - handleOpenUrl, openShortcut, + handleOpenActionUrl, + handleOpenActionResourceUrl, })); function remove(key: string) { @@ -73,7 +74,7 @@ function RootView(props: RootViewProps, ref: any) { tabViewsCloseFunctions.current.set(tabKey, canWeClose); } - async function handleOpenUrl(action: ActionInfo) { + async function handleOpenActionUrl(action: ActionInfo) { const { actionRawData } = action; let parsedContext; @@ -129,6 +130,36 @@ function RootView(props: RootViewProps, ref: any) { }); } + async function handleOpenActionResourceUrl({ + model, + view_id, + res_id, + }: { + model: string; + res_id: number; + view_id?: number; + }) { + const view = await ConnectionProvider.getHandler().getView({ + model, + id: view_id || undefined, + type: "form", + context: rootContext, + }); + + return await openAction({ + action_id: -1, + action_type: "ir.actions.act_window", + model, + views: [[view.view_id, "form"]], + context: rootContext, + domain: [], + title: view.title || model, + target: "current", + initialView: { id: view.view_id, type: "form" }, + res_id, + }); + } + async function retrieveAndOpenAction({ action, values,