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

Configurable debugUrl #221

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 13 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const WebhookList = React.lazy(
() => import("./WebhookDisplay/WebhookList.component")
);
import { ApolloProvider } from "@apollo/client";
import { WebhookStoreUrlContext } from "./NavBar/WebhookStoreUrl/WebhookStoreUrl.context";
import { WebhookContext } from "./NavBar/WebhookContext/WebhookContext";
import { createApolloClient } from "./apollo.client";
import { useStateInLocalStorage } from "./use-state-with-local-storage.hook";
import { isValidHttpUrl } from "./utils/is-valid-url";
Expand All @@ -31,11 +31,19 @@ export default function App() {
isValidHttpUrl
);

const [debugUrl, setDebugUrl] = useStateInLocalStorage(
"debugUrl",
"http://localhost:8010/proxy",
isValidHttpUrl
);

return (
<WebhookStoreUrlContext.Provider
<WebhookContext.Provider
value={{
value: webhookStoreUrl,
setValue: setWebhooksStoreUrl,
webhookStoreUrl,
setWebhooksStoreUrl,
debugUrl,
setDebugUrl,
}}
>
<ApolloProvider client={createApolloClient(webhookStoreUrl)}>
Expand All @@ -47,6 +55,6 @@ export default function App() {
</Suspense>
</Theme>
</ApolloProvider>
</WebhookStoreUrlContext.Provider>
</WebhookContext.Provider>
);
}
28 changes: 28 additions & 0 deletions src/NavBar/DebugUrl/DebugUrl.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Label } from "@pluralsight/ps-design-system-text";
import TextInput from "@pluralsight/ps-design-system-textinput";
import React, { useContext } from "react";
import { WebhookContext } from "../WebhookContext/WebhookContext";
import NavItem from "@pluralsight/ps-design-system-navitem";

export function DebugUrlInput() {
const { debugUrl, setDebugUrl } = useContext(WebhookContext);
return (
<NavItem key={"DebugUrlInput"}>
<Label
size={Label.sizes.xSmall}
style={{ marginRight: "8px", marginLeft: "8px" }}
>
Debug Destination URL:
</Label>
<TextInput
appearance={TextInput.appearances.subtle}
placeholder="http://localhost:8010/proxy"
size={TextInput.sizes.small}
defaultValue={debugUrl}
onBlur={(event) => {
setDebugUrl(event.target.value);
}}
></TextInput>
</NavItem>
);
}
4 changes: 2 additions & 2 deletions src/NavBar/StoreConfig/StoreConfigNavItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from "@pluralsight/ps-design-system-button";
import { StoreConfigInnerDialog } from "./StoreConfigDialog";
import Dialog from "@pluralsight/ps-design-system-dialog";
import useFetch from "use-http";
import { WebhookStoreUrlContext } from "../WebhookStoreUrl/WebhookStoreUrl.context";
import { WebhookContext } from "../WebhookContext/WebhookContext";
import { ACCESS_TOKEN_KEY, IDENTITY_TOKEN_KEY } from "../../local-storage";
import { decodeJWT } from "../../utils/decode-jwt";

Expand All @@ -27,7 +27,7 @@ export const StoreConfigNavItem = () => {
userHasAccessToStore: boolean;
}>({ userHasAccessToStore: false });

const { value: webhookStoreUrl } = useContext(WebhookStoreUrlContext);
const { webhookStoreUrl } = useContext(WebhookContext);
const accessToken = localStorage.getItem(ACCESS_TOKEN_KEY);
const { get, response } = useFetch(new URL(webhookStoreUrl).origin, {
headers: accessToken ? { Authorization: `Bearer ${accessToken}` } : {},
Expand Down
8 changes: 8 additions & 0 deletions src/NavBar/WebhookContext/WebhookContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";

export const WebhookContext = React.createContext({
webhookStoreUrl: "https://webhook-store.herokuapp.com",
setWebhooksStoreUrl: (_newValue: string) => {},
debugUrl: "http://localhost:8010/proxy",
setDebugUrl: (_newValue: string) => {},
});
8 changes: 4 additions & 4 deletions src/NavBar/WebhookStoreUrl/WebhookStoreUrl.component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Label } from "@pluralsight/ps-design-system-text";
import TextInput from "@pluralsight/ps-design-system-textinput";
import React, { useContext } from "react";
import { WebhookStoreUrlContext } from "./WebhookStoreUrl.context";
import { WebhookContext } from "../WebhookContext/WebhookContext";
import NavItem from "@pluralsight/ps-design-system-navitem";

export function WebhookStoreUrlInput() {
const { value, setValue } = useContext(WebhookStoreUrlContext);
const { webhookStoreUrl, setWebhooksStoreUrl } = useContext(WebhookContext);
return (
<NavItem key={"WebhookStoreUrlInput"}>
<Label
Expand All @@ -18,9 +18,9 @@ export function WebhookStoreUrlInput() {
appearance={TextInput.appearances.subtle}
placeholder="https://webhook-store.herokuapp.com"
size={TextInput.sizes.small}
defaultValue={value}
defaultValue={webhookStoreUrl}
onBlur={(event) => {
setValue(new URL(event.target.value).origin);
setWebhooksStoreUrl(new URL(event.target.value).origin);
}}
></TextInput>
</NavItem>
Expand Down
8 changes: 0 additions & 8 deletions src/NavBar/WebhookStoreUrl/WebhookStoreUrl.context.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/TopNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import NavItem from "@pluralsight/ps-design-system-navitem";
import { ProxyStatus } from "./NavBar/ProxyStatus/ProxyStatus.component";
import { LoginOrDisplayUser } from "./NavBar/User/LoginOrDisplayUser";
import { StoreConfigNavItem } from "./NavBar/StoreConfig/StoreConfigNavItem";
import { DebugUrlInput } from "./NavBar/DebugUrl/DebugUrl.component";
import { ENVIRONMENT_KEY } from "./local-storage";

function SkillsLogo() {
Expand Down Expand Up @@ -73,6 +74,7 @@ export default function TopNav() {
brand={<SkillsBranding />}
items={[
isDevEnv ? <WebhookStoreUrlInput key={"WebhookStoreUrlInput"} /> : null,
<DebugUrlInput key={"DebugUrlInput"} />,
<ProxyStatus key={"ProxyStatus"} />,
<StoreConfigNavItem key={"StoreConfig"} />,
]}
Expand Down
4 changes: 2 additions & 2 deletions src/WebhookDisplay/WebhookList.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "react-table";
import { forwardWebhookToLocalhost } from "../forward-to-localhost";
import posthog from "posthog-js";
import { WebhookStoreUrlContext } from "../NavBar/WebhookStoreUrl/WebhookStoreUrl.context";
import { WebhookContext } from "../NavBar/WebhookContext/WebhookContext";
import { UpdateQueryFn } from "@apollo/client/core/watchQueryOptions";

const largePayloadCellStyle: React.CSSProperties = {
Expand Down Expand Up @@ -153,7 +153,7 @@ const WebhookList: React.FC = () => {
const { data, subscribeToMore } = useQuery<QueryWebhook>(QUERY_WEBHOOKS, {
variables: { first: 100, path },
});
const { value: webhookStoreUrl } = useContext(WebhookStoreUrlContext);
const { webhookStoreUrl } = useContext(WebhookContext);
useEffect(() => {
const unsuscribe = subscribeToMore<SubscriptionWebhook>({
document: COMMENTS_SUBSCRIPTION,
Expand Down
7 changes: 4 additions & 3 deletions src/WebhookDisplay/WebhookPanel.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import {
} from "@pluralsight/ps-design-system-layout";
import Link from "@pluralsight/ps-design-system-link";
import { Heading, P } from "@pluralsight/ps-design-system-text";
import React, { useState } from "react";
import React, { useContext, useState } from "react";
import { Code } from "../Code";
import { forwardWebhookToLocalhost } from "../forward-to-localhost";
import { Webhook } from "./WebhookList.component";
import { WebhookContext } from "../NavBar/WebhookContext/WebhookContext";

export const WebhookPanel: React.FC<{
webhook: Webhook;
}> = ({ webhook }) => {
const baseUrl = "http://localhost:8010/proxy";
const { debugUrl } = useContext(WebhookContext);

const [webhookResponse, setWebhookResponse] = useState<{
code?: number;
Expand Down Expand Up @@ -47,7 +48,7 @@ export const WebhookPanel: React.FC<{
<Button
key="forwardWebhookToLocalhost"
onClick={() => {
forwardWebhookToLocalhost(baseUrl, webhook, setWebhookResponse);
forwardWebhookToLocalhost(debugUrl, webhook, setWebhookResponse);
}}
>
Send
Expand Down