Skip to content

Commit

Permalink
feat(settings): Allow linking to personal API key preset (#23047)
Browse files Browse the repository at this point in the history
* feat(settings): Allow linking to personal API key preset

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

* Update UI snapshots for `chromium` (1)

* Update UI snapshots for `chromium` (2)

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Twixes and github-actions[bot] authored Jun 18, 2024
1 parent 5b68eba commit 542da1f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions frontend/src/scenes/settings/user/PersonalAPIKeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ function PersonalAPIKeysTable(): JSX.Element {
loading={keysLoading}
loadingSkeletonRows={3}
className="mt-4"
nouns={['personal API key', 'personal API keys']}
columns={[
{
title: 'Label',
Expand Down
27 changes: 26 additions & 1 deletion frontend/src/scenes/settings/user/personalAPIKeysLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { LemonBanner, LemonDialog } from '@posthog/lemon-ui'
import { actions, afterMount, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { forms } from 'kea-forms'
import { loaders } from 'kea-loaders'
import { actionToUrl, router, urlToAction } from 'kea-router'
import api from 'lib/api'
import { CodeSnippet } from 'lib/components/CodeSnippet'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'

import { OrganizationBasicType, PersonalAPIKeyType, TeamBasicType } from '~/types'
Expand Down Expand Up @@ -323,7 +325,30 @@ export const personalAPIKeysLogic = kea<personalAPIKeysLogicType>([
lemonToast.success(`Personal API key deleted`)
},
})),

urlToAction(({ actions }) => ({
[urls.settings('user-api-keys')]: (_, searchParams) => {
const presetKey = searchParams.preset
if (presetKey) {
const preset = API_KEY_SCOPE_PRESETS.find((preset) => preset.value === presetKey)
if (preset) {
actions.setEditingKeyId('new')
actions.setEditingKeyValues({
preset: preset.value,
label: preset.label,
scopes: preset.scopes,
})
}
}
},
})),
actionToUrl(() => ({
setEditingKeyId: ({ id }) => {
if (!id) {
// When the modal is closed, remove the preset from the URL
return [router.values.location.pathname, {}, router.values.location.hash]
}
},
})),
afterMount(({ actions }) => {
actions.loadAllTeams()
}),
Expand Down

0 comments on commit 542da1f

Please sign in to comment.