-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error handling in Connect (#47328)
* Preserve newlines and tabs in `Alert` * Use Alert's details to show the status text of an error * Make methods that show errors retryable * Add horizontal padding in `DocumentCluster` * Use Alert's details and primaryAction where appropriate * Add a story for DocumentAccessRequests * Add missing types * Fix lint and tests * Add license * Remove cyclic import from `Alert.tsx` * Add a comment for `white-space: pre-wrap` * Clean up parsing cluster name, add missing action to retry starting a headless watcher
- Loading branch information
Showing
19 changed files
with
287 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
web/packages/teleterm/src/ui/DocumentAccessRequests/DocumentAccessRequests.story.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* Teleport | ||
* Copyright (C) 2024 Gravitational, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { AccessRequest } from 'gen-proto-ts/teleport/lib/teleterm/v1/access_request_pb'; | ||
|
||
import AppContextProvider from 'teleterm/ui/appContextProvider'; | ||
import { MockWorkspaceContextProvider } from 'teleterm/ui/fixtures/MockWorkspaceContextProvider'; | ||
import { ResourcesContextProvider } from 'teleterm/ui/DocumentCluster/resourcesContext'; | ||
import { DocumentAccessRequests } from 'teleterm/ui/DocumentAccessRequests/DocumentAccessRequests'; | ||
import * as types from 'teleterm/ui/services/workspacesService'; | ||
import { makeRootCluster } from 'teleterm/services/tshd/testHelpers'; | ||
import { MockAppContext } from 'teleterm/ui/fixtures/mocks'; | ||
import { getEmptyPendingAccessRequest } from 'teleterm/ui/services/workspacesService/accessRequestsService'; | ||
import { MockedUnaryCall } from 'teleterm/services/tshd/cloneableClient'; | ||
|
||
const rootCluster = makeRootCluster(); | ||
|
||
export default { | ||
title: 'Teleterm/DocumentAccessRequests', | ||
}; | ||
|
||
const doc: types.DocumentAccessRequests = { | ||
kind: 'doc.access_requests', | ||
uri: '/docs/123', | ||
state: 'browsing', | ||
clusterUri: rootCluster.uri, | ||
requestId: '', | ||
title: 'Access Requests', | ||
}; | ||
|
||
const mockedAccessRequest: AccessRequest = { | ||
id: '01929070-6886-77eb-90aa-c7223dd73f67', | ||
state: 'PENDING', | ||
resolveReason: '', | ||
requestReason: '', | ||
user: 'requester', | ||
roles: ['access', 'searcheable-resources'], | ||
reviews: [], | ||
suggestedReviewers: ['admin', 'reviewer'], | ||
thresholdNames: ['default'], | ||
resourceIds: [ | ||
{ | ||
kind: 'kube_cluster', | ||
name: 'minikube', | ||
clusterName: 'main', | ||
subResourceName: '', | ||
}, | ||
], | ||
resources: [ | ||
{ | ||
id: { | ||
kind: 'kube_cluster', | ||
name: 'minikube', | ||
clusterName: 'main', | ||
subResourceName: '', | ||
}, | ||
details: { hostname: '', friendlyName: '' }, | ||
}, | ||
], | ||
promotedAccessListTitle: '', | ||
created: { seconds: 1729000138n, nanos: 886521000 }, | ||
expires: { seconds: 1729026573n, nanos: 0 }, | ||
maxDuration: { seconds: 1729026573n, nanos: 0 }, | ||
requestTtl: { seconds: 1729026573n, nanos: 0 }, | ||
sessionTtl: { seconds: 1729026573n, nanos: 0 }, | ||
}; | ||
|
||
export function Loaded() { | ||
const appContext = new MockAppContext(); | ||
appContext.tshd.getAccessRequests = () => | ||
new MockedUnaryCall({ | ||
totalCount: 0, | ||
startKey: '', | ||
requests: [mockedAccessRequest], | ||
}); | ||
appContext.workspacesService.setState(draftState => { | ||
draftState.rootClusterUri = rootCluster.uri; | ||
draftState.workspaces[rootCluster.uri] = { | ||
localClusterUri: doc.clusterUri, | ||
documents: [doc], | ||
location: doc.uri, | ||
accessRequests: { | ||
pending: getEmptyPendingAccessRequest(), | ||
isBarCollapsed: true, | ||
}, | ||
}; | ||
}); | ||
|
||
return ( | ||
<AppContextProvider value={appContext}> | ||
<MockWorkspaceContextProvider> | ||
<ResourcesContextProvider> | ||
<DocumentAccessRequests doc={doc} visible={true} /> | ||
</ResourcesContextProvider> | ||
</MockWorkspaceContextProvider> | ||
</AppContextProvider> | ||
); | ||
} | ||
|
||
export function ErrorLoading() { | ||
const appContext = new MockAppContext(); | ||
appContext.tshd.getAccessRequests = () => | ||
new MockedUnaryCall(null, new Error('network error')); | ||
appContext.workspacesService.setState(draftState => { | ||
draftState.rootClusterUri = rootCluster.uri; | ||
draftState.workspaces[rootCluster.uri] = { | ||
localClusterUri: doc.clusterUri, | ||
documents: [doc], | ||
location: doc.uri, | ||
accessRequests: { | ||
pending: getEmptyPendingAccessRequest(), | ||
isBarCollapsed: true, | ||
}, | ||
}; | ||
}); | ||
appContext.clustersService.setState(draftState => { | ||
draftState.clusters.set(rootCluster.uri, rootCluster); | ||
}); | ||
|
||
return ( | ||
<AppContextProvider value={appContext}> | ||
<MockWorkspaceContextProvider> | ||
<ResourcesContextProvider> | ||
<DocumentAccessRequests doc={doc} visible={true} /> | ||
</ResourcesContextProvider> | ||
</MockWorkspaceContextProvider> | ||
</AppContextProvider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.