import React from 'react'; import { SETTINGS } from '../../config'; import type { FetchApplicationManagementDataQuery } from '../graphql/graphql-sdk'; import { FetchApplicationManagementDataDocument, useUpdateGitIntegrationMutation } from '../graphql/graphql-sdk'; import { CheckboxInput, useApplicationContextSafe } from '../../presentation'; import { useLogEvent } from '../utils/logging'; import { useNotifyOnError } from '../utils/useNotifyOnError.hook'; import { Spinner } from '../../widgets/spinners/Spinner'; import './GitIntegration.less'; type IGitIntegrationProps = NonNullable< NonNullable['gitIntegration'] >; const ManifestPath = ({ manifestPath }: Pick) => { const [currentPath, setCurrentPath] = React.useState(manifestPath); const [isEditing, setIsEditing] = React.useState(false); const appName = useApplicationContextSafe().name; const [updateIntegration, { loading }] = useUpdateGitIntegrationMutation({ refetchQueries: [{ query: FetchApplicationManagementDataDocument, variables: { appName } }], onCompleted: () => { setIsEditing(false); }, }); const baseManifestPath = SETTINGS.managedDelivery?.manifestBasePath + '/'; return (
Config file path:{' '} {isEditing ? (
{ e.preventDefault(); updateIntegration({ variables: { payload: { application: appName, manifestPath: currentPath } } }); }} > {baseManifestPath} setCurrentPath(e.target.value)} autoFocus />
) : ( {baseManifestPath} {manifestPath} )} {loading ? ( ) : ( )}
); }; export const GitIntegration = ({ isEnabled, branch, link, repository, manifestPath }: IGitIntegrationProps) => { const appName = useApplicationContextSafe().name; const [updateIntegration, { loading, error }] = useUpdateGitIntegrationMutation({ refetchQueries: [{ query: FetchApplicationManagementDataDocument, variables: { appName } }], }); const logEvent = useLogEvent('GitIntegration'); useNotifyOnError({ key: 'toggleGitIntegration', content: `Failed to ${isEnabled ? 'disable' : 'enable'} auto-import`, error, }); const repoAndBranch = [repository, branch].join(':'); return (
Auto-import delivery config from  {link ? ( e.stopPropagation()}> {repoAndBranch} ) : ( repoAndBranch )} {loading && ( )}
} disabled={loading} onChange={(e: React.ChangeEvent) => { updateIntegration({ variables: { payload: { application: appName, isEnabled: e.target.checked } } }); logEvent({ action: e.target.checked ? 'EnableIntegration' : 'DisableIntegration' }); }} />
Turning this on will automatically import your config from git when a new commit is made to{' '} {branch || 'your main branch'}
); };