-
Notifications
You must be signed in to change notification settings - Fork 22
fix(admin-ui): Use typescript generated client for Auth Server Config API pages #2455
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
38e803b
fix(admin-ui): Use typescript generated client for Auth Server Config…
syntrydy 19372ae
fix(admin-ui): Use typescript generated client for Auth Server Config…
syntrydy 18380be
fix(admin-ui): Apply code review #2453
syntrydy 8858f1e
fix(admin-ui): Apply code review #2453
syntrydy 5f127d6
fix(admin-ui): Apply code review #2453
syntrydy 05a5cf4
fix(admin-ui): Apply code review #2453
syntrydy e83e7cb
fix(admin-ui): Apply code review #2453
syntrydy bcff224
Merge branch 'main' into admin-ui-2453
syntrydy fcef427
Merge branch 'main' into admin-ui-2453
moabu 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| interface YamlModuleContent { | ||
| components?: { | ||
| schemas?: Record<string, unknown> | ||
| } | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| declare module '*.yaml' { | ||
| const content: YamlModuleContent | ||
| export default content | ||
| } | ||
|
|
||
| declare module '*.yml' { | ||
| const content: YamlModuleContent | ||
| export default content | ||
| } |
123 changes: 0 additions & 123 deletions
123
...n-ui/plugins/auth-server/components/Configuration/ConfigApiConfiguration/ApiConfigForm.js
This file was deleted.
Oops, something went wrong.
116 changes: 116 additions & 0 deletions
116
...-ui/plugins/auth-server/components/Configuration/ConfigApiConfiguration/ApiConfigForm.tsx
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,116 @@ | ||
| import React, { useCallback, useState, useEffect } from 'react' | ||
| import GluuCommitDialog from 'Routes/Apps/Gluu/GluuCommitDialog' | ||
| import { FormGroup } from 'Components' | ||
| import { useNavigate } from 'react-router-dom' | ||
| import spec from '../../../../../configApiSpecs.yaml' | ||
| import { API_CONFIG_WRITE } from 'Utils/PermChecker' | ||
| import { useCedarling } from '@/cedarling' | ||
| import GluuCommitFooter from 'Routes/Apps/Gluu/GluuCommitFooter' | ||
| import JsonPropertyBuilderConfigApi from './JsonPropertyBuilderConfigApi' | ||
| import { toast } from 'react-toastify' | ||
| import type { ApiAppConfiguration, JsonPatch } from './types' | ||
|
|
||
| interface ApiConfigFormProps { | ||
| configuration: ApiAppConfiguration | ||
| onSubmit: (patches: JsonPatch[], message: string) => Promise<void> | ||
| } | ||
|
|
||
| interface SpecSchema { | ||
| components: { | ||
| schemas: { | ||
| ApiAppConfiguration: { | ||
| properties: Record<string, unknown> | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const { properties: schema } = (spec as unknown as SpecSchema).components?.schemas | ||
| ?.ApiAppConfiguration ?? { properties: {} } | ||
|
|
||
| const ApiConfigForm: React.FC<ApiConfigFormProps> = ({ configuration, onSubmit }) => { | ||
| const { hasCedarPermission, authorize } = useCedarling() | ||
| const navigate = useNavigate() | ||
| const [modal, setModal] = useState(false) | ||
| const [patches, setPatches] = useState<JsonPatch[]>([]) | ||
|
|
||
| const operations = patches | ||
|
|
||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| useEffect(() => { | ||
| const authorizePermissions = async () => { | ||
| try { | ||
| await authorize([API_CONFIG_WRITE]) | ||
| } catch (error) { | ||
| console.error('Error authorizing API config permissions:', error) | ||
| } | ||
| } | ||
|
|
||
| authorizePermissions() | ||
| }, [authorize]) | ||
|
|
||
| const toggle = useCallback(() => { | ||
| if (patches?.length > 0) { | ||
| setModal((prev) => !prev) | ||
| } else { | ||
| toast.error('No changes to update') | ||
| } | ||
| }, [patches]) | ||
|
|
||
| const submitForm = useCallback( | ||
| async (userMessage: string) => { | ||
| toggle() | ||
| await onSubmit(patches, userMessage) | ||
| }, | ||
| [toggle, onSubmit, patches], | ||
| ) | ||
|
|
||
| function generateLabel(name: string): string { | ||
| const result = name.replace(/([A-Z])/g, ' $1') | ||
| return result.charAt(0).toUpperCase() + result.slice(1) | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const patchHandler = (patch: JsonPatch) => { | ||
| setPatches((existingPatches) => [...existingPatches, patch]) | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const handleBack = () => { | ||
| navigate('/home/dashboard') | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {Object.keys(configuration).map((propKey) => ( | ||
| <JsonPropertyBuilderConfigApi | ||
| key={propKey} | ||
| propKey={propKey} | ||
| propValue={configuration[propKey as keyof ApiAppConfiguration]} | ||
| lSize={6} | ||
| handler={patchHandler} | ||
| schema={schema[propKey] as { type?: string; items?: { type?: string; enum?: string[] } }} | ||
| doc_category="config_api_properties" | ||
| /> | ||
| ))} | ||
|
|
||
| <FormGroup row></FormGroup> | ||
| {hasCedarPermission(API_CONFIG_WRITE) && ( | ||
| <GluuCommitFooter | ||
| saveHandler={toggle} | ||
| hideButtons={{ back: false }} | ||
| backButtonLabel="Back" | ||
| backButtonHandler={handleBack} | ||
| /> | ||
| )} | ||
|
|
||
| {hasCedarPermission(API_CONFIG_WRITE) && ( | ||
| <GluuCommitDialog | ||
| handler={toggle} | ||
| modal={modal} | ||
| operations={operations} | ||
| onAccept={submitForm} | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default ApiConfigForm | ||
28 changes: 0 additions & 28 deletions
28
...n-ui/plugins/auth-server/components/Configuration/ConfigApiConfiguration/ConfigApiPage.js
This file was deleted.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...-ui/plugins/auth-server/components/Configuration/ConfigApiConfiguration/ConfigApiPage.tsx
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,72 @@ | ||
| import React, { useState } from 'react' | ||
| import ApiConfigForm from './ApiConfigForm' | ||
| import { Card } from 'Components' | ||
| import GluuLoader from 'Routes/Apps/Gluu/GluuLoader' | ||
| import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle' | ||
| import SetTitle from 'Utils/SetTitle' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { useGetConfigApiProperties, usePatchConfigApiProperties } from 'JansConfigApi' | ||
| import { useConfigApiActions } from './hooks' | ||
| import { toast } from 'react-toastify' | ||
| import type { JsonPatch } from './types' | ||
|
|
||
| function ConfigApiPage(): JSX.Element { | ||
| const { t } = useTranslation() | ||
| const { logConfigApiUpdate } = useConfigApiActions() | ||
| const [errorMessage, setErrorMessage] = useState<string | null>(null) | ||
|
|
||
| SetTitle(t('titles.config_api_configuration')) | ||
|
|
||
| const { data: configuration, isLoading, error } = useGetConfigApiProperties() | ||
|
|
||
| const patchConfigMutation = usePatchConfigApiProperties() | ||
|
|
||
| const handleSubmit = async (patches: JsonPatch[], message: string) => { | ||
| try { | ||
| setErrorMessage(null) | ||
|
|
||
| await patchConfigMutation.mutateAsync({ data: patches }) | ||
|
|
||
| try { | ||
| await logConfigApiUpdate(message, { requestBody: patches }) | ||
| } catch (auditError) { | ||
| console.error('Error logging audit:', auditError) | ||
| toast.warning(t('messages.audit_log_failed')) | ||
| } | ||
|
|
||
| toast.success(t('messages.success_in_saving')) | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (err) { | ||
| console.error('Error updating config:', err) | ||
| const errorMsg = err instanceof Error ? err.message : t('messages.error_in_saving') | ||
| setErrorMessage(errorMsg) | ||
| toast.error(errorMsg) | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const loading = patchConfigMutation.isPending || isLoading | ||
|
|
||
| if (error) { | ||
| return ( | ||
| <Card style={applicationStyle.mainCard}> | ||
| <div className="p-4 text-danger"> | ||
| {t('messages.error_in_loading')}: {error instanceof Error ? error.message : String(error)} | ||
| </div> | ||
| </Card> | ||
| ) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return ( | ||
| <GluuLoader blocking={loading}> | ||
| <Card style={applicationStyle.mainCard}> | ||
| {configuration && <ApiConfigForm configuration={configuration} onSubmit={handleSubmit} />} | ||
| {errorMessage && ( | ||
| <div className="alert alert-danger mt-3" role="alert"> | ||
| {errorMessage} | ||
| </div> | ||
| )} | ||
| </Card> | ||
| </GluuLoader> | ||
| ) | ||
| } | ||
|
|
||
| export default ConfigApiPage | ||
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.
Uh oh!
There was an error while loading. Please reload this page.