-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more information to session detail page (#1659)
* rename `session` route to `browser-sessions` * add session detail route * stubbed route with userid * get session and display as session tile on session detail page * improve error message * useMemo instead of ref * oauth session detail page * compat session detail * link to session detail from compat and oauth sessions
- Loading branch information
Kerry
committed
Aug 31, 2023
1 parent
21d3d3a
commit 0c267c0
Showing
10 changed files
with
349 additions
and
16 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
96 changes: 96 additions & 0 deletions
96
frontend/src/components/SessionDetail/CompatSessionDetail.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,96 @@ | ||
// Copyright 2022 The Matrix.org Foundation C.I.C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { H3, Button } from "@vector-im/compound-web"; | ||
import { useSetAtom } from "jotai"; | ||
import { useTransition } from "react"; | ||
|
||
import { FragmentType, useFragment } from "../../gql"; | ||
import BlockList from "../BlockList/BlockList"; | ||
import { | ||
COMPAT_SESSION_FRAGMENT, | ||
endCompatSessionFamily, | ||
simplifyUrl, | ||
} from "../CompatSession"; | ||
import DateTime from "../DateTime"; | ||
|
||
import SessionDetails from "./SessionDetails"; | ||
|
||
type Props = { | ||
session: FragmentType<typeof COMPAT_SESSION_FRAGMENT>; | ||
}; | ||
|
||
const CompatSessionDetail: React.FC<Props> = ({ session }) => { | ||
const [pending, startTransition] = useTransition(); | ||
const data = useFragment(COMPAT_SESSION_FRAGMENT, session); | ||
const endSession = useSetAtom(endCompatSessionFamily(data.id)); | ||
|
||
// @TODO(kerrya) make this wait for session refresh properly | ||
// https://github.com/matrix-org/matrix-authentication-service/issues/1533 | ||
const onSessionEnd = (): void => { | ||
startTransition(() => { | ||
endSession(); | ||
}); | ||
}; | ||
|
||
const finishedAt = data.finishedAt | ||
? [{ label: "Finished", value: <DateTime datetime={data.createdAt} /> }] | ||
: []; | ||
const sessionDetails = [ | ||
{ label: "ID", value: <code>{data.id}</code> }, | ||
{ label: "Device ID", value: <code>{data.deviceId}</code> }, | ||
{ label: "Signed in", value: <DateTime datetime={data.createdAt} /> }, | ||
...finishedAt, | ||
]; | ||
|
||
const clientName = data.ssoLogin?.redirectUri | ||
? simplifyUrl(data.ssoLogin.redirectUri) | ||
: undefined; | ||
|
||
const clientDetails = [ | ||
{ label: "Name", value: clientName }, | ||
{ | ||
label: "Uri", | ||
value: ( | ||
<a target="_blank" href={data.ssoLogin?.redirectUri}> | ||
{data.ssoLogin?.redirectUri} | ||
</a> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div> | ||
<BlockList> | ||
<H3>{data.deviceId || data.id}</H3> | ||
<SessionDetails title="Session" details={sessionDetails} /> | ||
<SessionDetails title="Client" details={clientDetails} /> | ||
{!data.finishedAt && ( | ||
<Button | ||
kind="destructive" | ||
size="sm" | ||
onClick={onSessionEnd} | ||
disabled={pending} | ||
> | ||
{/* @TODO(kerrya) put this back after pending state works properly */} | ||
{/* { pending && <LoadingSpinner />} */} | ||
End session | ||
</Button> | ||
)} | ||
</BlockList> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CompatSessionDetail; |
113 changes: 113 additions & 0 deletions
113
frontend/src/components/SessionDetail/OAuth2SessionDetail.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,113 @@ | ||
// Copyright 2022 The Matrix.org Foundation C.I.C. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import { H3, Button } from "@vector-im/compound-web"; | ||
import { useSetAtom } from "jotai"; | ||
import { useTransition } from "react"; | ||
|
||
import { FragmentType, useFragment } from "../../gql"; | ||
import { getDeviceIdFromScope } from "../../utils/deviceIdFromScope"; | ||
import BlockList from "../BlockList/BlockList"; | ||
import DateTime from "../DateTime"; | ||
import { | ||
OAUTH2_SESSION_FRAGMENT, | ||
Oauth2SessionType, | ||
endSessionFamily, | ||
} from "../OAuth2Session"; | ||
|
||
import SessionDetails from "./SessionDetails"; | ||
|
||
type Props = { | ||
session: FragmentType<typeof OAUTH2_SESSION_FRAGMENT>; | ||
}; | ||
|
||
const OAuth2SessionDetail: React.FC<Props> = ({ session }) => { | ||
const [pending, startTransition] = useTransition(); | ||
const data = useFragment( | ||
OAUTH2_SESSION_FRAGMENT, | ||
session, | ||
) as Oauth2SessionType; | ||
const endSession = useSetAtom(endSessionFamily(data.id)); | ||
|
||
// @TODO(kerrya) make this wait for session refresh properly | ||
// https://github.com/matrix-org/matrix-authentication-service/issues/1533 | ||
const onSessionEnd = (): void => { | ||
startTransition(() => { | ||
endSession(); | ||
}); | ||
}; | ||
|
||
const deviceId = getDeviceIdFromScope(data.scope); | ||
|
||
const scopes = data.scope.split(" "); | ||
|
||
const finishedAt = data.finishedAt | ||
? [{ label: "Finished", value: <DateTime datetime={data.createdAt} /> }] | ||
: []; | ||
const sessionDetails = [ | ||
{ label: "ID", value: <code>{data.id}</code> }, | ||
{ label: "Device ID", value: <code>{deviceId}</code> }, | ||
{ label: "Signed in", value: <DateTime datetime={data.createdAt} /> }, | ||
...finishedAt, | ||
{ | ||
label: "Scopes", | ||
value: ( | ||
<> | ||
{scopes.map((scope) => ( | ||
<p> | ||
<code key={scope}>{scope}</code> | ||
</p> | ||
))} | ||
</> | ||
), | ||
}, | ||
]; | ||
|
||
const clientDetails = [ | ||
{ label: "Name", value: data.client.clientName }, | ||
{ label: "ID", value: <code>{data.client.clientId}</code> }, | ||
{ | ||
label: "Uri", | ||
value: ( | ||
<a target="_blank" href={data.client.clientUri}> | ||
{data.client.clientUri} | ||
</a> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<div> | ||
<BlockList> | ||
<H3>{deviceId || data.id}</H3> | ||
<SessionDetails title="Session" details={sessionDetails} /> | ||
<SessionDetails title="Client" details={clientDetails} /> | ||
{!data.finishedAt && ( | ||
<Button | ||
kind="destructive" | ||
size="sm" | ||
onClick={onSessionEnd} | ||
disabled={pending} | ||
> | ||
{/* @TODO(kerrya) put this back after pending state works properly */} | ||
{/* { pending && <LoadingSpinner />} */} | ||
End session | ||
</Button> | ||
)} | ||
</BlockList> | ||
</div> | ||
); | ||
}; | ||
|
||
export default OAuth2SessionDetail; |
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
36 changes: 36 additions & 0 deletions
36
frontend/src/components/SessionDetail/SessionDetails.module.css
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,36 @@ | ||
/* Copyright 2023 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
.list { | ||
display: flex; | ||
flex-direction: column; | ||
margin-top: var(--cpd-space-1x); | ||
gap: var(--cpd-space-1x); | ||
} | ||
|
||
.detail-row { | ||
display: flex; | ||
flex-direction: row; | ||
gap: var(--cpd-space-4x); | ||
} | ||
|
||
.detail-label { | ||
flex: 0 0 20%; | ||
color: var(--cpd-color-text-secondary); | ||
} | ||
|
||
.detail-value { | ||
overflow-wrap: anywhere; | ||
} |
Oops, something went wrong.