From 5bf273c307c350653ef5c22232d3a28960bb2603 Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 26 Jul 2024 13:24:26 +0200 Subject: [PATCH 1/9] wip --- .../components/gitHubApps/GitHubAppPage.tsx | 13 ++- .../components/gitHubApps/GitHubAppsPage.tsx | 80 ++++++++----- .../site-admin/SiteAdminGitHubAppsArea.tsx | 1 + .../src/user/settings/UserGitHubAppsArea.tsx | 108 ++++++++++++++++++ client/web/src/user/settings/routes.tsx | 6 + client/web/src/user/settings/sidebaritems.ts | 5 + cmd/frontend/internal/githubapp/httpapi.go | 2 + 7 files changed, 182 insertions(+), 33 deletions(-) create mode 100644 client/web/src/user/settings/UserGitHubAppsArea.tsx diff --git a/client/web/src/components/gitHubApps/GitHubAppPage.tsx b/client/web/src/components/gitHubApps/GitHubAppPage.tsx index b27fc7a4ee67..b9fb23963f25 100644 --- a/client/web/src/components/gitHubApps/GitHubAppPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppPage.tsx @@ -27,7 +27,12 @@ import { // eslint-disable-next-line no-restricted-imports import type { BreadcrumbItem } from '@sourcegraph/wildcard/src/components/PageHeader' -import { GitHubAppDomain, type GitHubAppByIDResult, type GitHubAppByIDVariables } from '../../graphql-operations' +import { + GitHubAppDomain, + type GitHubAppByIDResult, + type GitHubAppByIDVariables, + GitHubAppKind +} from '../../graphql-operations' import { ExternalServiceNode } from '../externalServices/ExternalServiceNode' import { ConnectionList, ConnectionSummary, SummaryContainer } from '../FilteredConnection/ui' import { PageTitle } from '../PageTitle' @@ -44,6 +49,7 @@ interface Props extends TelemetryProps, TelemetryV2Props { * The parent breadcrumb item to show for this page in the header. */ headerParentBreadcrumb: BreadcrumbItem + isSiteAdmin: boolean /** An optional annotation to show in the page header. */ headerAnnotation?: React.ReactNode } @@ -53,6 +59,7 @@ export const GitHubAppPage: FC = ({ telemetryRecorder, headerParentBreadcrumb, headerAnnotation, + isSiteAdmin, }) => { const { appID } = useParams() const navigate = useNavigate() @@ -81,7 +88,7 @@ export const GitHubAppPage: FC = ({ const onAddInstallation = async (app: NonNullable): Promise => { try { - const req = await fetch(`/githubapp/state?id=${app?.id}&domain=${app?.domain}`) + const req = await fetch(`/githubapp/state?id=${app?.id}&domain=${app?.domain}&kind=${GitHubAppKind.USER_CREDENTIAL}`) const state = await req.text() const trailingSlash = app.appURL.endsWith('/') ? '' : '/' window.location.assign(`${app.appURL}${trailingSlash}installations/new?state=${state}`) @@ -100,7 +107,7 @@ export const GitHubAppPage: FC = ({ {removeModalOpen && ( setRemoveModalOpen(false)} - afterDelete={() => navigate('/site-admin/github-apps')} + afterDelete={() => navigate(`/${isSiteAdmin ? 'site-admin' : 'user/settings'}/github-apps`)} app={app} /> )} diff --git a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx index bbae037ca5de..9544c47a0c02 100644 --- a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx @@ -1,15 +1,15 @@ -import { useEffect, useMemo } from 'react' +import {useEffect, useMemo} from 'react' -import { mdiPlus } from '@mdi/js' +import {mdiPlus} from '@mdi/js' import classNames from 'classnames' -import { useLocation } from 'react-router-dom' +import {useLocation} from 'react-router-dom' -import { useQuery } from '@sourcegraph/http-client' -import type { TelemetryV2Props } from '@sourcegraph/shared/src/telemetry' -import { EVENT_LOGGER } from '@sourcegraph/shared/src/telemetry/web/eventLogger' -import { ButtonLink, Container, ErrorAlert, Icon, Link, LoadingSpinner, PageHeader } from '@sourcegraph/wildcard' +import {useQuery} from '@sourcegraph/http-client' +import type {TelemetryV2Props} from '@sourcegraph/shared/src/telemetry' +import {EVENT_LOGGER} from '@sourcegraph/shared/src/telemetry/web/eventLogger' +import {ButtonLink, Container, ErrorAlert, Icon, Link, LoadingSpinner, PageHeader} from '@sourcegraph/wildcard' -import { GitHubAppDomain, type GitHubAppsResult, type GitHubAppsVariables } from '../../graphql-operations' +import {GitHubAppDomain, type GitHubAppsResult, type GitHubAppsVariables} from '../../graphql-operations' import { ConnectionContainer, ConnectionList, @@ -17,22 +17,23 @@ import { ConnectionSummary, SummaryContainer, } from '../FilteredConnection/ui' -import { PageTitle } from '../PageTitle' +import {PageTitle} from '../PageTitle' -import { GITHUB_APPS_QUERY } from './backend' -import { GitHubAppCard } from './GitHubAppCard' -import { GitHubAppFailureAlert } from './GitHubAppFailureAlert' +import {GITHUB_APPS_QUERY} from './backend' +import {GitHubAppCard} from './GitHubAppCard' +import {GitHubAppFailureAlert} from './GitHubAppFailureAlert' import styles from './GitHubAppsPage.module.scss' interface Props extends TelemetryV2Props { batchChangesEnabled: boolean + isSiteAdmin: boolean } -export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetryRecorder }) => { - const { data, loading, error, refetch } = useQuery(GITHUB_APPS_QUERY, { +export const GitHubAppsPage: React.FC = ({batchChangesEnabled, telemetryRecorder, isSiteAdmin}) => { + const {data, loading, error, refetch} = useQuery(GITHUB_APPS_QUERY, { variables: { - domain: GitHubAppDomain.REPOS, + domain: isSiteAdmin ? GitHubAppDomain.REPOS : GitHubAppDomain.BATCHES, }, }) const gitHubApps = useMemo(() => data?.gitHubApps?.nodes ?? [], [data]) @@ -51,50 +52,69 @@ export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetry } if (loading && !data) { - return + return } return ( <> - + - Create and connect a GitHub App to better manage GitHub code host connections.{' '} - - See how GitHub App configuration works. - - {batchChangesEnabled && ( + {isSiteAdmin ? + <> + Create and connect a GitHub App to better manage GitHub code host connections.{' '} + + See how GitHub App configuration works. + + + : + batchChangesEnabled ? + <> + Use personal GitHub Apps to act on your behalf when running Batch Changes. + + : + <> + Personal GitHub Apps are currently only used for Batch Changes, but this feature is not enabled on your instance. + + } + {batchChangesEnabled && isSiteAdmin + ? <> {' '} To create a GitHub App to sign Batch Changes commits, visit{' '} Batch Changes settings. - )} + : + <> + {' '} + To create a GitHub App to sign Batch Changes commits, ask your site admin. + + } } actions={ - Create GitHub App + Create GitHub App } /> - {!success && setupError && } + {!success && setupError && } - {error && } - {loading && !data && } + {error && } + {loading && !data && } {gitHubApps?.map(app => ( - + ))} diff --git a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx index 83678c4611d3..51c0eff96a19 100644 --- a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx +++ b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx @@ -75,6 +75,7 @@ export const SiteAdminGitHubAppsArea: FC = props => { } /> diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx new file mode 100644 index 000000000000..e006737146e3 --- /dev/null +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -0,0 +1,108 @@ +import type { FC } from 'react' + +import { Routes, Route } from 'react-router-dom' + +import { useQuery } from '@sourcegraph/http-client' +import type { AuthenticatedUser } from '@sourcegraph/shared/src/auth' +import type { PlatformContextProps } from '@sourcegraph/shared/src/platform/context' +import type { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService' +import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent' +import { LoadingSpinner, ErrorAlert } from '@sourcegraph/wildcard' + +import { + GitHubAppDomain, + GitHubAppKind, + type SiteExternalServiceConfigResult, + type SiteExternalServiceConfigVariables, +} from '../../graphql-operations' + +import { SITE_EXTERNAL_SERVICE_CONFIG } from '../../site-admin/backend' + +const CreateGitHubAppPage = lazyComponent( + () => import('../../components/gitHubApps/CreateGitHubAppPage'), + 'CreateGitHubAppPage' +) +const GitHubAppPage = lazyComponent(() => import('../../components/gitHubApps/GitHubAppPage'), 'GitHubAppPage') +const GitHubAppsPage = lazyComponent(() => import('../../components/gitHubApps/GitHubAppsPage'), 'GitHubAppsPage') + +interface Props extends TelemetryProps, PlatformContextProps { + authenticatedUser: AuthenticatedUser + batchChangesEnabled: boolean +} + +const DEFAULT_EVENTS = [ + 'repository', + 'public', + 'member', + 'membership', + 'organization', + 'team', + 'team_add', + 'meta', + 'push', +] + +const DEFAULT_PERMISSIONS = { + contents: 'read', + emails: 'read', + members: 'read', + metadata: 'read', +} + +export const UserGitHubAppsArea: FC = props => { + const { data, error, loading } = useQuery( + SITE_EXTERNAL_SERVICE_CONFIG, + {} + ) + + if (error && !loading) { + return + } + + if (loading && !error) { + return + } + + if (!data) { + return null + } + + return ( + + + } + /> + + + } + /> + + } + /> + + ) +} diff --git a/client/web/src/user/settings/routes.tsx b/client/web/src/user/settings/routes.tsx index 37b1c8d49c4f..660d854ef861 100644 --- a/client/web/src/user/settings/routes.tsx +++ b/client/web/src/user/settings/routes.tsx @@ -107,6 +107,12 @@ export const userSettingsAreaRoutes: readonly UserSettingsAreaRoute[] = [ ), condition: shouldRenderBatchChangesPage, }, + { + path: 'github-apps/*', + render: lazyComponent(() => import('./UserGitHubAppsArea'), 'UserGitHubAppsArea'), + // GitHub Apps are currently only relevant for users who use them with batch changes. If they are used for other things too, you can remove this condition. + condition: shouldRenderBatchChangesPage, + }, ] interface UserSettingAreaIndexPageProps extends PlatformContextProps, SettingsCascadeProps, TelemetryProps { diff --git a/client/web/src/user/settings/sidebaritems.ts b/client/web/src/user/settings/sidebaritems.ts index a2c2629ba466..f588a865b255 100644 --- a/client/web/src/user/settings/sidebaritems.ts +++ b/client/web/src/user/settings/sidebaritems.ts @@ -61,4 +61,9 @@ export const userSettingsSideBarItems: UserSettingsSidebarItems = [ label: 'Event log', condition: ({ user: { viewerCanAdminister } }) => viewerCanAdminister, }, + { + to: '/github-apps', + label: 'GitHub Apps', + condition: ({ user: { viewerCanAdminister } }) => viewerCanAdminister, + }, ] diff --git a/cmd/frontend/internal/githubapp/httpapi.go b/cmd/frontend/internal/githubapp/httpapi.go index 000210a558bb..444e125d2195 100644 --- a/cmd/frontend/internal/githubapp/httpapi.go +++ b/cmd/frontend/internal/githubapp/httpapi.go @@ -145,6 +145,7 @@ func (srv *gitHubAppServer) stateHandler(w http.ResponseWriter, r *http.Request) gqlID := r.URL.Query().Get("id") domain := r.URL.Query().Get("domain") baseURL := r.URL.Query().Get("baseURL") + kind := r.URL.Query().Get("kind") if gqlID == "" { // we marshal an empty `gitHubAppStateDetails` struct because we want the values saved in the cache // to always conform to the same structure. @@ -168,6 +169,7 @@ func (srv *gitHubAppServer) stateHandler(w http.ResponseWriter, r *http.Request) AppID: int(id64), Domain: domain, BaseURL: baseURL, + Kind: kind, }) if err != nil { http.Error(w, fmt.Sprintf("Unexpected error when marshalling state: %s", err.Error()), http.StatusInternalServerError) From 79e04ae3a1d40bdd26811b18df51b5bea2fa9b8f Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 26 Jul 2024 15:34:01 +0200 Subject: [PATCH 2/9] chore: gazelle configure and linting --- client/web/BUILD.bazel | 1 + .../components/gitHubApps/GitHubAppPage.tsx | 6 +- .../components/gitHubApps/GitHubAppsPage.tsx | 76 +++++++++---------- .../src/user/settings/UserGitHubAppsArea.tsx | 1 - 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/client/web/BUILD.bazel b/client/web/BUILD.bazel index 8dd44c673a3f..a8797928f762 100644 --- a/client/web/BUILD.bazel +++ b/client/web/BUILD.bazel @@ -1711,6 +1711,7 @@ ts_project( "src/user/settings/RedirectToUserPage.tsx", "src/user/settings/RedirectToUserSettings.tsx", "src/user/settings/ScimAlert.tsx", + "src/user/settings/UserGitHubAppsArea.tsx", "src/user/settings/UserSettingsArea.tsx", "src/user/settings/UserSettingsSidebar.tsx", "src/user/settings/accessTokens/UserSettingsCreateAccessTokenCallbackPage.tsx", diff --git a/client/web/src/components/gitHubApps/GitHubAppPage.tsx b/client/web/src/components/gitHubApps/GitHubAppPage.tsx index b9fb23963f25..d2882bb79258 100644 --- a/client/web/src/components/gitHubApps/GitHubAppPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppPage.tsx @@ -31,7 +31,7 @@ import { GitHubAppDomain, type GitHubAppByIDResult, type GitHubAppByIDVariables, - GitHubAppKind + GitHubAppKind, } from '../../graphql-operations' import { ExternalServiceNode } from '../externalServices/ExternalServiceNode' import { ConnectionList, ConnectionSummary, SummaryContainer } from '../FilteredConnection/ui' @@ -88,7 +88,9 @@ export const GitHubAppPage: FC = ({ const onAddInstallation = async (app: NonNullable): Promise => { try { - const req = await fetch(`/githubapp/state?id=${app?.id}&domain=${app?.domain}&kind=${GitHubAppKind.USER_CREDENTIAL}`) + const req = await fetch( + `/githubapp/state?id=${app?.id}&domain=${app?.domain}&kind=${GitHubAppKind.USER_CREDENTIAL}` + ) const state = await req.text() const trailingSlash = app.appURL.endsWith('/') ? '' : '/' window.location.assign(`${app.appURL}${trailingSlash}installations/new?state=${state}`) diff --git a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx index 9544c47a0c02..f81f4095c8c1 100644 --- a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx @@ -1,15 +1,15 @@ -import {useEffect, useMemo} from 'react' +import { useEffect, useMemo } from 'react' -import {mdiPlus} from '@mdi/js' +import { mdiPlus } from '@mdi/js' import classNames from 'classnames' -import {useLocation} from 'react-router-dom' +import { useLocation } from 'react-router-dom' -import {useQuery} from '@sourcegraph/http-client' -import type {TelemetryV2Props} from '@sourcegraph/shared/src/telemetry' -import {EVENT_LOGGER} from '@sourcegraph/shared/src/telemetry/web/eventLogger' -import {ButtonLink, Container, ErrorAlert, Icon, Link, LoadingSpinner, PageHeader} from '@sourcegraph/wildcard' +import { useQuery } from '@sourcegraph/http-client' +import type { TelemetryV2Props } from '@sourcegraph/shared/src/telemetry' +import { EVENT_LOGGER } from '@sourcegraph/shared/src/telemetry/web/eventLogger' +import { ButtonLink, Container, ErrorAlert, Icon, Link, LoadingSpinner, PageHeader } from '@sourcegraph/wildcard' -import {GitHubAppDomain, type GitHubAppsResult, type GitHubAppsVariables} from '../../graphql-operations' +import { GitHubAppDomain, type GitHubAppsResult, type GitHubAppsVariables } from '../../graphql-operations' import { ConnectionContainer, ConnectionList, @@ -17,11 +17,11 @@ import { ConnectionSummary, SummaryContainer, } from '../FilteredConnection/ui' -import {PageTitle} from '../PageTitle' +import { PageTitle } from '../PageTitle' -import {GITHUB_APPS_QUERY} from './backend' -import {GitHubAppCard} from './GitHubAppCard' -import {GitHubAppFailureAlert} from './GitHubAppFailureAlert' +import { GITHUB_APPS_QUERY } from './backend' +import { GitHubAppCard } from './GitHubAppCard' +import { GitHubAppFailureAlert } from './GitHubAppFailureAlert' import styles from './GitHubAppsPage.module.scss' @@ -30,8 +30,8 @@ interface Props extends TelemetryV2Props { isSiteAdmin: boolean } -export const GitHubAppsPage: React.FC = ({batchChangesEnabled, telemetryRecorder, isSiteAdmin}) => { - const {data, loading, error, refetch} = useQuery(GITHUB_APPS_QUERY, { +export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetryRecorder, isSiteAdmin }) => { + const { data, loading, error, refetch } = useQuery(GITHUB_APPS_QUERY, { variables: { domain: isSiteAdmin ? GitHubAppDomain.REPOS : GitHubAppDomain.BATCHES, }, @@ -52,48 +52,42 @@ export const GitHubAppsPage: React.FC = ({batchChangesEnabled, telemetryR } if (loading && !data) { - return + return } return ( <> - + - {isSiteAdmin ? + {isSiteAdmin ? ( <> Create and connect a GitHub App to better manage GitHub code host connections.{' '} See how GitHub App configuration works. - : - batchChangesEnabled ? - <> - Use personal GitHub Apps to act on your behalf when running Batch Changes. - - : - <> - Personal GitHub Apps are currently only used for Batch Changes, but this feature is not enabled on your instance. - - } - {batchChangesEnabled && isSiteAdmin - ? + ) : batchChangesEnabled ? ( + <>Use personal GitHub Apps to act on your behalf when running Batch Changes. + ) : ( <> - {' '} - To create a GitHub App to sign Batch Changes commits, visit{' '} - Batch Changes settings. + Personal GitHub Apps are currently only used for Batch Changes, but this feature is not + enabled on your instance. - : + )} + {batchChangesEnabled && isSiteAdmin ? ( <> {' '} - To create a GitHub App to sign Batch Changes commits, ask your site admin. + To create a GitHub App to sign Batch Changes commits, visit{' '} + Batch Changes settings. - } + ) : ( + <> To create a GitHub App to sign Batch Changes commits, ask your site admin. + )} } actions={ @@ -103,18 +97,18 @@ export const GitHubAppsPage: React.FC = ({batchChangesEnabled, telemetryR variant="primary" as={Link} > - Create GitHub App + Create GitHub App } /> - {!success && setupError && } + {!success && setupError && } - {error && } - {loading && !data && } + {error && } + {loading && !data && } {gitHubApps?.map(app => ( - + ))} diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx index e006737146e3..192722743a16 100644 --- a/client/web/src/user/settings/UserGitHubAppsArea.tsx +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -15,7 +15,6 @@ import { type SiteExternalServiceConfigResult, type SiteExternalServiceConfigVariables, } from '../../graphql-operations' - import { SITE_EXTERNAL_SERVICE_CONFIG } from '../../site-admin/backend' const CreateGitHubAppPage = lazyComponent( From 2806ce7aadd3885061641f94cc7457dd20a30501 Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 26 Jul 2024 15:43:55 +0200 Subject: [PATCH 3/9] chore: add missing parameter --- client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx | 1 + client/web/src/user/settings/UserGitHubAppsArea.tsx | 1 + 2 files changed, 2 insertions(+) diff --git a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx index 51c0eff96a19..d495e9395861 100644 --- a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx +++ b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx @@ -99,6 +99,7 @@ export const SiteAdminGitHubAppsArea: FC = props => { } diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx index 192722743a16..7b07b34e3bc6 100644 --- a/client/web/src/user/settings/UserGitHubAppsArea.tsx +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -98,6 +98,7 @@ export const UserGitHubAppsArea: FC = props => { } From bc931be3dd6db6511fbc62cc156acea262057c5f Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 26 Jul 2024 16:10:18 +0200 Subject: [PATCH 4/9] chore: add missing parameter --- client/web/src/site-admin/routes.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/web/src/site-admin/routes.tsx b/client/web/src/site-admin/routes.tsx index 304b8a5b0e8e..ac462d7fea52 100644 --- a/client/web/src/site-admin/routes.tsx +++ b/client/web/src/site-admin/routes.tsx @@ -425,6 +425,7 @@ export const otherSiteAdminRoutes: readonly SiteAdminAreaRoute[] = [ headerAnnotation={} telemetryService={props.telemetryService} telemetryRecorder={props.platformContext.telemetryRecorder} + isSiteAdmin={true} /> ), condition: ({ batchChangesEnabled }) => batchChangesEnabled, From 8465b6f33ee15c7e2417ae26bb472a5b9090faa1 Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Wed, 31 Jul 2024 09:15:48 +0200 Subject: [PATCH 5/9] chore: don't show "Create GitHub App" when we're not in the site-admin context --- .../components/gitHubApps/GitHubAppsPage.tsx | 5 +- .../src/user/settings/UserGitHubAppsArea.tsx | 61 +++---------------- 2 files changed, 14 insertions(+), 52 deletions(-) diff --git a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx index f81f4095c8c1..6ad646e50ad2 100644 --- a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx @@ -91,14 +91,17 @@ export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetry } actions={ + isSiteAdmin ? Create GitHub App + : + <> } /> diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx index 7b07b34e3bc6..6a85d8c17fa7 100644 --- a/client/web/src/user/settings/UserGitHubAppsArea.tsx +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -1,26 +1,17 @@ -import type { FC } from 'react' +import type {FC} from 'react' -import { Routes, Route } from 'react-router-dom' +import {Route, Routes} from 'react-router-dom' -import { useQuery } from '@sourcegraph/http-client' -import type { AuthenticatedUser } from '@sourcegraph/shared/src/auth' -import type { PlatformContextProps } from '@sourcegraph/shared/src/platform/context' -import type { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService' -import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent' -import { LoadingSpinner, ErrorAlert } from '@sourcegraph/wildcard' +import {useQuery} from '@sourcegraph/http-client' +import type {AuthenticatedUser} from '@sourcegraph/shared/src/auth' +import type {PlatformContextProps} from '@sourcegraph/shared/src/platform/context' +import type {TelemetryProps} from '@sourcegraph/shared/src/telemetry/telemetryService' +import {lazyComponent} from '@sourcegraph/shared/src/util/lazyComponent' +import {ErrorAlert, LoadingSpinner} from '@sourcegraph/wildcard' -import { - GitHubAppDomain, - GitHubAppKind, - type SiteExternalServiceConfigResult, - type SiteExternalServiceConfigVariables, -} from '../../graphql-operations' -import { SITE_EXTERNAL_SERVICE_CONFIG } from '../../site-admin/backend' +import {type SiteExternalServiceConfigResult, type SiteExternalServiceConfigVariables,} from '../../graphql-operations' +import {SITE_EXTERNAL_SERVICE_CONFIG} from '../../site-admin/backend' -const CreateGitHubAppPage = lazyComponent( - () => import('../../components/gitHubApps/CreateGitHubAppPage'), - 'CreateGitHubAppPage' -) const GitHubAppPage = lazyComponent(() => import('../../components/gitHubApps/GitHubAppPage'), 'GitHubAppPage') const GitHubAppsPage = lazyComponent(() => import('../../components/gitHubApps/GitHubAppsPage'), 'GitHubAppsPage') @@ -29,25 +20,6 @@ interface Props extends TelemetryProps, PlatformContextProps { batchChangesEnabled: boolean } -const DEFAULT_EVENTS = [ - 'repository', - 'public', - 'member', - 'membership', - 'organization', - 'team', - 'team_add', - 'meta', - 'push', -] - -const DEFAULT_PERMISSIONS = { - contents: 'read', - emails: 'read', - members: 'read', - metadata: 'read', -} - export const UserGitHubAppsArea: FC = props => { const { data, error, loading } = useQuery( SITE_EXTERNAL_SERVICE_CONFIG, @@ -79,19 +51,6 @@ export const UserGitHubAppsArea: FC = props => { } /> - - } - /> Date: Wed, 31 Jul 2024 09:18:45 +0200 Subject: [PATCH 6/9] chore: linting --- .../components/gitHubApps/GitHubAppsPage.tsx | 21 ++++++++++--------- .../src/user/settings/UserGitHubAppsArea.tsx | 20 +++++++++--------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx index 6ad646e50ad2..9cc610e31dac 100644 --- a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx @@ -91,17 +91,18 @@ export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetry } actions={ - isSiteAdmin ? - - Create GitHub App - - : + isSiteAdmin ? ( + + Create GitHub App + + ) : ( <> + ) } /> diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx index 6a85d8c17fa7..a8b4265452be 100644 --- a/client/web/src/user/settings/UserGitHubAppsArea.tsx +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -1,16 +1,16 @@ -import type {FC} from 'react' +import type { FC } from 'react' -import {Route, Routes} from 'react-router-dom' +import { Route, Routes } from 'react-router-dom' -import {useQuery} from '@sourcegraph/http-client' -import type {AuthenticatedUser} from '@sourcegraph/shared/src/auth' -import type {PlatformContextProps} from '@sourcegraph/shared/src/platform/context' -import type {TelemetryProps} from '@sourcegraph/shared/src/telemetry/telemetryService' -import {lazyComponent} from '@sourcegraph/shared/src/util/lazyComponent' -import {ErrorAlert, LoadingSpinner} from '@sourcegraph/wildcard' +import { useQuery } from '@sourcegraph/http-client' +import type { AuthenticatedUser } from '@sourcegraph/shared/src/auth' +import type { PlatformContextProps } from '@sourcegraph/shared/src/platform/context' +import type { TelemetryProps } from '@sourcegraph/shared/src/telemetry/telemetryService' +import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent' +import { ErrorAlert, LoadingSpinner } from '@sourcegraph/wildcard' -import {type SiteExternalServiceConfigResult, type SiteExternalServiceConfigVariables,} from '../../graphql-operations' -import {SITE_EXTERNAL_SERVICE_CONFIG} from '../../site-admin/backend' +import { type SiteExternalServiceConfigResult, type SiteExternalServiceConfigVariables } from '../../graphql-operations' +import { SITE_EXTERNAL_SERVICE_CONFIG } from '../../site-admin/backend' const GitHubAppPage = lazyComponent(() => import('../../components/gitHubApps/GitHubAppPage'), 'GitHubAppPage') const GitHubAppsPage = lazyComponent(() => import('../../components/gitHubApps/GitHubAppsPage'), 'GitHubAppsPage') From f7056c6eabc4033405c488892a21dfb1ce20bbf4 Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 9 Aug 2024 10:04:50 +0200 Subject: [PATCH 7/9] fix: update telemetry based on user --- client/web/src/components/gitHubApps/GitHubAppsPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx index 9cc610e31dac..1f61bb72146f 100644 --- a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx @@ -39,9 +39,9 @@ export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetry const gitHubApps = useMemo(() => data?.gitHubApps?.nodes ?? [], [data]) useEffect(() => { - EVENT_LOGGER.logPageView('SiteAdminGitHubApps') - telemetryRecorder.recordEvent('admin.GitHubApps', 'view') - }, [telemetryRecorder]) + EVENT_LOGGER.logPageView(isSiteAdmin ? 'SiteAdminGitHubApps' : 'UserGitHubApps') + telemetryRecorder.recordEvent(isSiteAdmin ? 'admin.GitHubApps' : 'user.GitHubApps', 'view') + }, [telemetryRecorder, isSiteAdmin]) const location = useLocation() const success = new URLSearchParams(location.search).get('success') === 'true' From cf73f1a3eab4812ff13069605a24059ffd1cc86f Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 9 Aug 2024 10:14:20 +0200 Subject: [PATCH 8/9] wip review comments --- .../components/gitHubApps/GitHubAppPage.tsx | 12 +++--- .../components/gitHubApps/GitHubAppsPage.tsx | 42 ++++++++++--------- .../site-admin/SiteAdminGitHubAppsArea.tsx | 2 +- client/web/src/site-admin/routes.tsx | 2 +- .../src/user/settings/UserGitHubAppsArea.tsx | 2 +- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/client/web/src/components/gitHubApps/GitHubAppPage.tsx b/client/web/src/components/gitHubApps/GitHubAppPage.tsx index d2882bb79258..4cff985d037d 100644 --- a/client/web/src/components/gitHubApps/GitHubAppPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppPage.tsx @@ -49,7 +49,7 @@ interface Props extends TelemetryProps, TelemetryV2Props { * The parent breadcrumb item to show for this page in the header. */ headerParentBreadcrumb: BreadcrumbItem - isSiteAdmin: boolean + userOwned: boolean /** An optional annotation to show in the page header. */ headerAnnotation?: React.ReactNode } @@ -59,16 +59,16 @@ export const GitHubAppPage: FC = ({ telemetryRecorder, headerParentBreadcrumb, headerAnnotation, - isSiteAdmin, + userOwned, }) => { const { appID } = useParams() const navigate = useNavigate() const [removeModalOpen, setRemoveModalOpen] = useState(false) useEffect(() => { - telemetryService.logPageView('SiteAdminGitHubApp') - telemetryRecorder.recordEvent('admin.GitHubApp', 'view') - }, [telemetryService, telemetryRecorder]) + telemetryService.logPageView(userOwned ? 'UserGitHubApp' : 'SiteAdminGitHubApp') + telemetryRecorder.recordEvent(userOwned ? 'user.GitHubApp' : 'admin.GitHubApp', 'view') + }, [telemetryService, telemetryRecorder, userOwned]) const [fetchError, setError] = useState() const { data, loading, error } = useQuery(GITHUB_APP_BY_ID_QUERY, { @@ -109,7 +109,7 @@ export const GitHubAppPage: FC = ({ {removeModalOpen && ( setRemoveModalOpen(false)} - afterDelete={() => navigate(`/${isSiteAdmin ? 'site-admin' : 'user/settings'}/github-apps`)} + afterDelete={() => navigate(`/${userOwned ? 'user/settings' : 'site-admin'}/github-apps`)} app={app} /> )} diff --git a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx index 1f61bb72146f..6bf87ae68c0c 100644 --- a/client/web/src/components/gitHubApps/GitHubAppsPage.tsx +++ b/client/web/src/components/gitHubApps/GitHubAppsPage.tsx @@ -27,21 +27,21 @@ import styles from './GitHubAppsPage.module.scss' interface Props extends TelemetryV2Props { batchChangesEnabled: boolean - isSiteAdmin: boolean + userOwned: boolean } -export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetryRecorder, isSiteAdmin }) => { +export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetryRecorder, userOwned }) => { const { data, loading, error, refetch } = useQuery(GITHUB_APPS_QUERY, { variables: { - domain: isSiteAdmin ? GitHubAppDomain.REPOS : GitHubAppDomain.BATCHES, + domain: userOwned ? GitHubAppDomain.BATCHES : GitHubAppDomain.REPOS, }, }) const gitHubApps = useMemo(() => data?.gitHubApps?.nodes ?? [], [data]) useEffect(() => { - EVENT_LOGGER.logPageView(isSiteAdmin ? 'SiteAdminGitHubApps' : 'UserGitHubApps') - telemetryRecorder.recordEvent(isSiteAdmin ? 'admin.GitHubApps' : 'user.GitHubApps', 'view') - }, [telemetryRecorder, isSiteAdmin]) + EVENT_LOGGER.logPageView(userOwned ? 'UserGitHubApps' : 'SiteAdminGitHubApps') + telemetryRecorder.recordEvent(userOwned ? 'user.GitHubApps' : 'admin.GitHubApps', 'view') + }, [telemetryRecorder, userOwned]) const location = useLocation() const success = new URLSearchParams(location.search).get('success') === 'true' @@ -64,34 +64,38 @@ export const GitHubAppsPage: React.FC = ({ batchChangesEnabled, telemetry className={classNames(styles.pageHeader, 'mb-3')} description={ <> - {isSiteAdmin ? ( + {userOwned ? ( + batchChangesEnabled ? ( + <>Use personal GitHub Apps to act on your behalf when running Batch Changes. + ) : ( + <> + Personal GitHub Apps are currently only used for Batch Changes, but this feature is + not enabled on your instance. + + ) + ) : ( <> Create and connect a GitHub App to better manage GitHub code host connections.{' '} See how GitHub App configuration works. - ) : batchChangesEnabled ? ( - <>Use personal GitHub Apps to act on your behalf when running Batch Changes. - ) : ( - <> - Personal GitHub Apps are currently only used for Batch Changes, but this feature is not - enabled on your instance. - )} - {batchChangesEnabled && isSiteAdmin ? ( + {batchChangesEnabled && userOwned ? ( + <> To create a GitHub App to sign Batch Changes commits, ask your site admin. + ) : ( <> {' '} To create a GitHub App to sign Batch Changes commits, visit{' '} Batch Changes settings. - ) : ( - <> To create a GitHub App to sign Batch Changes commits, ask your site admin. )} } actions={ - isSiteAdmin ? ( + userOwned ? ( + <> + ) : ( = ({ batchChangesEnabled, telemetry > Create GitHub App - ) : ( - <> ) } /> diff --git a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx index d495e9395861..370918080a84 100644 --- a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx +++ b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx @@ -99,7 +99,7 @@ export const SiteAdminGitHubAppsArea: FC = props => { } diff --git a/client/web/src/site-admin/routes.tsx b/client/web/src/site-admin/routes.tsx index ac462d7fea52..88e41ee117ee 100644 --- a/client/web/src/site-admin/routes.tsx +++ b/client/web/src/site-admin/routes.tsx @@ -425,7 +425,7 @@ export const otherSiteAdminRoutes: readonly SiteAdminAreaRoute[] = [ headerAnnotation={} telemetryService={props.telemetryService} telemetryRecorder={props.platformContext.telemetryRecorder} - isSiteAdmin={true} + userOwned={false} /> ), condition: ({ batchChangesEnabled }) => batchChangesEnabled, diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx index a8b4265452be..ce6c520df8ac 100644 --- a/client/web/src/user/settings/UserGitHubAppsArea.tsx +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -57,7 +57,7 @@ export const UserGitHubAppsArea: FC = props => { } From f44f0169914693bb6501be68c6352296b861e894 Mon Sep 17 00:00:00 2001 From: Michael Bahr Date: Fri, 9 Aug 2024 11:57:42 +0200 Subject: [PATCH 9/9] more review changes --- client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx | 2 +- client/web/src/user/settings/UserGitHubAppsArea.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx index 370918080a84..928217f3362b 100644 --- a/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx +++ b/client/web/src/site-admin/SiteAdminGitHubAppsArea.tsx @@ -75,7 +75,7 @@ export const SiteAdminGitHubAppsArea: FC = props => { } /> diff --git a/client/web/src/user/settings/UserGitHubAppsArea.tsx b/client/web/src/user/settings/UserGitHubAppsArea.tsx index ce6c520df8ac..3a04c982652b 100644 --- a/client/web/src/user/settings/UserGitHubAppsArea.tsx +++ b/client/web/src/user/settings/UserGitHubAppsArea.tsx @@ -46,7 +46,7 @@ export const UserGitHubAppsArea: FC = props => { } />