Skip to content

Commit

Permalink
feat: add new handleOpenResourceAction url feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mguellsegarra committed Jan 17, 2025
1 parent 53aa776 commit 7286618
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/context/TabManagerContext.tsx
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
6 changes: 5 additions & 1 deletion src/helpers/shareUrlHelper.ts
Original file line number Diff line number Diff line change
@@ -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"];
Expand Down
35 changes: 33 additions & 2 deletions src/views/RootView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ function RootView(props: RootViewProps, ref: any) {

useImperativeHandle(ref, () => ({
retrieveAndOpenAction,
handleOpenUrl,
openShortcut,
handleOpenActionUrl,
handleOpenActionResourceUrl,
}));

function remove(key: string) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7286618

Please sign in to comment.