0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-06 20:40:08 -05:00

fix(console): hide single platform universal connector tab

This commit is contained in:
wangsijie 2022-07-08 11:13:23 +08:00
parent 78e06d5c7f
commit 3d944a518b
No known key found for this signature in database
GPG key ID: C72642FE24F7D42B

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>
);
};