0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

chore: update code

This commit is contained in:
Darcy Ye 2024-11-21 16:41:59 +08:00
parent e47545a7bb
commit f478062e13
No known key found for this signature in database
GPG key ID: B46F4C07EDEFC610
4 changed files with 43 additions and 48 deletions

View file

@ -28,6 +28,14 @@ import { isPaidPlan } from '@/utils/subscription';
import Footer from './Footer';
import styles from './index.module.scss';
type AvailableApplicationTypeForCreation = Extract<
ApplicationType,
| ApplicationType.Native
| ApplicationType.SPA
| ApplicationType.Traditional
| ApplicationType.MachineToMachine
>;
type FormData = {
type: ApplicationType;
name: string;
@ -160,22 +168,13 @@ function CreateForm({
onChange={onChange}
>
{Object.values(ApplicationType)
.filter(
(
value
): value is Extract<
ApplicationType,
| ApplicationType.Native
| ApplicationType.SPA
| ApplicationType.Traditional
| ApplicationType.MachineToMachine
> =>
[
ApplicationType.Native,
ApplicationType.SPA,
ApplicationType.Traditional,
ApplicationType.MachineToMachine,
].includes(value)
.filter((value): value is AvailableApplicationTypeForCreation =>
[
ApplicationType.Native,
ApplicationType.SPA,
ApplicationType.Traditional,
ApplicationType.MachineToMachine,
].includes(value)
)
.map((type) => (
<Radio

View file

@ -13,14 +13,7 @@ import TraditionalWebApp from '@/assets/icons/traditional-web-app.svg?react';
type ApplicationIconMap = {
// TODO: @darcy Add SAML icon when we support SAML application in console
[key in Extract<
ApplicationType,
| ApplicationType.Native
| ApplicationType.SPA
| ApplicationType.Traditional
| ApplicationType.MachineToMachine
| ApplicationType.Protected
>]: SvgComponent;
[key in Exclude<ApplicationType, ApplicationType.SAML>]: SvgComponent;
};
export const lightModeApplicationIconMap: ApplicationIconMap = Object.freeze({

View file

@ -27,7 +27,7 @@ function GuideDrawer({ app, secrets, onClose }: Props) {
const [selectedGuide, setSelectedGuide] = useState<SelectedGuide>();
const appType = useMemo(
// SAML application is actually a Traditional application, the same as OIDC applications.
// TODO: @darcy Revisit this section during the implementation of the SAML app guide, note that SAML is currently treated as a Traditional app to prevent TypeScript errors (this is actually feasible since the API for creating SAML apps has not yet been enabled). However, SAML apps cannot modify OIDC config, so the final guide may differ.
() => (app.type === ApplicationType.SAML ? ApplicationType.Traditional : app.type),
[app.type]
);

View file

@ -42,7 +42,7 @@ type FormProps = {
function ConfigForm({
ssoConnector,
applications,
applications: allApplications,
idpInitiatedAuthConfig,
mutateIdpInitiatedConfig,
}: FormProps) {
@ -50,6 +50,21 @@ function ConfigForm({
const { getTo } = useTenantPathname();
const api = useApi();
/**
* See definition of `applicationsSearchUrl`, there is only non-third party SPA/Traditional applications here, and SAML applications are always third party secured by DB schema, we need to manually exclude other application types here to make TypeScript happy.
*/
const applications = useMemo(
() =>
allApplications.filter(
(
application
): application is Omit<Application, 'type'> & {
type: Exclude<ApplicationType, ApplicationType.SAML>;
} => application.type !== ApplicationType.SAML
),
[allApplications]
);
const {
control,
register,
@ -177,29 +192,17 @@ function ConfigForm({
placeholder={t(
'enterprise_sso_details.idp_initiated_auth_config.empty_applications_placeholder'
)}
options={applications
.filter(
(
application
): application is Omit<Application, 'type'> & {
type: Exclude<ApplicationType, ApplicationType.SAML>;
} =>
/**
* See definition of `applicationsSearchUrl`, there is only non-third party SPA/Traditional applications here, and SAML applications are always third party secured by DB schema, we need to manually exclude other application types here to make TypeScript happy.
*/
application.type !== ApplicationType.SAML
)
.map((application) => ({
value: application.id,
title: (
<span>
{application.name}
<span className={styles.applicationDetails}>
({t(`guide.categories.${application.type}`)}, ID: {application.id})
</span>
options={applications.map((application) => ({
value: application.id,
title: (
<span>
{application.name}
<span className={styles.applicationDetails}>
({t(`guide.categories.${application.type}`)}, ID: {application.id})
</span>
),
}))}
</span>
),
}))}
value={value}
error={emptyApplicationsError ?? errors.config?.defaultApplicationId?.message}
onChange={onChange}