From 6ced6c945e4f312daa9542275fe5f5f0cad01446 Mon Sep 17 00:00:00 2001 From: karthik Date: Thu, 16 Sep 2021 15:23:41 +0530 Subject: [PATCH] Fix create broker button in Add broker page --- .../components/add/brokers/AddBrokerForm.tsx | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/frontend/packages/knative-plugin/src/components/add/brokers/AddBrokerForm.tsx b/frontend/packages/knative-plugin/src/components/add/brokers/AddBrokerForm.tsx index 07a2409c317..bf52d416f9d 100644 --- a/frontend/packages/knative-plugin/src/components/add/brokers/AddBrokerForm.tsx +++ b/frontend/packages/knative-plugin/src/components/add/brokers/AddBrokerForm.tsx @@ -4,7 +4,7 @@ import { FormikProps } from 'formik'; import * as _ from 'lodash'; import { useTranslation } from 'react-i18next'; import AppSection from '@console/dev-console/src/components/import/app/AppSection'; -import { useAccessReview } from '@console/internal/components/utils'; +import { LoadingInline, useAccessReview2 } from '@console/internal/components/utils'; import { K8sResourceKind } from '@console/internal/module/k8s'; import { FlexForm, @@ -13,6 +13,7 @@ import { FormFooter, YAMLEditorField, UNASSIGNED_APPLICATIONS_KEY, + useFormikValidationFix, } from '@console/shared'; import { EditorType } from '@console/shared/src/components/synced-editor/editor-toggle'; import { safeJSToYAML } from '@console/shared/src/utils/yaml'; @@ -42,7 +43,8 @@ const AddBrokerForm: React.FC & AddBrokerFo setFieldValue, } = formikProps; - const canCreateBroker = useAccessReview({ + useFormikValidationFix(values); + const [canCreateBroker, loadingAccessReview] = useAccessReview2({ group: EventingBrokerModel.apiGroup, resource: EventingBrokerModel.plural, namespace, @@ -119,29 +121,33 @@ const AddBrokerForm: React.FC & AddBrokerFo onSave={handleSubmit} /> ); + + const syncedEditor = canCreateBroker ? ( + + ) : ( + + {t('knative-plugin~You do not have write access in this project.')} + + ); + return ( - {canCreateBroker ? ( - - ) : ( - - {t('knative-plugin~You do not have write access in this project.')} - - )} + {loadingAccessReview && } + {!loadingAccessReview && syncedEditor} & AddBrokerFo isSubmitting={isSubmitting} submitLabel={t('knative-plugin~Create')} disableSubmit={ - (values.editorType === EditorType.YAML ? !dirty : !dirty || !_.isEmpty(errors)) || + !canCreateBroker || + (values.editorType === EditorType.YAML ? !dirty : !_.isEmpty(errors)) || isSubmitting } resetLabel={t('knative-plugin~Cancel')}