-
-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console, phrases): update the supported webhook events (#5856)
* test(core): add integration tests add integration tests for interaction hooks * chore(test): remove legacy test remove legacy test * feat(console, phrases): update the supported webhook events update the supported webhook events * refactor(console): rename webhook and webhook log keys rename webhook and webhook log keys * fix(test): fix integration test fix integration test * feat(console): add devFeature guard add devFeature guard * chore: add changeset add changeset * chore(console): remove the lint rule disable comment remove the lint rule disable comment * fix(test): fix the integartion tests fix the integration tests * fix(console): refine the code refine the code * chore(console): refine comments refine comments
- Loading branch information
Showing
30 changed files
with
438 additions
and
151 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
"@logto/console": patch | ||
"@logto/phrases": patch | ||
--- | ||
|
||
replace the i18n translated hook event label with the hook event value directly in the console | ||
|
||
- remove all the legacy interaction hook events i18n phrases | ||
- replace the translated label with the hook event value directly in the console | ||
- `Create new account` -> `PostRegister` | ||
- `Sign in` -> `PostSignIn` | ||
- `Reset password` -> `PostResetPassword` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,58 @@ | ||
import { type AdminConsoleKey } from '@logto/phrases'; | ||
import { InteractionHookEvent, type LogKey } from '@logto/schemas'; | ||
import { | ||
DataHookSchema, | ||
InteractionHookEvent, | ||
hookEvents, | ||
type DataHookEvent, | ||
} from '@logto/schemas'; | ||
|
||
type HookEventLabel = { | ||
// TODO: Implement all hook events | ||
[key in InteractionHookEvent]: AdminConsoleKey; | ||
}; | ||
export const dataHookEventsLabel = Object.freeze({ | ||
[DataHookSchema.User]: 'webhooks.schemas.user', | ||
[DataHookSchema.Organization]: 'webhooks.schemas.organization', | ||
[DataHookSchema.Role]: 'webhooks.schemas.role', | ||
[DataHookSchema.Scope]: 'webhooks.schemas.scope', | ||
[DataHookSchema.OrganizationRole]: 'webhooks.schemas.organization_role', | ||
[DataHookSchema.OrganizationScope]: 'webhooks.schemas.organization_scope', | ||
} satisfies Record<DataHookSchema, AdminConsoleKey>); | ||
|
||
export const interactionHookEvents = Object.values(InteractionHookEvent); | ||
|
||
const dataHookEvents: DataHookEvent[] = hookEvents.filter( | ||
// eslint-disable-next-line no-restricted-syntax | ||
(event): event is DataHookEvent => !interactionHookEvents.includes(event as InteractionHookEvent) | ||
); | ||
|
||
const isDataHookSchema = (schema: string): schema is DataHookSchema => | ||
// eslint-disable-next-line no-restricted-syntax | ||
Object.values(DataHookSchema).includes(schema as DataHookSchema); | ||
|
||
// Group DataHook events by schema | ||
// TODO: Replace this using `groupBy` once Node v22 goes LTS | ||
const schemaGroupedDataHookEventsMap = dataHookEvents.reduce<Map<DataHookSchema, DataHookEvent[]>>( | ||
(eventGroup, event) => { | ||
const [schema] = event.split('.'); | ||
|
||
if (schema && isDataHookSchema(schema)) { | ||
eventGroup.set(schema, [...(eventGroup.get(schema) ?? []), event]); | ||
} | ||
|
||
export const hookEventLabel = Object.freeze({ | ||
[InteractionHookEvent.PostRegister]: 'webhooks.events.post_register', | ||
[InteractionHookEvent.PostResetPassword]: 'webhooks.events.post_reset_password', | ||
[InteractionHookEvent.PostSignIn]: 'webhooks.events.post_sign_in', | ||
}) satisfies HookEventLabel; | ||
return eventGroup; | ||
}, | ||
new Map() | ||
); | ||
|
||
type HookEventLogKey = { | ||
// TODO: Implement all hook events | ||
[key in InteractionHookEvent]: LogKey; | ||
// Sort the grouped `DataHook` events per console product design | ||
const hookEventSchemaOrder: { | ||
[key in DataHookSchema]: number; | ||
} = { | ||
[DataHookSchema.User]: 0, | ||
[DataHookSchema.Organization]: 1, | ||
[DataHookSchema.Role]: 2, | ||
[DataHookSchema.OrganizationRole]: 3, | ||
[DataHookSchema.Scope]: 4, | ||
[DataHookSchema.OrganizationScope]: 5, | ||
}; | ||
|
||
export const hookEventLogKey = Object.freeze({ | ||
[InteractionHookEvent.PostRegister]: 'TriggerHook.PostRegister', | ||
[InteractionHookEvent.PostResetPassword]: 'TriggerHook.PostResetPassword', | ||
[InteractionHookEvent.PostSignIn]: 'TriggerHook.PostSignIn', | ||
}) satisfies HookEventLogKey; | ||
export const schemaGroupedDataHookEvents = Array.from(schemaGroupedDataHookEventsMap.entries()) | ||
.slice() | ||
.sort(([schemaA], [schemaB]) => hookEventSchemaOrder[schemaA] - hookEventSchemaOrder[schemaB]); |
14 changes: 14 additions & 0 deletions
14
packages/console/src/ds-components/Checkbox/CategorizedCheckboxGroup/index.module.scss
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,14 @@ | ||
@use '@/scss/underscore' as _; | ||
|
||
.groupTitle { | ||
font: var(--font-body-2); | ||
color: var(--color-text-secondary); | ||
margin-bottom: _.unit(2); | ||
} | ||
|
||
.groupList { | ||
// Max two columns | ||
gap: _.unit(5); | ||
display: grid; | ||
grid-template-columns: repeat(2, 1fr); | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/console/src/ds-components/Checkbox/CategorizedCheckboxGroup/index.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,42 @@ | ||
import { type AdminConsoleKey } from '@logto/phrases'; | ||
import classNames from 'classnames'; | ||
|
||
import DynamicT from '@/ds-components/DynamicT'; | ||
|
||
import CheckboxGroup, { type Option } from '../CheckboxGroup'; | ||
|
||
import * as styles from './index.module.scss'; | ||
|
||
export type CheckboxOptionGroup<T> = { | ||
title: AdminConsoleKey; | ||
options: Array<Option<T>>; | ||
}; | ||
|
||
type Props<T> = { | ||
readonly groups: Array<CheckboxOptionGroup<T>>; | ||
readonly value: T[]; | ||
readonly onChange: (value: T[]) => void; | ||
readonly className?: string; | ||
}; | ||
|
||
function CategorizedCheckboxGroup<T extends string>({ | ||
groups, | ||
value: checkedValues, | ||
onChange, | ||
className, | ||
}: Props<T>) { | ||
return ( | ||
<div className={classNames(styles.groupList, className)}> | ||
{groups.map(({ title, options }) => ( | ||
<div key={title}> | ||
<div className={styles.groupTitle}> | ||
<DynamicT forKey={title} /> | ||
</div> | ||
<CheckboxGroup options={options} value={checkedValues} onChange={onChange} /> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default CategorizedCheckboxGroup; |
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
Oops, something went wrong.