From 666f7783c313ba4e5d861588819cc0298d545f21 Mon Sep 17 00:00:00 2001 From: Samiul Monir <150824886+Samiul-TheSoccerFan@users.noreply.github.com> Date: Tue, 11 Feb 2025 14:47:13 -0500 Subject: [PATCH] [Search]: Fix Number type field to have correct property (#210462) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This PR includes the following updates: - Converted `readOnly` fields to `disabled` to ensure consistency across all view-only fields. - Added an `isPreconfigured` check to disable the `num_allocations` field. While `num_allocations` is the only updatable field for `Elasticsearch` services, it cannot be modified if the endpoint is preconfigured. ### Not preconfigured ![Screenshot 2025-02-10 at 3 54 32 PM](https://github.com/user-attachments/assets/a70aa6a4-69b5-4f75-95ba-f3793b6992d2) ### Preconfigured ![Screenshot 2025-02-10 at 3 54 19 PM](https://github.com/user-attachments/assets/4e174b33-307a-4707-974e-a91e1ca56649) ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit dc0ccc4b7db1ce7fd449618ffc5c4efb58936326) --- .../configuration/configuration_field.tsx | 7 +++- .../configuration_form_items.tsx | 3 ++ .../inference_flyout_wrapper.test.tsx | 34 +++++++++++++++++++ .../components/inference_flyout_wrapper.tsx | 13 ++++--- .../inference_service_form_fields.tsx | 3 ++ 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_field.tsx b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_field.tsx index e82eba9798d51..69c5b75253399 100644 --- a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_field.tsx +++ b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_field.tsx @@ -25,6 +25,7 @@ interface ConfigurationFieldProps { isLoading: boolean; setConfigValue: (value: number | string | boolean | null) => void; isEdit?: boolean; + isPreconfigured?: boolean; } interface ConfigInputFieldProps { @@ -32,6 +33,7 @@ interface ConfigInputFieldProps { isLoading: boolean; validateAndSetConfigValue: (value: string | boolean) => void; isEdit?: boolean; + isPreconfigured?: boolean; } export const ConfigInputField: React.FC = ({ configEntry, @@ -117,6 +119,7 @@ export const ConfigNumberField: React.FC = ({ isLoading, validateAndSetConfigValue, isEdit, + isPreconfigured, }) => { const { isValid, value, default_value: defaultValue, key, updatable } = configEntry; const [innerValue, setInnerValue] = useState(value ?? defaultValue); @@ -126,7 +129,7 @@ export const ConfigNumberField: React.FC = ({ return ( = ({ isLoading, setConfigValue, isEdit, + isPreconfigured, }) => { const validateAndSetConfigValue = (value: number | string | boolean) => { setConfigValue(ensureCorrectTyping(configEntry.type, value)); @@ -204,6 +208,7 @@ export const ConfigurationField: React.FC = ({ configEntry={configEntry} validateAndSetConfigValue={validateAndSetConfigValue} isEdit={isEdit} + isPreconfigured={isPreconfigured} /> ); diff --git a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_form_items.tsx b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_form_items.tsx index fd2142d3ecafe..7993b8dff420c 100644 --- a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_form_items.tsx +++ b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/configuration/configuration_form_items.tsx @@ -26,6 +26,7 @@ interface ConfigurationFormItemsProps { setConfigEntry: (key: string, value: string | number | boolean | null) => void; direction?: 'column' | 'row' | 'rowReverse' | 'columnReverse' | undefined; isEdit?: boolean; + isPreconfigured?: boolean; } export const ConfigurationFormItems: React.FC = ({ @@ -34,6 +35,7 @@ export const ConfigurationFormItems: React.FC = ({ setConfigEntry, direction, isEdit, + isPreconfigured, }) => { return ( @@ -76,6 +78,7 @@ export const ConfigurationFormItems: React.FC = ({ setConfigEntry(key, value); }} isEdit={isEdit} + isPreconfigured={isPreconfigured} /> {sensitive ? ( diff --git a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.test.tsx b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.test.tsx index 70e6033ff966e..51e65be1e534e 100644 --- a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.test.tsx +++ b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.test.tsx @@ -164,4 +164,38 @@ describe('InferenceFlyout', () => { renderComponent({ isEdit: true, inferenceEndpoint: mockEndpoint }); expect(screen.getByTestId('inference-endpoint-submit-button')).toBeDisabled(); }); + + it('disables the num_allocations field for preconfigured endpoints', () => { + const mockEndpoint = { + config: { + inferenceId: '.test-id', + provider: 'elasticsearch', + taskType: 'text_embedding', + providerConfig: {}, + }, + secrets: { + providerSecrets: {}, + }, + }; + + renderComponent({ isEdit: true, inferenceEndpoint: mockEndpoint }); + expect(screen.getByTestId('num_allocations-number')).toBeDisabled(); + }); + + it('the num_allocations field is enabled for other endpoints', () => { + const mockEndpoint = { + config: { + inferenceId: 'test-id', + provider: 'elasticsearch', + taskType: 'text_embedding', + providerConfig: {}, + }, + secrets: { + providerSecrets: {}, + }, + }; + + renderComponent({ isEdit: true, inferenceEndpoint: mockEndpoint }); + expect(screen.getByTestId('num_allocations-number')).toBeEnabled(); + }); }); diff --git a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.tsx b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.tsx index 768dae692f01b..f9078f3da6cb0 100644 --- a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.tsx +++ b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_flyout_wrapper.tsx @@ -78,6 +78,8 @@ export const InferenceFlyoutWrapper: React.FC = ({ mutate(data, !!isEdit); }, [form, isEdit, mutate]); + const isPreconfigured = inferenceEndpoint?.config.inferenceId.startsWith('.'); + return ( = ({
- + @@ -102,9 +109,7 @@ export const InferenceFlyoutWrapper: React.FC = ({ size="m" isLoading={form.isSubmitting || isLoading} disabled={ - (!form.isValid && form.isSubmitted) || - isLoading || - inferenceEndpoint?.config.inferenceId.startsWith('.') // Disable edit option for preconfigured endpoints + (!form.isValid && form.isSubmitted) || isLoading || isPreconfigured // Disable edit option for preconfigured endpoints } data-test-subj="inference-endpoint-submit-button" onClick={handleSubmit} diff --git a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_service_form_fields.tsx b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_service_form_fields.tsx index 51a8603809b79..411133f9dd95a 100644 --- a/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_service_form_fields.tsx +++ b/x-pack/platform/packages/shared/kbn-inference-endpoint-ui-common/src/components/inference_service_form_fields.tsx @@ -48,12 +48,14 @@ interface InferenceServicesProps { http: HttpSetup; toasts: IToasts; isEdit?: boolean; + isPreconfigured?: boolean; } export const InferenceServiceFormFields: React.FC = ({ http, toasts, isEdit, + isPreconfigured, }) => { const { data: providers, isLoading } = useProviders(http, toasts); const [updatedProviders, setUpdatedProviders] = useState( @@ -412,6 +414,7 @@ export const InferenceServiceFormFields: React.FC = ({ items={requiredProviderFormFields} setConfigEntry={onSetProviderConfigEntry} isEdit={isEdit} + isPreconfigured={isPreconfigured} />