-
Couldn't load subscription status.
- Fork 13
Add SCIM UI #2926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
charliepark
wants to merge
27
commits into
main
Choose a base branch
from
scim-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add SCIM UI #2926
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c3cbe1d
Add SCIM tab to UI
charliepark 781338f
Add tests
charliepark 2e9fd5d
Tweak truncation
charliepark 711e286
Use 90 day default for expiration time in mock data
charliepark 9a5b622
revert UI copy change
charliepark 5d0ec9d
TODOs update
charliepark ddc38a0
Remove Delete All from UI and set handler to NotImplemented
charliepark bcaede8
Merge branch 'main' into scim-ui
charliepark 72b0478
npm i
charliepark 1f9d238
update npm and re-run npm i
charliepark f8da78a
merge main and resolve conflicts
charliepark 9c180b5
Remove todo list
charliepark 5ccfbd5
Update import and className ordering
charliepark 732151c
Update path snapshots
charliepark 366107f
tweak height of token pseudo input; order tokens by created_at
charliepark 47e43af
Remove EXPIRES column and content from confirmation modal
charliepark 6769f2f
Simplify mock handler
charliepark 69283da
Revert "Remove EXPIRES column and content from confirmation modal"
charliepark e50b8dd
Set mock token data to have null expiration datetime
charliepark cbe165e
Hide 'Learn about SCIM Auth' text until we have documentation up that…
charliepark 31dbaae
Remove unnecessary test
charliepark fe07125
For desktops, give a min-width to the Expires column so it doesn't fe…
charliepark 8b04094
merge main
david-crespo d7a7f28
SCIM UI tweaks
benjaminleonard 373cf62
Fix funky modal (unrelated to SCIM)
benjaminleonard bb1b6ef
Message spacing tweak
benjaminleonard 0ffff24
Unify input label with others
benjaminleonard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,273 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
|
|
||
| import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table' | ||
| import { useCallback, useMemo, useState } from 'react' | ||
| import { type LoaderFunctionArgs } from 'react-router' | ||
|
|
||
| import { AccessToken24Icon } from '@oxide/design-system/icons/react' | ||
| import { Badge } from '@oxide/design-system/ui' | ||
|
|
||
| import { | ||
| apiQueryClient, | ||
| useApiMutation, | ||
| usePrefetchedApiQuery, | ||
| type ScimClientBearerToken, | ||
| } from '~/api' | ||
| import { getSiloSelector, useSiloSelector } from '~/hooks/use-params' | ||
| import { confirmDelete } from '~/stores/confirm-delete' | ||
| import { addToast } from '~/stores/toast' | ||
| import { useColsWithActions, type MenuAction } from '~/table/columns/action-col' | ||
| import { Columns } from '~/table/columns/common' | ||
| import { Table } from '~/table/Table' | ||
| import { CardBlock } from '~/ui/lib/CardBlock' | ||
| import { CopyToClipboard } from '~/ui/lib/CopyToClipboard' | ||
| import { CreateButton } from '~/ui/lib/CreateButton' | ||
| import { DateTime } from '~/ui/lib/DateTime' | ||
| import { EmptyMessage } from '~/ui/lib/EmptyMessage' | ||
| import { Message } from '~/ui/lib/Message' | ||
| import { Modal } from '~/ui/lib/Modal' | ||
| import { TableEmptyBox } from '~/ui/lib/Table' | ||
| import { Truncate } from '~/ui/lib/Truncate' | ||
|
|
||
| const colHelper = createColumnHelper<ScimClientBearerToken>() | ||
|
|
||
| const EmptyState = () => ( | ||
| <TableEmptyBox border={false}> | ||
| <EmptyMessage | ||
| icon={<AccessToken24Icon />} | ||
| title="No SCIM tokens" | ||
| body="Create a token to see it here" | ||
| /> | ||
| </TableEmptyBox> | ||
| ) | ||
|
|
||
| export async function clientLoader({ params }: LoaderFunctionArgs) { | ||
| const { silo } = getSiloSelector(params) | ||
| await apiQueryClient.prefetchQuery('scimTokenList', { query: { silo } }) | ||
| return null | ||
| } | ||
|
|
||
| export default function SiloScimTab() { | ||
| const siloSelector = useSiloSelector() | ||
| const { data } = usePrefetchedApiQuery('scimTokenList', { | ||
| query: { silo: siloSelector.silo }, | ||
| }) | ||
|
|
||
| // Order tokens by creation date, oldest first | ||
| const tokens = useMemo( | ||
| () => [...data].sort((a, b) => a.timeCreated.getTime() - b.timeCreated.getTime()), | ||
| [data] | ||
| ) | ||
|
|
||
| const [showCreateModal, setShowCreateModal] = useState(false) | ||
| const [createdToken, setCreatedToken] = useState<{ | ||
| id: string | ||
| bearerToken: string | ||
| timeCreated: Date | ||
| timeExpires?: Date | null | ||
| } | null>(null) | ||
|
|
||
| const deleteToken = useApiMutation('scimTokenDelete', { | ||
| onSuccess() { | ||
| apiQueryClient.invalidateQueries('scimTokenList') | ||
| }, | ||
| }) | ||
|
|
||
| const makeActions = useCallback( | ||
| (token: ScimClientBearerToken): MenuAction[] => [ | ||
| { | ||
| label: 'Delete', | ||
| onActivate: confirmDelete({ | ||
| doDelete: () => | ||
| deleteToken.mutateAsync({ | ||
| path: { tokenId: token.id }, | ||
| query: { silo: siloSelector.silo }, | ||
| }), | ||
| label: token.id, | ||
| }), | ||
| }, | ||
| ], | ||
| [deleteToken, siloSelector.silo] | ||
| ) | ||
|
|
||
| const staticColumns = useMemo( | ||
| () => [ | ||
| colHelper.accessor('id', { | ||
| header: 'ID', | ||
| cell: (info) => ( | ||
| <Truncate text={info.getValue()} position="middle" maxLength={18} /> | ||
| ), | ||
| }), | ||
| colHelper.accessor('timeCreated', Columns.timeCreated), | ||
| colHelper.accessor('timeExpires', { | ||
| header: 'Expires', | ||
| cell: (info) => { | ||
| const expires = info.getValue() | ||
| return expires ? ( | ||
| <DateTime date={expires} /> | ||
| ) : ( | ||
| <Badge color="neutral">Never</Badge> | ||
| ) | ||
| }, | ||
| meta: { thClassName: 'lg:w-1/4' }, | ||
| }), | ||
| ], | ||
| [] | ||
| ) | ||
|
|
||
| const columns = useColsWithActions(staticColumns, makeActions, 'Copy token ID') | ||
|
|
||
| const table = useReactTable({ | ||
| data: tokens, | ||
| columns, | ||
| getCoreRowModel: getCoreRowModel(), | ||
| }) | ||
| // const { href, linkText } = docLinks.scim | ||
| return ( | ||
| <> | ||
| <CardBlock> | ||
| <CardBlock.Header | ||
| title="SCIM Bearer Tokens" | ||
| titleId="scim-tokens-label" | ||
| description="Manage authentication tokens for SCIM identity provisioning" | ||
| > | ||
| <CreateButton onClick={() => setShowCreateModal(true)}>Create token</CreateButton> | ||
| </CardBlock.Header> | ||
| <CardBlock.Body> | ||
| {tokens.length === 0 ? ( | ||
| <EmptyState /> | ||
| ) : ( | ||
| <Table | ||
| aria-labelledby="scim-tokens-label" | ||
| table={table} | ||
| className="table-inline" | ||
| /> | ||
| )} | ||
| </CardBlock.Body> | ||
| {/* <CardBlock.Footer> | ||
| <div className="text-sans-md text-raise group-hover:bg-tertiary relative -ml-2 inline-block rounded py-1 pr-7 pl-2"> | ||
| <span className="inline-block max-w-[300px] truncate align-middle"> | ||
| Learn more about{' '} | ||
| <a | ||
| href={href} | ||
| className="text-accent group-hover:text-accent" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| {linkText} | ||
| <OpenLink12Icon className="absolute top-1.5 ml-1 translate-y-[1px]" /> | ||
| </a> | ||
| </span> | ||
| </div> | ||
| </CardBlock.Footer> */} | ||
| </CardBlock> | ||
|
|
||
| {showCreateModal && ( | ||
| <CreateTokenModal | ||
| siloSelector={siloSelector} | ||
| onDismiss={() => setShowCreateModal(false)} | ||
| onSuccess={(token) => { | ||
| setShowCreateModal(false) | ||
| setCreatedToken(token) | ||
| }} | ||
| /> | ||
| )} | ||
|
|
||
| {createdToken && ( | ||
| <TokenCreatedModal token={createdToken} onDismiss={() => setCreatedToken(null)} /> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| function CreateTokenModal({ | ||
| siloSelector, | ||
| onDismiss, | ||
| onSuccess, | ||
| }: { | ||
| siloSelector: { silo: string } | ||
| onDismiss: () => void | ||
| onSuccess: (token: { | ||
| id: string | ||
| bearerToken: string | ||
| timeCreated: Date | ||
| timeExpires?: Date | null | ||
| }) => void | ||
| }) { | ||
| const createToken = useApiMutation('scimTokenCreate', { | ||
| onSuccess(token) { | ||
| apiQueryClient.invalidateQueries('scimTokenList') | ||
| onSuccess(token) | ||
| }, | ||
| onError(err) { | ||
| addToast({ variant: 'error', title: 'Failed to create token', content: err.message }) | ||
| }, | ||
| }) | ||
|
|
||
| return ( | ||
| <Modal isOpen onDismiss={onDismiss} title="Create token"> | ||
| <Modal.Section> | ||
| This token will have access to provision users and groups via SCIM. Store it | ||
| securely and never share it publicly. | ||
| </Modal.Section> | ||
|
|
||
| <Modal.Footer | ||
| onDismiss={onDismiss} | ||
| onAction={() => { | ||
| createToken.mutate({ query: { silo: siloSelector.silo } }) | ||
| }} | ||
| actionText="Create" | ||
| actionLoading={createToken.isPending} | ||
| /> | ||
| </Modal> | ||
| ) | ||
| } | ||
|
|
||
| function TokenCreatedModal({ | ||
| token, | ||
| onDismiss, | ||
| }: { | ||
| token: { | ||
| id: string | ||
| bearerToken: string | ||
| timeCreated: Date | ||
| timeExpires?: Date | null | ||
| } | ||
| onDismiss: () => void | ||
| }) { | ||
| return ( | ||
| <Modal isOpen onDismiss={onDismiss} title="Create token"> | ||
| <Modal.Section> | ||
| <Message | ||
| variant="notice" | ||
| content="This is the only time you'll see this token. Copy it now and store it securely." | ||
| /> | ||
|
|
||
| <div className="mt-4"> | ||
| <div className="text-sans-md text-raise mb-2">Bearer Token</div> | ||
| <div className="text-sans-md text-raise bg-default border-default flex items-stretch rounded border"> | ||
| <div className="flex-1 overflow-hidden px-3 py-2.75 text-ellipsis"> | ||
| {token.bearerToken} | ||
| </div> | ||
| <div className="border-default flex w-8 items-center justify-center border-l"> | ||
| <CopyToClipboard text={token.bearerToken} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </Modal.Section> | ||
|
|
||
| <Modal.Footer | ||
| onDismiss={onDismiss} | ||
| actionText="Done" | ||
| onAction={onDismiss} | ||
| showCancel={false} | ||
| /> | ||
| </Modal> | ||
| ) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we need design polish from @benjaminleonard. I'd put the yellow bit at the top, for one. Maybe put the expiration at the bottom and display it in one line. Could do without the pseudo form field styling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh just kidding. it's a lot closer to the design than I expected. The pseudo-input it too tall though.