Skip to content

Commit

Permalink
Show an error message when Launchpad fails to load data (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdgarcia authored Jun 5, 2024
1 parent 70a8733 commit 1d4df71
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 33 deletions.
66 changes: 48 additions & 18 deletions src/popup/components/FocusView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { storage } from 'webextension-polyfill';
import { getGitKrakenDeepLinkUrl } from '../../deepLink';
import { ProviderMeta } from '../../providers';
import { GKDotDevUrl } from '../../shared';
import type { FocusViewSupportedProvider } from '../../types';
import type { FocusViewDataError, FocusViewSupportedProvider } from '../../types';
import { useFocusViewConnectedProviders, useFocusViewDataQuery, usePullRequestDraftCountsQuery } from '../hooks';
import { ConnectAProvider } from './ConnectAProvider';
import { ExternalLink } from './ExternalLink';
Expand Down Expand Up @@ -189,6 +189,52 @@ export const FocusView = ({ userId }: { userId: string }) => {
return <ConnectAProvider />;
}

let content: JSX.Element | null = null;
if (focusViewDataQuery.isLoading) {
content = (
<div className="text-center">
<i className="fa-regular fa-spinner-third fa-spin" />
</div>
);
} else if (focusViewDataQuery.error) {
const error = focusViewDataQuery.error as FocusViewDataError;
content = (
<div className="focus-view-error text-secondary">
<div className="italic">
An unexpected error occurred trying to load Launchpad data.{' '}
{error.domain ? (
<>
Make sure the service at{' '}
<ExternalLink className="text-link" href={error.domain}>
{error.domain}
</ExternalLink>{' '}
is reachable. If it is, make sure your access token is still valid.
</>
) : (
'Make sure your access token is still valid.'
)}
</div>
<ExternalLink className="text-link manage-integrations" href={`${GKDotDevUrl}/settings/integrations`}>
Manage Integration Settings
</ExternalLink>
</div>
);
} else {
content = (
<div className="pull-request-buckets">
{filteredBuckets?.map(bucket => (
<Bucket
key={bucket.id}
userId={userId}
bucket={bucket}
provider={selectedProvider}
prDraftCountsByEntityID={prDraftCountsQuery.data}
/>
))}
</div>
);
}

return (
<div className="focus-view">
{selectedProvider && (
Expand Down Expand Up @@ -224,23 +270,7 @@ export const FocusView = ({ userId }: { userId: string }) => {
</select>
</div>
)}
{focusViewDataQuery.isLoading ? (
<div className="text-center">
<i className="fa-regular fa-spinner-third fa-spin" />
</div>
) : (
<div className="pull-request-buckets">
{filteredBuckets?.map(bucket => (
<Bucket
key={bucket.id}
userId={userId}
bucket={bucket}
provider={selectedProvider}
prDraftCountsByEntityID={prDraftCountsQuery.data}
/>
))}
</div>
)}
{content}
</div>
);
};
37 changes: 22 additions & 15 deletions src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,27 @@ export const fetchFocusViewData = async (provider: FocusViewSupportedProvider):
return null;
}

switch (provider) {
case 'github':
case 'githubEnterprise':
return fetchGitHubFocusViewData(providerToken);
case 'gitlab':
case 'gitlabSelfHosted':
return fetchGitLabFocusViewData(providerToken);
case 'bitbucket':
return fetchBitbucketFocusViewData(providerToken);
case 'bitbucketServer':
return fetchBitbucketServerFocusViewData(providerToken);
case 'azure':
return fetchAzureFocusViewData(providerToken);
default:
throw new Error(`Attempted to fetch pull requests for unsupported provider: ${provider as Provider}`);
try {
switch (provider) {
case 'github':
case 'githubEnterprise':
return await fetchGitHubFocusViewData(providerToken);
case 'gitlab':
case 'gitlabSelfHosted':
return await fetchGitLabFocusViewData(providerToken);
case 'bitbucket':
return await fetchBitbucketFocusViewData(providerToken);
case 'bitbucketServer':
return await fetchBitbucketServerFocusViewData(providerToken);
case 'azure':
return await fetchAzureFocusViewData(providerToken);
default:
throw new Error(`Attempted to fetch pull requests for unsupported provider: ${provider as Provider}`);
}
} catch (e) {
if (e) {
Object.assign(e, { provider: provider, domain: providerToken.domain });
}
throw e;
}
};
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export type FocusViewData = {
pullRequests: PullRequestWithUniqueID[];
};

export type FocusViewDataError = Error & {
provider?: Provider;
domain?: string;
};

export interface ProviderConnection {
provider: Provider;
type: string;
Expand Down
10 changes: 10 additions & 0 deletions static/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ html {
margin-right: 4px;
}

/* Focus View - Error */
.focus-view .focus-view-error {
display: flex;
flex-direction: column;
}
.focus-view .focus-view-error .manage-integrations {
text-align: center;
margin-top: 8px;
}

/* Generic components */
button.icon-btn {
background: none;
Expand Down

0 comments on commit 1d4df71

Please sign in to comment.