mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
7af91c7e9d
https://linear.app/unleash/issue/2-1817/ui-create-an-incoming-webhooks-configuration-page This adds an incoming webhooks page with the respective table. We plan on possibly extending the table with a couple more columns in a future PR. This allows us: - View all configured incoming webhooks; - Copy their URL to the clipboard; - Remove them; For "new" and "edit" operations we still need the incoming webhooks form/dialog, coming in a future PR. **Note**: Even though we are showing the full URL in the table for now, we may end up truncating its start in the future (e.g. `.../api/incoming-webhook/<webhook-name>` - This decision depends on how it will look like after the rest of the columns are added. ![image](https://github.com/Unleash/unleash/assets/14320932/1cac3286-818f-4967-8686-43f78aa6bd33)
159 lines
6.5 KiB
TypeScript
159 lines
6.5 KiB
TypeScript
import { VFC, useState } from 'react';
|
|
import useAddons from 'hooks/api/getters/useAddons/useAddons';
|
|
import { AvailableIntegrations } from './AvailableIntegrations/AvailableIntegrations';
|
|
import { ConfiguredIntegrations } from './ConfiguredIntegrations/ConfiguredIntegrations';
|
|
import { Tab, Tabs, styled, useTheme } from '@mui/material';
|
|
import { Add } from '@mui/icons-material';
|
|
import { Route, Routes, useLocation, useNavigate } from 'react-router-dom';
|
|
import { useUiFlag } from 'hooks/useUiFlag';
|
|
import { useIncomingWebhooks } from 'hooks/api/getters/useIncomingWebhooks/useIncomingWebhooks';
|
|
import { PageContent } from 'component/common/PageContent/PageContent';
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
import { PageHeader } from 'component/common/PageHeader/PageHeader';
|
|
import { TabLink } from 'component/common/TabNav/TabLink';
|
|
import ResponsiveButton from 'component/common/ResponsiveButton/ResponsiveButton';
|
|
import { ADMIN } from 'component/providers/AccessProvider/permissions';
|
|
import { IIncomingWebhook } from 'interfaces/incomingWebhook';
|
|
import { IncomingWebhooks } from 'component/incomingWebhooks/IncomingWebhooks';
|
|
|
|
const StyledHeader = styled('div')(() => ({
|
|
display: 'flex',
|
|
justifyContent: 'space-between',
|
|
alignItems: 'center',
|
|
}));
|
|
|
|
const StyledTabsContainer = styled('div')({
|
|
flex: 1,
|
|
});
|
|
|
|
const StyledActions = styled('div')({
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
});
|
|
|
|
export const IntegrationList: VFC = () => {
|
|
const { pathname } = useLocation();
|
|
const navigate = useNavigate();
|
|
const theme = useTheme();
|
|
const incomingWebhooksEnabled = useUiFlag('incomingWebhooks');
|
|
const { providers, addons, loading } = useAddons();
|
|
const { incomingWebhooks } = useIncomingWebhooks();
|
|
|
|
const [selectedIncomingWebhook, setSelectedIncomingWebhook] =
|
|
useState<IIncomingWebhook>();
|
|
const [incomingWebhookModalOpen, setIncomingWebhookModalOpen] =
|
|
useState(false);
|
|
|
|
const onNewIncomingWebhook = () => {
|
|
navigate('/integrations/incoming-webhooks');
|
|
setSelectedIncomingWebhook(undefined);
|
|
setIncomingWebhookModalOpen(true);
|
|
};
|
|
|
|
const tabs = [
|
|
{
|
|
label: 'Integrations',
|
|
path: '/integrations',
|
|
},
|
|
{
|
|
label: `Incoming webhooks (${incomingWebhooks.length})`,
|
|
path: '/integrations/incoming-webhooks',
|
|
},
|
|
];
|
|
|
|
return (
|
|
<PageContent
|
|
header={
|
|
<ConditionallyRender
|
|
condition={incomingWebhooksEnabled}
|
|
show={
|
|
<StyledHeader>
|
|
<StyledTabsContainer>
|
|
<Tabs
|
|
value={pathname}
|
|
indicatorColor='primary'
|
|
textColor='primary'
|
|
variant='scrollable'
|
|
allowScrollButtonsMobile
|
|
>
|
|
{tabs.map(({ label, path }) => (
|
|
<Tab
|
|
key={label}
|
|
value={path}
|
|
label={
|
|
<TabLink to={path}>
|
|
{label}
|
|
</TabLink>
|
|
}
|
|
sx={{
|
|
padding: 0,
|
|
}}
|
|
/>
|
|
))}
|
|
</Tabs>
|
|
</StyledTabsContainer>
|
|
<StyledActions>
|
|
<ConditionallyRender
|
|
condition={pathname.includes(
|
|
'incoming-webhooks',
|
|
)}
|
|
show={
|
|
<ResponsiveButton
|
|
onClick={onNewIncomingWebhook}
|
|
maxWidth={`${theme.breakpoints.values.sm}px`}
|
|
Icon={Add}
|
|
permission={ADMIN}
|
|
>
|
|
New incoming webhook
|
|
</ResponsiveButton>
|
|
}
|
|
/>
|
|
</StyledActions>
|
|
</StyledHeader>
|
|
}
|
|
elseShow={<PageHeader title='Integrations' />}
|
|
/>
|
|
}
|
|
isLoading={loading}
|
|
withTabs={incomingWebhooksEnabled}
|
|
>
|
|
<Routes>
|
|
<Route
|
|
path='incoming-webhooks'
|
|
element={
|
|
<IncomingWebhooks
|
|
modalOpen={incomingWebhookModalOpen}
|
|
setModalOpen={setIncomingWebhookModalOpen}
|
|
selectedIncomingWebhook={selectedIncomingWebhook}
|
|
setSelectedIncomingWebhook={
|
|
setSelectedIncomingWebhook
|
|
}
|
|
/>
|
|
}
|
|
/>
|
|
<Route
|
|
path='*'
|
|
element={
|
|
<>
|
|
<ConditionallyRender
|
|
condition={addons.length > 0}
|
|
show={
|
|
<ConfiguredIntegrations
|
|
addons={addons}
|
|
providers={providers}
|
|
loading={loading}
|
|
/>
|
|
}
|
|
/>
|
|
<AvailableIntegrations
|
|
providers={providers}
|
|
onNewIncomingWebhook={onNewIncomingWebhook}
|
|
/>
|
|
</>
|
|
}
|
|
/>
|
|
</Routes>
|
|
</PageContent>
|
|
);
|
|
};
|