123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import {Fragment, useEffect} from 'react';
- import styled from '@emotion/styled';
- import {Alert} from 'sentry/components/alert';
- import Panel from 'sentry/components/panels/panel';
- import PanelBody from 'sentry/components/panels/panelBody';
- import PanelHeader from 'sentry/components/panels/panelHeader';
- import {t} from 'sentry/locale';
- import {space} from 'sentry/styles/space';
- import type {
- OrganizationIntegration,
- ServerlessFunction,
- } from 'sentry/types/integrations';
- import {trackAnalytics} from 'sentry/utils/analytics';
- import {
- type ApiQueryKey,
- setApiQueryData,
- useApiQuery,
- useQueryClient,
- } from 'sentry/utils/queryClient';
- import useOrganization from 'sentry/utils/useOrganization';
- import {IntegrationServerlessRow} from 'sentry/views/settings/organizationIntegrations/integrationServerlessRow';
- export function IntegrationServerlessFunctions({
- integration,
- }: {
- integration: OrganizationIntegration;
- }) {
- const organization = useOrganization();
- const queryClient = useQueryClient();
- const queryKey: ApiQueryKey = [
- `/organizations/${organization.slug}/integrations/${integration.id}/serverless-functions/`,
- ];
- const {data: serverlessFunctions = [], isSuccess} = useApiQuery<ServerlessFunction[]>(
- queryKey,
- {staleTime: 0}
- );
- useEffect(() => {
- if (isSuccess) {
- trackAnalytics('integrations.serverless_functions_viewed', {
- integration: integration.provider.key,
- integration_type: 'first_party',
- num_functions: serverlessFunctions.length,
- organization,
- });
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [isSuccess]);
- return (
- <Fragment>
- <Alert type="info">
- {t(
- 'Manage your AWS Lambda functions below. Only Node and Python runtimes are currently supported.'
- )}
- </Alert>
- <Panel>
- <StyledPanelHeader disablePadding hasButtons>
- <NameHeader>{t('Name')}</NameHeader>
- <LayerStatusWrapper>{t('Layer Status')}</LayerStatusWrapper>
- <EnableHeader>{t('Enabled')}</EnableHeader>
- </StyledPanelHeader>
- <StyledPanelBody>
- {serverlessFunctions.map((serverlessFn, i) => (
- <IntegrationServerlessRow
- key={serverlessFn.name}
- serverlessFunction={serverlessFn}
- integration={integration}
- onUpdate={(update: Partial<ServerlessFunction>) => {
- setApiQueryData<ServerlessFunction[]>(
- queryClient,
- queryKey,
- existingServerlessFunctions => {
- const newServerlessFunctions = [...existingServerlessFunctions];
- const updatedFunction = {
- ...newServerlessFunctions[i],
- ...update,
- };
- newServerlessFunctions[i] = updatedFunction;
- return newServerlessFunctions;
- }
- );
- }}
- />
- ))}
- </StyledPanelBody>
- </Panel>
- </Fragment>
- );
- }
- const StyledPanelHeader = styled(PanelHeader)`
- padding: ${space(2)};
- display: grid;
- grid-column-gap: ${space(1)};
- align-items: center;
- grid-template-columns: 2fr 1fr 0.5fr;
- grid-template-areas: 'function-name layer-status enable-switch';
- `;
- const HeaderText = styled('div')`
- flex: 1;
- `;
- const StyledPanelBody = styled(PanelBody)``;
- const NameHeader = styled(HeaderText)`
- grid-area: function-name;
- `;
- const LayerStatusWrapper = styled(HeaderText)`
- grid-area: layer-status;
- `;
- const EnableHeader = styled(HeaderText)`
- grid-area: enable-switch;
- `;
|