0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix(console): optimize loading screens in app guides (#4441)

This commit is contained in:
Charles Zhao 2023-09-06 23:42:11 +08:00 committed by GitHub
parent edfb0e9950
commit 6565dad0e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 39 deletions

View file

@ -52,7 +52,7 @@ const mapToUriOriginFormatArrays = (value?: string[]) =>
function ApplicationDetails() { function ApplicationDetails() {
const { id, guideId, tab } = useParams(); const { id, guideId, tab } = useParams();
const { navigate, match } = useTenantPathname(); const { navigate, match } = useTenantPathname();
const isGuideView = id && guideId && match(`/applications/${id}/guide/${guideId}`); const isGuideView = !!id && !!guideId && match(`/applications/${id}/guide/${guideId}`);
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data, error, mutate } = useSWR<ApplicationResponse, RequestError>( const { data, error, mutate } = useSWR<ApplicationResponse, RequestError>(
@ -145,6 +145,18 @@ function ApplicationDetails() {
setIsReadmeOpen(false); setIsReadmeOpen(false);
}; };
if (isGuideView) {
return (
<GuideModal
guideId={guideId}
app={data}
onClose={(id) => {
navigate(`/applications/${id}`);
}}
/>
);
}
return ( return (
<DetailsPage <DetailsPage
backLink="/applications" backLink="/applications"
@ -242,15 +254,6 @@ function ApplicationDetails() {
</> </>
)} )}
<UnsavedChangesAlertModal hasUnsavedChanges={!isDeleted && isDirty} /> <UnsavedChangesAlertModal hasUnsavedChanges={!isDeleted && isDirty} />
{isGuideView && (
<GuideModal
guideId={guideId}
app={data}
onClose={(id) => {
navigate(`/applications/${id}`);
}}
/>
)}
</DetailsPage> </DetailsPage>
); );
} }

View file

@ -51,7 +51,7 @@ export const GuideContext = createContext<GuideContextType>({
type Props = { type Props = {
className?: string; className?: string;
guideId: string; guideId: string;
app: ApplicationResponse; app?: ApplicationResponse;
isCompact?: boolean; isCompact?: boolean;
onClose: () => void; onClose: () => void;
}; };
@ -67,20 +67,21 @@ function Guide({ className, guideId, app, isCompact, onClose }: Props) {
const memorizedContext = useMemo( const memorizedContext = useMemo(
() => () =>
conditional( conditional(
!!guide && { !!guide &&
metadata: guide.metadata, !!app && {
Logo: guide.Logo, metadata: guide.metadata,
app, Logo: guide.Logo,
endpoint: tenantEndpoint?.toString() ?? '', app,
alternativeEndpoint: conditional(isCustomDomainActive && tenantEndpoint?.toString()), endpoint: tenantEndpoint?.toString() ?? '',
redirectUris: app.oidcClientMetadata.redirectUris, alternativeEndpoint: conditional(isCustomDomainActive && tenantEndpoint?.toString()),
postLogoutRedirectUris: app.oidcClientMetadata.postLogoutRedirectUris, redirectUris: app.oidcClientMetadata.redirectUris,
isCompact: Boolean(isCompact), postLogoutRedirectUris: app.oidcClientMetadata.postLogoutRedirectUris,
sampleUrls: { isCompact: Boolean(isCompact),
origin: 'http://localhost:3001/', sampleUrls: {
callback: 'http://localhost:3001/callback', origin: 'http://localhost:3001/',
}, callback: 'http://localhost:3001/callback',
} },
}
) satisfies GuideContextType | undefined, ) satisfies GuideContextType | undefined,
[guide, app, tenantEndpoint, isCustomDomainActive, isCompact] [guide, app, tenantEndpoint, isCustomDomainActive, isCompact]
); );
@ -88,7 +89,9 @@ function Guide({ className, guideId, app, isCompact, onClose }: Props) {
return ( return (
<> <>
<OverlayScrollbar className={classNames(styles.content, className)}> <OverlayScrollbar className={classNames(styles.content, className)}>
{memorizedContext ? ( {!app && <StepsSkeleton />}
{!!app && !guide && <NotFound className={styles.notFound} />}
{memorizedContext && (
<GuideContext.Provider value={memorizedContext}> <GuideContext.Provider value={memorizedContext}>
<MDXProvider <MDXProvider
components={{ components={{
@ -121,8 +124,6 @@ function Guide({ className, guideId, app, isCompact, onClose }: Props) {
</Suspense> </Suspense>
</MDXProvider> </MDXProvider>
</GuideContext.Provider> </GuideContext.Provider>
) : (
<NotFound className={styles.notFound} />
)} )}
</OverlayScrollbar> </OverlayScrollbar>
{memorizedContext && ( {memorizedContext && (

View file

@ -15,21 +15,14 @@ type Props = {
}; };
function GuideModal({ guideId, app, onClose }: Props) { function GuideModal({ guideId, app, onClose }: Props) {
if (!app) {
return null;
}
const closeModal = () => { const closeModal = () => {
onClose(app.id); if (app) {
onClose(app.id);
}
}; };
return ( return (
<Modal <Modal shouldCloseOnEsc isOpen className={modalStyles.fullScreen} onRequestClose={closeModal}>
shouldCloseOnEsc
isOpen={Boolean(app)}
className={modalStyles.fullScreen}
onRequestClose={closeModal}
>
<div className={styles.modalContainer}> <div className={styles.modalContainer}>
<GuideHeader onClose={closeModal} /> <GuideHeader onClose={closeModal} />
<Guide className={styles.guide} guideId={guideId} app={app} onClose={closeModal} /> <Guide className={styles.guide} guideId={guideId} app={app} onClose={closeModal} />

View file

@ -1,4 +1,5 @@
@use '@/scss/underscore' as _; @use '@/scss/underscore' as _;
@use '@/scss/dimensions' as dim;
.step { .step {
display: flex; display: flex;
@ -6,6 +7,8 @@
padding: _.unit(5) _.unit(6); padding: _.unit(5) _.unit(6);
border-radius: 16px; border-radius: 16px;
background-color: var(--color-layer-1); background-color: var(--color-layer-1);
max-width: dim.$guide-main-content-max-width;
margin: 0 auto;
.index { .index {
@include _.shimmering-animation; @include _.shimmering-animation;