Skip to content

Commit

Permalink
Merge pull request #36 from wenytang-ms/wenyt/deeplink
Browse files Browse the repository at this point in the history
feat: support the deeplink to connect data plane api to vscode extension for api center
  • Loading branch information
Bruce-Moe authored Sep 9, 2024
2 parents c8052ff + 8edb32e commit 9ff1b8e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ import css from "./index.module.scss";
const Header = () => {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const dataApiEndpoint = useLocalStorage(LocalStorageKey.dataApiEndpoint);
const dataApiClientId = useLocalStorage(LocalStorageKey.dataApiClientId);
const dataApiTenantId = useLocalStorage(LocalStorageKey.dataApiTenantId);
const [config, setConfig] = useState<Settings>();
const configService = useConfigService();
const authService = useAuthService();
const session = useSession();

const fetchConfig = async () => {
const config = await configService.getSettings();
setConfig(config);
dataApiEndpoint.set(config.dataApiHostName);

dataApiClientId.set(config.authentication.clientId);
dataApiTenantId.set(config.authentication.tenantId);
const isAuthenticatedResponse = await authService.isAuthenticated();
setIsAuthenticated(isAuthenticatedResponse);
};
Expand Down
8 changes: 5 additions & 3 deletions src/routes/Main/ApisList/ApisCards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
MoreHorizontalRegular,
ShareRegular,
} from "@fluentui/react-icons";

import { LocalStorageKey, useLocalStorage } from "../../../../util/useLocalStorage";
import VsCodeLogo from "../../../../components/logos/VsCodeLogo";
import { Api } from "../../../../contracts/api";

Expand Down Expand Up @@ -57,7 +57,9 @@ const ShareSubmenu: FC<{ shareLink: string; onLinkCopy: (isCopied: boolean) => v
const ApiCard: FC<{ api: Api }> = ({ api }) => {
const navigate = useNavigate();
const [isCopied, setIsCopied] = useState<boolean>(false);

const dataApiEndpoint = useLocalStorage(LocalStorageKey.dataApiEndpoint).get()?.split('/')[0];
const dataApiClientId = useLocalStorage(LocalStorageKey.dataApiClientId).get();
const dataApiTenantId = useLocalStorage(LocalStorageKey.dataApiTenantId).get();
return (
<Tooltip
content={
Expand Down Expand Up @@ -100,7 +102,7 @@ const ApiCard: FC<{ api: Api }> = ({ api }) => {
icon={<VsCodeLogo />}
onClick={e => {
e.stopPropagation();
window.open(`vscode:extension/apidev.azure-api-center`);
window.open(`vscode://apidev.azure-api-center?clientId=${dataApiClientId}&tenantId=${dataApiTenantId}&runtimeUrl=${dataApiEndpoint}`);
}}
>
Open in Visual Studio Code
Expand Down
4 changes: 4 additions & 0 deletions src/util/useLocalStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export enum LocalStorageKey {
searchRecents = "searchRecents",
dataApiEndpoint = "dataApiEndpoint",
isRestricted = "isRestricted",
dataApiClientId = "dataApiClientId",
dataApiTenantId = "dataApiTenantId",
}

type TLocalStorageValuesMap = {
Expand All @@ -23,6 +25,8 @@ type TLocalStorageValuesMap = {
[LocalStorageKey.searchRecents]: string;
[LocalStorageKey.dataApiEndpoint]: string;
[LocalStorageKey.isRestricted]: string;
[LocalStorageKey.dataApiClientId]: string;
[LocalStorageKey.dataApiTenantId]: string;
};

const LocalStorageContext = createContext<{ iterator?: number; update?: Dispatch<SetStateAction<number>> }>({
Expand Down

0 comments on commit 9ff1b8e

Please sign in to comment.