Skip to content

Commit

Permalink
feat: allow pass and resume domain in /open route
Browse files Browse the repository at this point in the history
gisce/webclient#1612
- Updated GraphActionBar to accept a new optional `domain` prop for improved functionality.
- Modified ShareUrlButton to utilize the `domain` prop, allowing for better sharing context.
- Refactored TreeActionBar to compute `finalDomain` using `useMemo`, optimizing performance.
- Adjusted share URL creation in shareUrlHelper to include `domain` in the URL parameters if provided.
- Updated GraphActionView to pass the merged `domain` to GraphActionBar.
  • Loading branch information
mguellsegarra committed Jan 14, 2025
1 parent dcf74f1 commit 8fc704c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
9 changes: 8 additions & 1 deletion src/actionbar/GraphActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import { View } from "@/types";
import { ShareUrlButton } from "./ShareUrlButton";
import { ActionBarSeparator } from "./FormActionBar";

function GraphActionBar({ refreshGraph }: { refreshGraph: () => void }) {
function GraphActionBar({
refreshGraph,
domain,
}: {
refreshGraph: () => void;
domain?: any[];
}) {
const { t } = useLocale();
const {
availableViews,
Expand Down Expand Up @@ -66,6 +72,7 @@ function GraphActionBar({ refreshGraph }: { refreshGraph: () => void }) {
<ShareUrlButton
action_id={currentView.extra?.action_id}
view_type={currentView.type}
domain={domain}
/>
</Space>
);
Expand Down
20 changes: 13 additions & 7 deletions src/actionbar/ShareUrlButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export type ShareUrlButtonProps = {
action_id?: number;
view_type: ViewType;
res_id?: number;
domain?: any[];
};

export function ShareUrlButton({
action_id,
view_type,
res_id,
domain,
}: ShareUrlButtonProps) {
const { token } = theme.useToken();
const { t } = useLocale();
Expand All @@ -27,6 +29,7 @@ export function ShareUrlButton({
action_id,
view_type,
res_id,
domain,
})
: "";

Expand Down Expand Up @@ -106,12 +109,15 @@ export function ShareUrlButton({
);

return (
<Popover content={popoverContent} trigger="click" placement="bottom">
<ActionButton
icon={<IconShare2 size={16} color={token.colorTextSecondary} />}
disabled={moreDataNeededForCopying}
tooltip={t("share")}
/>
</Popover>
<div style={{ maxHeight: 28 }}>
<Popover content={popoverContent} trigger="click" placement="bottom">
<ActionButton
style={{ height: 28 }}
icon={<IconShare2 size={16} color={token.colorTextSecondary} />}
disabled={moreDataNeededForCopying}
tooltip={t("share")}
/>
</Popover>
</div>
);
}
15 changes: 10 additions & 5 deletions src/actionbar/TreeActionBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useEffect, useState, useRef } from "react";
import { useContext, useEffect, useState, useRef, useMemo } from "react";
import { Space, Spin } from "antd";
import ChangeViewButton from "./ChangeViewButton";
import {
Expand Down Expand Up @@ -207,6 +207,13 @@ function TreeActionBar(props: Props) {
});
}

const finalDomain = useMemo(() => {
return mergeParams(
searchTreeRef?.current?.getDomain() || [],
searchParams || [],
);
}, [searchParams, searchTreeRef]);

return (
<Space wrap={true}>
{treeIsLoading && (
Expand Down Expand Up @@ -426,10 +433,7 @@ function TreeActionBar(props: Props) {
visible={exportModalVisible}
onClose={() => setExportModalVisible(false)}
model={currentModel!}
domain={mergeParams(
searchTreeRef?.current?.getDomain() || [],
searchParams || [],
)}
domain={finalDomain}
limit={limit}
totalRegisters={totalItems || 0}
selectedRegistersToExport={selectedRowItems}
Expand All @@ -442,6 +446,7 @@ function TreeActionBar(props: Props) {
<ShareUrlButton
action_id={currentView.extra?.action_id}
view_type={currentView.type}
domain={finalDomain}
/>
</Space>
);
Expand Down
5 changes: 5 additions & 0 deletions src/helpers/shareUrlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ export const createShareOpenUrl = ({
action_id,
view_type,
res_id,
domain,
}: {
action_id: number;
view_type?: ViewType;
res_id?: number;
domain?: any[];
}) => {
const url = new URL(window.location.href);
url.pathname += url.pathname.endsWith("/") ? "open" : "/open";
url.searchParams.set("action_id", action_id.toString());
view_type && url.searchParams.set("view_type", view_type);
res_id && url.searchParams.set("res_id", res_id?.toString());
domain &&
domain.length > 0 &&
url.searchParams.set("domain", JSON.stringify(domain));
return url.toString();
};
1 change: 1 addition & 0 deletions src/views/actionViews/GraphActionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const GraphActionView = (props: GraphActionViewProps) => {
<>
<TitleHeader title={viewData.title || viewData.name}>
<GraphActionBar
domain={mergeParams(searchParams || [], domain)}
refreshGraph={() => {
(graphRef.current as any).refresh();
}}
Expand Down

0 comments on commit 8fc704c

Please sign in to comment.