import PropTypes from 'prop-types';
import * as React from 'react';
import {
Link,
Route,
Navigate,
Routes,
useParams,
useMatch,
useNavigate,
} from 'react-router-dom';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Grid';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import AddIcon from '@mui/icons-material/Add';
import useFormatMessage from 'hooks/useFormatMessage';
import useAppConfig from 'hooks/useAppConfig.ee';
import useCurrentUserAbility from 'hooks/useCurrentUserAbility';
import * as URLS from 'config/urls';
import SplitButton from 'components/SplitButton';
import ConditionalIconButton from 'components/ConditionalIconButton';
import AppConnections from 'components/AppConnections';
import AppFlows from 'components/AppFlows';
import AddAppConnection from 'components/AddAppConnection';
import AppIcon from 'components/AppIcon';
import Container from 'components/Container';
import PageTitle from 'components/PageTitle';
import useApp from 'hooks/useApp';
import useAppAuthClients from 'hooks/useAppAuthClients';
import Can from 'components/Can';
import { AppPropType } from 'propTypes/propTypes';
const ReconnectConnection = (props) => {
const { application, onClose } = props;
const { connectionId } = useParams();
return (
);
};
ReconnectConnection.propTypes = {
application: AppPropType.isRequired,
onClose: PropTypes.func.isRequired,
};
export default function Application() {
const theme = useTheme();
const matchSmallScreens = useMediaQuery(theme.breakpoints.down('md'));
const formatMessage = useFormatMessage();
const connectionsPathMatch = useMatch({
path: URLS.APP_CONNECTIONS_PATTERN,
end: false,
});
const flowsPathMatch = useMatch({ path: URLS.APP_FLOWS_PATTERN, end: false });
const { appKey } = useParams();
const navigate = useNavigate();
const { data: appAuthClients } = useAppAuthClients(appKey);
const { data, loading } = useApp(appKey);
const app = data?.data || {};
const { data: appConfig } = useAppConfig(appKey);
const currentUserAbility = useCurrentUserAbility();
const goToApplicationPage = () => navigate('connections');
const connectionOptions = React.useMemo(() => {
const addCustomConnection = {
label: formatMessage('app.addConnection'),
key: 'addConnection',
'data-test': 'add-connection-button',
to: URLS.APP_ADD_CONNECTION(appKey, false),
disabled:
!currentUserAbility.can('create', 'Connection') ||
appConfig?.data?.useOnlyPredefinedAuthClients === true ||
appConfig?.data?.disabled === true,
};
const addConnectionWithAuthClient = {
label: formatMessage('app.addConnectionWithAuthClient'),
key: 'addConnectionWithAuthClient',
'data-test': 'add-connection-with-auth-client-button',
to: URLS.APP_ADD_CONNECTION(appKey, true),
disabled:
!currentUserAbility.can('create', 'Connection') ||
appAuthClients?.data?.length === 0 ||
appConfig?.data?.disabled === true,
};
// means there is no app config. defaulting to custom connections only
if (!appConfig?.data) {
return [addCustomConnection];
}
// means only auth clients are allowed for connection creation
if (appConfig?.data?.useOnlyPredefinedAuthClients === true) {
return [addConnectionWithAuthClient];
}
// means there is no app auth client. so we don't show the `addConnectionWithAuthClient`
if (appAuthClients?.data?.length === 0) {
return [addCustomConnection];
}
return [addCustomConnection, addConnectionWithAuthClient];
}, [appKey, appConfig, appAuthClients, currentUserAbility, formatMessage]);
if (loading) return null;
return (
<>
{app.name}
{(allowed) => (
}
disabled={!allowed}
>
{formatMessage('app.createFlow')}
)}
}
/>
{(allowed) => (
)}
}
/>
}
/>
}
/>
}
/>
}
/>
}
/>
>
);
}