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

Merge pull request #1470 from logto-io/sijie-log-3528-hide-universal-tab

fix(console): hide single platform universal connector tab
This commit is contained in:
Charles Zhao 2022-07-08 21:35:56 +08:00 committed by GitHub
commit 6a965226c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
import { ConnectorDTO } from '@logto/schemas';
import { ConnectorDTO, ConnectorPlatform } from '@logto/schemas';
import classNames from 'classnames';
import React from 'react';
import React, { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import useSWR from 'swr';
@ -19,28 +19,38 @@ const ConnectorTabs = ({ target, connectorId }: Props) => {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
const { data } = useSWR<ConnectorDTO[]>(`/api/connectors?target=${target}`);
if (!data) {
const connectors = useMemo(() => {
if (!data) {
return [];
}
return data.filter(({ enabled }) => enabled);
}, [data]);
if (connectors.length === 0) {
return null;
}
if (connectors.length === 1 && connectors[0]?.platform === ConnectorPlatform.Universal) {
return null;
}
return (
<div className={styles.tabs}>
{data
.filter(({ enabled }) => enabled)
.map((connector) => (
<Link
key={connector.id}
to={`/connectors/${connector.id}`}
className={classNames(styles.tab, connector.id === connectorId && styles.active)}
>
{connector.platform && (
<div className={styles.icon}>
<ConnectorPlatformIcon platform={connector.platform} />
</div>
)}
{connector.platform && t(connectorPlatformLabel[connector.platform])}
</Link>
))}
{connectors.map((connector) => (
<Link
key={connector.id}
to={`/connectors/${connector.id}`}
className={classNames(styles.tab, connector.id === connectorId && styles.active)}
>
{connector.platform && (
<div className={styles.icon}>
<ConnectorPlatformIcon platform={connector.platform} />
</div>
)}
{connector.platform && t(connectorPlatformLabel[connector.platform])}
</Link>
))}
</div>
);
};