Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deeplink Base Url #3375

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/src/components/DashboardWrapper/DashboardWrapper.tsx
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Loading