Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

web: Add Test connection button and API call to code host#45972

Merged
indradhanush merged 21 commits into
mainfrom
ig/test-connection-button
Dec 30, 2022
Merged

web: Add Test connection button and API call to code host#45972
indradhanush merged 21 commits into
mainfrom
ig/test-connection-button

Conversation

@indradhanush

@indradhanush indradhanush commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

UI for #44683.

Test plan

  1. Tested locally

Check connection unavailable

image

Check connection available

image

Check connection successful

image

Check connection failed

image

Check connection errored (application error)

image

Test button in action 🎥 for success, failure and error modes

CleanShot 2022-12-29 at 15 47 47

  1. Builds should pass

App preview:

Check out the client app preview documentation to learn more.

@cla-bot cla-bot Bot added the cla-signed label Dec 26, 2022
@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Dec 26, 2022

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.01% (+0.38 kb) 0.03% (+4.48 kb) 0.04% (+4.10 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits f502511 and 821918c or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

Step 1 of many.

Need to tie down the response to the button to show changes.
@indradhanush indradhanush force-pushed the ig/test-connection-button branch from 35e2008 to 5c677c2 Compare December 27, 2022 03:30
@indradhanush indradhanush marked this pull request as ready for review December 29, 2022 10:23
@indradhanush indradhanush requested review from a team and 0xnmn December 29, 2022 10:24
@indradhanush indradhanush added site-admin Site admin experience site-admin-ux Issues related to site-admin UX: bugs, papercuts, design, ... labels Dec 29, 2022
updatedAt: '2021-03-15T19:39:11Z',
createdAt: '2021-03-15T19:39:11Z',
webhookURL: null,
hasConnectionCheck: true,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change brought to you by yarn build-ts errors.

id: 'service1',
kind: ExternalServiceKind.GITHUB,
displayName: 'GitHub.com',
displayName: 'GitHub #1',

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small fix: Fixed a warning for both the displayName being same in the storybook.

<span className={classNames('text-primary')}>
<LoadingSpinner /> Checking connection...
</span>
)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this rather(same for other places):

const checkConnectionNode = checkConnectionData?.node
const isCodeHostReachable = node?.__typename === 'ExternalService' &&
                            node?.checkConnection?.__typename === 'ExternalServiceAvailable' && 
                            node?.checkConnection?.lastCheckedAt;
 
 {isCodeHostReachable && (
    <span className="text-success">
        <Icon aria-hidden={true} svgPath={mdiCheckCircle} /> Code host is reachable.
    </span>
 )}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@indradhanush indradhanush requested a review from 0xnmn December 29, 2022 11:20
Comment thread client/web/src/components/externalServices/ExternalServiceNode.tsx Outdated
{ called: checkConnectionCalled, loading: checkConnectionLoading, data: checkConnectionData },
] = useExternalServiceCheckConnectionByIdLazyQuery(node.id)

const [checkConnectionError, setCheckConnectionError] = useState<boolean | Error>(false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the type of state can be simplified to just Error and initially set to undefined.
(Or you might need Error | undefined, I'm not 100% sure 😁)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Probably. But we're doing something similar already for isDeleting a little above this code. Maybe we keep them the same to have a recognizable pattern in this part of the code? What do you think?

@0xnmn 0xnmn Dec 29, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useLazyQuery should return error on its own and you don't need to save error state separately.

You can do const [doCheckConnection, { loading, data, error }] = useExternalServiceCheckConnectionByIdLazyQuery(node.id)

deleteExternalService is legacy and not using the react hooks; that is why the error is handled separately there.

Read: https://www.apollographql.com/docs/react/api/react/hooks/#error

Comment thread client/web/src/components/externalServices/ExternalServiceNode.tsx Outdated
Comment thread client/web/src/components/externalServices/ExternalServiceNode.tsx Outdated
)}
{node.nextSyncAt === null && <>No next sync scheduled.</>}
<br />
{isErrorLike(checkConnectionError) && (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified to !checkConnectionError. Because currently it is either false or Error which is isErrorLike

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably, loading check should be added here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified to !checkConnectionError. Because currently it is either false or Error which is isErrorLike

I think the isErrorLike is a stronger check here in case there's ever a bug and checkConnectionError is true, then we will end up displaying an error message with true in it. I checked in other places and it looks like isErrorLike is used in such cases. I'd vote to keep it as is.

+1 on moving the loading check to be the first. Fixed that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't believe this can happen, we need to trust our code :)
but still it's your call

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't believe this can happen, we need to trust our code :)

Yeah I trust the code now. But I'm thinking that the current check is stronger for any potential future bugs if anyone / me end up setting true as a value by mistake only because its technically allowed by the type here. Just defensive programming I guess. 😛

Since it's not too complicated in its current form and also is used quite widely in our code, keeping it is not the worst idea. 😀

Comment thread client/web/src/components/externalServices/ExternalServiceNode.tsx Outdated
Comment thread client/web/src/components/externalServices/ExternalServiceNode.tsx Outdated
Improve code organisation and variable naming.
@indradhanush indradhanush requested review from a team and sashaostrikov December 29, 2022 13:09

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
But let's wait for @thenamankumar as well.


const [checkConnectionError, setCheckConnectionError] = useState<boolean | Error>(false)

const onTestConnection = useCallback<React.MouseEventHandler>(async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use error from useLazyQuery

@indradhanush indradhanush Dec 30, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest commit 98e18be.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use doCheckConnection. No need to wrap with useCallback.

@0xnmn 0xnmn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for extra state management for error handling. 🎉
@indradhanush indradhanush requested a review from 0xnmn December 30, 2022 03:30

const [checkConnectionError, setCheckConnectionError] = useState<boolean | Error>(false)

const onTestConnection = useCallback<React.MouseEventHandler>(async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use doCheckConnection. No need to wrap with useCallback.

@indradhanush indradhanush enabled auto-merge (squash) December 30, 2022 07:41
@indradhanush indradhanush merged commit 23a42cf into main Dec 30, 2022
@indradhanush indradhanush deleted the ig/test-connection-button branch December 30, 2022 10:52
</div>
<div className="flex-shrink-0 ml-3">
<Tooltip
content={node.hasConnectionCheck ? 'Test code host connection' : 'Connection check unavailable'}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change Test code host connection to Test whether code host is reachable from Sourcegraph

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tweaked the suggested message slightly to make it a little shorter.

className="test-connection-external-service-button"
variant="secondary"
onClick={() => doCheckConnection()}
disabled={!node.hasConnectionCheck || loading}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(man, GitHub lost my comment, so here it is again)

I think we should just hide the button if !node.hasConnectionCheck. A disabled button suggests there's a way to enable it. In this case though, we don't support the connection check and a Sourcegraph update is required to get it enabled once we add support, meaning: nothing the user can do.

@indradhanush indradhanush Jan 2, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(man, GitHub lost my comment, so here it is again)

Have been seeing some reliability issues with GitHub myself this week. 🙁

@indradhanush indradhanush Jan 2, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get how a user might thinkg that the disabled button suggests that there's a way to enabled it. But with the suggested change, it looks inconsistent to me when one entry doesn't have that button. Besides we do indicate that the connection check is unavailable on the disabled button. Think that should be okay?

image

If it looks all right to you, I can create the PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's alright. (Ideally and further down the road we create a "details" page for code hosts where we can put this)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed site-admin Site admin experience site-admin-ux Issues related to site-admin UX: bugs, papercuts, design, ...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants