diff --git a/public/app/features/provisioning/Config/ConfigForm.tsx b/public/app/features/provisioning/Config/ConfigForm.tsx index 5779e017e6a..6b5bf350383 100644 --- a/public/app/features/provisioning/Config/ConfigForm.tsx +++ b/public/app/features/provisioning/Config/ConfigForm.tsx @@ -19,6 +19,7 @@ import { FormPrompt } from 'app/core/components/FormPrompt/FormPrompt'; import { TokenPermissionsInfo } from '../Shared/TokenPermissionsInfo'; import { getGitProviderFields, getLocalProviderFields } from '../Wizard/fields'; +import { InlineSecureValueWarning } from '../components/InlineSecureValueWarning'; import { useCreateOrUpdateRepository } from '../hooks/useCreateOrUpdateRepository'; import { RepositoryFormData } from '../types'; import { dataToSpec } from '../utils/data'; @@ -48,6 +49,7 @@ export function ConfigForm({ data }: ConfigFormProps) { control, formState: { errors, isDirty }, setValue, + setError, watch, getValues, } = useForm({ defaultValues: getDefaultValues(data?.spec) }); @@ -65,6 +67,17 @@ export function ConfigForm({ data }: ConfigFormProps) { const localFields = type === 'local' ? getLocalProviderFields(type) : null; const hasTokenInstructions = getHasTokenInstructions(type); + // TODO: this should be removed after 12.2 is released + useEffect(() => { + if (isGitBased && !data?.secure?.token) { + setTokenConfigured(false); + setError('token', { + type: 'manual', + message: `Enter your ${gitFields?.tokenConfig.label ?? 'access token'}`, + }); + } + }, [data, gitFields, setTokenConfigured, setError, isGitBased]); + useEffect(() => { if (request.isSuccess) { const formData = getValues(); @@ -108,6 +121,7 @@ export function ConfigForm({ data }: ConfigFormProps) { {gitFields && ( <> + )} + )} + {notFound ? ( { + // navigate to edit page, rather than view page + locationService.push(`${PROVISIONING_URL}/${repo.metadata?.name}/edit`); + }} + /> + ); + } + let tooltip: string | undefined = undefined; let color: BadgeColor = 'purple'; let text = 'Unknown'; diff --git a/public/app/features/provisioning/components/InlineSecureValueWarning.tsx b/public/app/features/provisioning/components/InlineSecureValueWarning.tsx new file mode 100644 index 00000000000..9ed4a23b7b1 --- /dev/null +++ b/public/app/features/provisioning/components/InlineSecureValueWarning.tsx @@ -0,0 +1,32 @@ +import { t } from '@grafana/i18n'; +import { Alert } from '@grafana/ui'; +import { Repository } from 'app/api/clients/provisioning/v0alpha1'; + +interface Props { + repo?: Repository; + items?: Repository[]; +} + +// TODO: remove this after 12.2 +export function InlineSecureValueWarning({ repo, items }: Props) { + const isRepoValid = (r?: Repository) => r?.spec?.type === 'local' || !!r?.secure?.token?.name; + + if (isRepoValid(repo)) { + return null; + } + + // When a list is passed in, show an error if anything is missing + if (items?.every(isRepoValid)) { + return null; + } + + return ( + + ); +} diff --git a/public/locales/en-US/grafana.json b/public/locales/en-US/grafana.json index 278716c8265..1111a31316f 100644 --- a/public/locales/en-US/grafana.json +++ b/public/locales/en-US/grafana.json @@ -9039,6 +9039,7 @@ "name-line-width": "Line width", "name-stacking": "Stacking" }, + "inline-token-warning-badge-tooltip": "The method to save the token is to re-enter it in the repository settings.", "inspector": { "inspect-data-tab": { "loading": "Loading", @@ -11442,6 +11443,8 @@ "title-delete-all-configured-repositories": "Delete all configured repositories", "title-legacy-storage-detected": "Legacy storage detected" }, + "inline-secure-values-warning": "You need to save your access tokens again due to a system update", + "inline-token-warning-badge-text": "Token needs to be saved again", "job-status": { "label-view-details": "View details", "loading-finished-job": "Loading finished job...",