Skip to content

Commit

Permalink
fix: Deeplink Base Url (#3375)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Nov 17, 2023
1 parent 45b28f1 commit 7824d24
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
3 changes: 2 additions & 1 deletion web/src/components/DashboardWrapper/DashboardWrapper.tsx
@@ -1,14 +1,15 @@
import {useMemo} from 'react';
import {useNavigate} from 'react-router-dom';
import DashboardProvider from 'providers/Dashboard';
import {getServerBaseUrl} from 'utils/Common';

interface IProps {
children: React.ReactNode;
}

const DashboardWrapper = ({children}: IProps) => {
const navigate = useNavigate();
const dashboardProviderValue = useMemo(() => ({baseUrl: '', navigate}), [navigate]);
const dashboardProviderValue = useMemo(() => ({baseUrl: '', dashboardUrl: getServerBaseUrl(), navigate}), [navigate]);

return <DashboardProvider value={dashboardProviderValue}>{children}</DashboardProvider>;
};
Expand Down
@@ -1,13 +1,18 @@
import {useCallback, useState} from 'react';
import DeepLinkService, {TDeepLinkConfig} from 'services/DeepLink.service';
import {useDashboard} from 'providers/Dashboard/Dashboard.provider';

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

const onGetDeepLink = useCallback((config: TDeepLinkConfig) => {
const link = DeepLinkService.getLink(config);
setDeepLink(link);
}, []);
const onGetDeepLink = useCallback(
(config: TDeepLinkConfig) => {
const link = DeepLinkService.getLink({...config, baseUrl: dashboardUrl});
setDeepLink(link);
},
[dashboardUrl]
);

return {deepLink, onGetDeepLink};
};
Expand Down
2 changes: 2 additions & 0 deletions web/src/providers/Dashboard/Dashboard.provider.tsx
Expand Up @@ -4,11 +4,13 @@ import {NavigateFunction} from 'react-router-dom';

interface IContext {
baseUrl: string;
dashboardUrl: string;
navigate: NavigateFunction;
}

export const Context = createContext<IContext>({
baseUrl: '',
dashboardUrl: '',
navigate: noop,
});

Expand Down
12 changes: 9 additions & 3 deletions web/src/services/DeepLink.service.ts
@@ -1,17 +1,23 @@
import {TVariableSetValue} from 'models/VariableSet.model';
import Test from 'models/Test.model';
import {getServerBaseUrl} from '../utils/Common';
import {getServerBaseUrl} from 'utils/Common';

export type TDeepLinkConfig = {
variables: TVariableSetValue[];
useVariableSetId: boolean;
test: Test;
variableSetId?: string;
baseUrl?: string;
};

const DeepLinkService = () => ({
getLink({variables, useVariableSetId, test: {id: testId}, variableSetId}: TDeepLinkConfig) {
const baseUrl = getServerBaseUrl();
getLink({
baseUrl = getServerBaseUrl(),
variables,
useVariableSetId,
test: {id: testId},
variableSetId,
}: TDeepLinkConfig) {
const filteredVariables = variables.filter(variable => !!variable && variable.key);
const stringVariables = encodeURI(JSON.stringify(filteredVariables));

Expand Down

0 comments on commit 7824d24

Please sign in to comment.