Skip to content

Commit

Permalink
Merge pull request #93 from atlassian/main
Browse files Browse the repository at this point in the history
[pull] main from atlassian:main
  • Loading branch information
ammar-ahmed-butt authored Oct 26, 2023
2 parents 4a9487e + 888e412 commit fa6dd04
Show file tree
Hide file tree
Showing 54 changed files with 1,268 additions and 294 deletions.
2 changes: 1 addition & 1 deletion github-for-jira.sd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ environmentOverrides:
- type: lambda
name: auto-deployment-github-app
attributes:
runtime: nodejs14.x
runtime: nodejs18.x
prefetchMicrosEnvVars: true
artifact: "_sox/github-for-jira/auto-deployment-github-app-${BITBUCKET_BUILD_NUMBER}.zip"
handler: auto-deployment.handler
Expand Down
3 changes: 3 additions & 0 deletions spa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
"@atlaskit/heading": "^1.3.7",
"@atlaskit/icon": "^21.12.4",
"@atlaskit/lozenge": "^11.4.3",
"@atlaskit/modal-dialog": "^12.8.3",
"@atlaskit/page-header": "^10.4.4",
"@atlaskit/select": "^16.5.7",
"@atlaskit/skeleton": "^0.2.3",
"@atlaskit/spinner": "^15.6.1",
"@atlaskit/textarea": "^4.7.7",
"@atlaskit/tokens": "^1.11.1",
"@atlaskit/tooltip": "^17.8.3",
"@emotion/styled": "^11.11.0",
Expand Down
50 changes: 30 additions & 20 deletions spa/src/analytics/analytics-proxy-client.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
import { AnalyticClient, ScreenEventProps, TrackEventProps, UIEventProps } from "./types";
import { axiosRest } from "../api/axiosInstance";
import { axiosRest, axiosRestWithNoJwt } from "../api/axiosInstance";
import { reportError } from "../utils";
const sendAnalytics = (eventType: string, eventProperties: Record<string, unknown>, eventAttributes?: Record<string, unknown>) => {
axiosRest.post(`/rest/app/cloud/analytics-proxy`,
{
eventType,
eventProperties,
eventAttributes
}).catch(e => {
reportError(e, {
path: "sendAnalytics",
eventType,
...eventProperties,
...eventAttributes
const sendAnalytics = (eventType: string, eventProperties: Record<string, unknown>, eventAttributes?: Record<string, unknown>, requestId?: string) => {
const eventData = {
eventType,
eventProperties,
eventAttributes
};
const eventError = {
path: "sendAnalytics",
eventType,
...eventProperties,
...eventAttributes
};

if (requestId) {
axiosRestWithNoJwt.post(`/rest/app/cloud/deferred/analytics-proxy/${requestId}`, eventData)
.catch(e => {
reportError(e, eventError);
});
});
} else {
axiosRest.post(`/rest/app/cloud/analytics-proxy`, eventData)
.catch(e => {
reportError(e, eventError);
});
}
};
export const analyticsProxyClient: AnalyticClient = {
sendScreenEvent: function(eventProps: ScreenEventProps, attributes?: Record<string, unknown>) {
sendAnalytics("screen", eventProps, attributes);
sendScreenEvent: function(eventProps: ScreenEventProps, attributes?: Record<string, unknown>, requestId?: string) {
sendAnalytics("screen", eventProps, attributes, requestId);
},
sendUIEvent: function (eventProps: UIEventProps, attributes?: Record<string, unknown>) {
sendUIEvent: function (eventProps: UIEventProps, attributes?: Record<string, unknown>, requestId?: string) {
sendAnalytics("ui", {
...eventProps,
source: "spa"
}, attributes);
}, attributes, requestId);
},
sendTrackEvent: function (eventProps: TrackEventProps, attributes?: Record<string, unknown>) {
sendTrackEvent: function (eventProps: TrackEventProps, attributes?: Record<string, unknown>, requestId?: string) {
sendAnalytics("track", {
...eventProps,
source: "spa"
}, attributes);
}, attributes, requestId);
}
};
18 changes: 12 additions & 6 deletions spa/src/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ type UIEventActionSubject =
| "connectOrganisation" | "installToNewOrganisation"
| "checkBackfillStatus"
| "dropExperienceViaBackButton"
| "checkOrgAdmin"
| "learnAboutIssueLinking" | "learnAboutDevelopmentWork";
| "learnAboutIssueLinking" | "learnAboutDevelopmentWork"
| "checkOrgAdmin" | "generateDeferredInstallationLink"
| "closedDeferredInstallationModal" | "copiedDeferredInstallationUrl"
| "signInAndConnectThroughDeferredInstallationStartScreen";

export type UIEventProps = {
actionSubject: UIEventActionSubject,
Expand All @@ -17,7 +19,11 @@ export type ScreenNames =
"StartConnectionEntryScreen"
| "AuthorisationScreen"
| "OrganisationConnectionScreen"
| "SuccessfulConnectedScreen";
| "SuccessfulConnectedScreen"
| "DeferredInstallationModal"
| "DeferredInstallationStartScreen"
| "DeferredInstallationFailedScreen"
| "DeferredInstallationSuccessScreen";

type TrackEventActionSubject =
"finishOAuthFlow"
Expand All @@ -35,8 +41,8 @@ export type ScreenEventProps = {
};

export type AnalyticClient = {
sendScreenEvent: (eventProps: ScreenEventProps, attributes?: Record<string, unknown>) => void;
sendUIEvent: (eventProps: UIEventProps, attributes?: Record<string, unknown>) => void;
sendTrackEvent: (eventProps: TrackEventProps, attributes?: Record<string, unknown>) => void;
sendScreenEvent: (eventProps: ScreenEventProps, attributes?: Record<string, unknown>, requestId?: string) => void;
sendUIEvent: (eventProps: UIEventProps, attributes?: Record<string, unknown>, requestId?: string) => void;
sendTrackEvent: (eventProps: TrackEventProps, attributes?: Record<string, unknown>, requestId?: string) => void;
};

6 changes: 3 additions & 3 deletions spa/src/api/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GetRedirectUrlResponse, ExchangeTokenResponse } from "rest-interfaces";
import { axiosRest } from "../axiosInstance";
import { axiosRestWithNoJwt } from "../axiosInstance";

export default {
generateOAuthUrl: () => axiosRest.get<GetRedirectUrlResponse>("/rest/app/cloud/oauth/redirectUrl"),
exchangeToken: (code: string, state: string) => axiosRest.post<ExchangeTokenResponse>("/rest/app/cloud/oauth/exchangeToken", { code, state }),
generateOAuthUrl: () => axiosRestWithNoJwt.get<GetRedirectUrlResponse>("/rest/app/cloud/oauth/redirectUrl"),
exchangeToken: (code: string, state: string) => axiosRestWithNoJwt.post<ExchangeTokenResponse>("/rest/app/cloud/oauth/exchangeToken", { code, state }),
};
11 changes: 11 additions & 0 deletions spa/src/api/axiosInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { getJiraJWT } from "../utils";

const THIRTY_SECONDS_IN_MS = 30_000;

const axiosRestWithNoJwt = axios.create({ timeout: THIRTY_SECONDS_IN_MS });
const axiosRest = axios.create({
timeout: THIRTY_SECONDS_IN_MS
});
Expand Down Expand Up @@ -47,9 +48,19 @@ axiosRestWithGitHubToken.interceptors.request.use(async (config) => {
return config;
});

const axiosRestWithNoJwtButWithGitHubToken = axios.create({
timeout: THIRTY_SECONDS_IN_MS
});
axiosRestWithNoJwtButWithGitHubToken.interceptors.request.use(async (config) => {
config.headers["github-auth"] = gitHubToken;
return config;
});

export {
axiosGitHub,
axiosRest,
axiosRestWithNoJwt,
axiosRestWithNoJwtButWithGitHubToken,
axiosRestWithGitHubToken,
clearGitHubToken,
setGitHubToken,
Expand Down
14 changes: 14 additions & 0 deletions spa/src/api/deferral/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
DeferralParsedRequest,
DeferredInstallationUrlParams,
GetDeferredInstallationUrl
} from "rest-interfaces";
import { axiosRest, axiosRestWithNoJwt, axiosRestWithNoJwtButWithGitHubToken } from "../axiosInstance";

export default {
parseDeferredRequestId: (requestId: string) => axiosRestWithNoJwt.get<DeferralParsedRequest>(`/rest/app/cloud/deferred/parse/${requestId}`),
getDeferredInstallationUrl: (params: DeferredInstallationUrlParams) =>
axiosRest.get<GetDeferredInstallationUrl>("/rest/app/cloud/deferred/installation-url", { params }),
connectDeferredOrg: (requestId: string) => axiosRestWithNoJwtButWithGitHubToken.post(`/rest/app/cloud/deferred/connect/${requestId}`)
};

2 changes: 2 additions & 0 deletions spa/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import App from "./apps";
import Orgs from "./orgs";
import GitHub from "./github";
import Subscription from "./subscriptions";
import Deferral from "./deferral";

const ApiRequest = {
token: Token,
auth: Auth,
gitHub: GitHub,
app: App,
orgs: Orgs,
deferral: Deferral,
subscriptions: Subscription,
};

Expand Down
2 changes: 2 additions & 0 deletions spa/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import StartConnection from "./pages/StartConnection";
import ConfigSteps from "./pages/ConfigSteps";
import Connected from "./pages/Connected";
import InstallationRequested from "./pages/InstallationRequested";
import DeferredInstallation from "./pages/DeferredInstallation";
import Connections from "./pages/Connections";

import * as Sentry from "@sentry/react";
Expand Down Expand Up @@ -36,6 +37,7 @@ const App = () => {
<Route path="steps" element={<ConfigSteps/>}/>
<Route path="connected" element={<Connected />}/>
<Route path="installationRequested" element={<InstallationRequested />}/>
<Route path="deferred" element={<DeferredInstallation />}/>
</Route>
</SentryRoutes>
</BrowserRouter>
Expand Down
31 changes: 17 additions & 14 deletions spa/src/common/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,26 @@ const wrapperCenterStyle = css`
justify-content: center;
`;

const navigateToHomePage = () => {
analyticsClient.sendUIEvent({ actionSubject: "dropExperienceViaBackButton", action: "clicked" });
AP.getLocation((location: string) => {
const locationUrl = new URL(location);
AP.navigator.go( "site", { absoluteUrl: `${locationUrl.origin}/jira/marketplace/discover/app/com.github.integration.production` });
});
};
export const Wrapper = (attr: { hideClosedBtn?: boolean, children?: ReactNode | undefined }) => {
const navigateToHomePage = () => {
analyticsClient.sendUIEvent({ actionSubject: "dropExperienceViaBackButton", action: "clicked" });
AP.getLocation((location: string) => {
const locationUrl = new URL(location);
AP.navigator.go( "site", { absoluteUrl: `${locationUrl.origin}/jira/marketplace/discover/app/com.github.integration.production` });
});
};

export const Wrapper = (attr: { children?: ReactNode | undefined }) => {
return (
<div css={wrapperStyle}>
<Button
style={{ float: "right" }}
iconBefore={<CrossIcon label="Close" size="medium" />}
appearance="subtle"
onClick={navigateToHomePage}
/>
{
!attr.hideClosedBtn && <Button
style={{ float: "right" }}
iconBefore={<CrossIcon label="Close" size="medium" />}
appearance="subtle"
onClick={navigateToHomePage}
/>
}

<div css={wrapperCenterStyle}>{attr.children}</div>
</div>
);
Expand Down
Loading

0 comments on commit fa6dd04

Please sign in to comment.