Skip to content

Commit 7824d24

Browse files
authored
fix: Deeplink Base Url (#3375)
1 parent 45b28f1 commit 7824d24

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

web/src/components/DashboardWrapper/DashboardWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import {useMemo} from 'react';
22
import {useNavigate} from 'react-router-dom';
33
import DashboardProvider from 'providers/Dashboard';
4+
import {getServerBaseUrl} from 'utils/Common';
45

56
interface IProps {
67
children: React.ReactNode;
78
}
89

910
const DashboardWrapper = ({children}: IProps) => {
1011
const navigate = useNavigate();
11-
const dashboardProviderValue = useMemo(() => ({baseUrl: '', navigate}), [navigate]);
12+
const dashboardProviderValue = useMemo(() => ({baseUrl: '', dashboardUrl: getServerBaseUrl(), navigate}), [navigate]);
1213

1314
return <DashboardProvider value={dashboardProviderValue}>{children}</DashboardProvider>;
1415
};

web/src/components/RunDetailAutomateMethods/methods/DeepLink/hooks/useDeepLink.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import {useCallback, useState} from 'react';
22
import DeepLinkService, {TDeepLinkConfig} from 'services/DeepLink.service';
3+
import {useDashboard} from 'providers/Dashboard/Dashboard.provider';
34

45
const useDeepLink = () => {
56
const [deepLink, setDeepLink] = useState<string>('');
7+
const {dashboardUrl} = useDashboard();
68

7-
const onGetDeepLink = useCallback((config: TDeepLinkConfig) => {
8-
const link = DeepLinkService.getLink(config);
9-
setDeepLink(link);
10-
}, []);
9+
const onGetDeepLink = useCallback(
10+
(config: TDeepLinkConfig) => {
11+
const link = DeepLinkService.getLink({...config, baseUrl: dashboardUrl});
12+
setDeepLink(link);
13+
},
14+
[dashboardUrl]
15+
);
1116

1217
return {deepLink, onGetDeepLink};
1318
};

web/src/providers/Dashboard/Dashboard.provider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import {NavigateFunction} from 'react-router-dom';
44

55
interface IContext {
66
baseUrl: string;
7+
dashboardUrl: string;
78
navigate: NavigateFunction;
89
}
910

1011
export const Context = createContext<IContext>({
1112
baseUrl: '',
13+
dashboardUrl: '',
1214
navigate: noop,
1315
});
1416

web/src/services/DeepLink.service.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import {TVariableSetValue} from 'models/VariableSet.model';
22
import Test from 'models/Test.model';
3-
import {getServerBaseUrl} from '../utils/Common';
3+
import {getServerBaseUrl} from 'utils/Common';
44

55
export type TDeepLinkConfig = {
66
variables: TVariableSetValue[];
77
useVariableSetId: boolean;
88
test: Test;
99
variableSetId?: string;
10+
baseUrl?: string;
1011
};
1112

1213
const DeepLinkService = () => ({
13-
getLink({variables, useVariableSetId, test: {id: testId}, variableSetId}: TDeepLinkConfig) {
14-
const baseUrl = getServerBaseUrl();
14+
getLink({
15+
baseUrl = getServerBaseUrl(),
16+
variables,
17+
useVariableSetId,
18+
test: {id: testId},
19+
variableSetId,
20+
}: TDeepLinkConfig) {
1521
const filteredVariables = variables.filter(variable => !!variable && variable.key);
1622
const stringVariables = encodeURI(JSON.stringify(filteredVariables));
1723

0 commit comments

Comments
 (0)