mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
feat(console): show standard connector name in table (#2791)
This commit is contained in:
parent
66b72ddbce
commit
bd9abaa509
1 changed files with 23 additions and 2 deletions
|
@ -1,10 +1,13 @@
|
||||||
import type { ConnectorResponse } from '@logto/schemas';
|
import type { ConnectorFactoryResponse, ConnectorResponse } from '@logto/schemas';
|
||||||
import { ConnectorType } from '@logto/schemas';
|
import { ConnectorType } from '@logto/schemas';
|
||||||
import { conditional } from '@silverhand/essentials';
|
import { conditional } from '@silverhand/essentials';
|
||||||
|
import { useMemo } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
import Status from '@/components/Status';
|
import Status from '@/components/Status';
|
||||||
|
import UnnamedTrans from '@/components/UnnamedTrans';
|
||||||
import { connectorTitlePlaceHolder } from '@/consts/connectors';
|
import { connectorTitlePlaceHolder } from '@/consts/connectors';
|
||||||
import { ConnectorsTabs } from '@/consts/page-tabs';
|
import { ConnectorsTabs } from '@/consts/page-tabs';
|
||||||
import useConnectorInUse from '@/hooks/use-connector-in-use';
|
import useConnectorInUse from '@/hooks/use-connector-in-use';
|
||||||
|
@ -25,6 +28,16 @@ const ConnectorRow = ({ type, connectors, onClickSetup }: Props) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const showSetupButton = type !== ConnectorType.Social && !firstConnector;
|
const showSetupButton = type !== ConnectorType.Social && !firstConnector;
|
||||||
|
|
||||||
|
const standardConnectors = connectors.filter(({ isStandard }) => isStandard);
|
||||||
|
|
||||||
|
if (standardConnectors.length > 1) {
|
||||||
|
throw new Error('More than one standard connectors with the same target is not supported.');
|
||||||
|
}
|
||||||
|
const firstStandardConnector = standardConnectors[0];
|
||||||
|
const { data: connectorFactory } = useSWR<ConnectorFactoryResponse>(
|
||||||
|
firstStandardConnector && `/api/connector-factories/${firstStandardConnector.connectorId}`
|
||||||
|
);
|
||||||
|
|
||||||
const handleClickRow = () => {
|
const handleClickRow = () => {
|
||||||
if (showSetupButton || !firstConnector) {
|
if (showSetupButton || !firstConnector) {
|
||||||
return;
|
return;
|
||||||
|
@ -39,12 +52,20 @@ const ConnectorRow = ({ type, connectors, onClickSetup }: Props) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const connectorTypeColumn = useMemo(() => {
|
||||||
|
if (!firstStandardConnector) {
|
||||||
|
return t(connectorTitlePlaceHolder[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return connectorFactory && <UnnamedTrans resource={connectorFactory.name} />;
|
||||||
|
}, [type, connectorFactory, t, firstStandardConnector]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className={conditional(!showSetupButton && tableStyles.clickable)} onClick={handleClickRow}>
|
<tr className={conditional(!showSetupButton && tableStyles.clickable)} onClick={handleClickRow}>
|
||||||
<td>
|
<td>
|
||||||
<ConnectorName type={type} connectors={connectors} onClickSetup={onClickSetup} />
|
<ConnectorName type={type} connectors={connectors} onClickSetup={onClickSetup} />
|
||||||
</td>
|
</td>
|
||||||
<td>{t(connectorTitlePlaceHolder[type])}</td>
|
<td>{connectorTypeColumn}</td>
|
||||||
<td>
|
<td>
|
||||||
{inUse !== undefined && (
|
{inUse !== undefined && (
|
||||||
<Status status={inUse ? 'enabled' : 'disabled'}>
|
<Status status={inUse ? 'enabled' : 'disabled'}>
|
||||||
|
|
Loading…
Reference in a new issue