From 68229a53c123a791dc8f3d0739bac02f27f69cd4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 16 Dec 2024 18:16:17 +0000 Subject: [PATCH] mds bug fixes (#538) Signed-off-by: saimedhi (cherry picked from commit 292d4ec45b45e75e85e0da90e9a4a04d6bc22e7c) Signed-off-by: github-actions[bot] --- .../pages/workflows/new_workflow/new_workflow.tsx | 12 ++++++++---- .../new_workflow/quick_configure_modal.tsx | 4 ++-- public/pages/workflows/workflows.tsx | 15 ++++++++------- public/utils/utils.ts | 5 +++++ 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/public/pages/workflows/new_workflow/new_workflow.tsx b/public/pages/workflows/new_workflow/new_workflow.tsx index f0c2a537..a8e8c6c3 100644 --- a/public/pages/workflows/new_workflow/new_workflow.tsx +++ b/public/pages/workflows/new_workflow/new_workflow.tsx @@ -27,7 +27,8 @@ import { searchConnectors, } from '../../../store'; import { enrichPresetWorkflowWithUiMetadata } from './utils'; -import { getDataSourceId } from '../../../utils'; +import { getDataSourceId, isDataSourceReady } from '../../../utils'; +import { getDataSourceEnabled } from '../../../services'; interface NewWorkflowProps {} @@ -39,6 +40,7 @@ interface NewWorkflowProps {} export function NewWorkflow(props: NewWorkflowProps) { const dispatch = useAppDispatch(); const dataSourceId = getDataSourceId(); + const dataSourceEnabled = getDataSourceEnabled().enabled; // workflows state const { presetWorkflows, loading } = useSelector( @@ -61,9 +63,11 @@ export function NewWorkflow(props: NewWorkflowProps) { // so we optimize by fetching once at the top-level here. useEffect(() => { dispatch(getWorkflowPresets()); - dispatch(searchModels({ apiBody: FETCH_ALL_QUERY, dataSourceId })); - dispatch(searchConnectors({ apiBody: FETCH_ALL_QUERY, dataSourceId })); - }, []); + if (isDataSourceReady(dataSourceId)) { + dispatch(searchModels({ apiBody: FETCH_ALL_QUERY, dataSourceId })); + dispatch(searchConnectors({ apiBody: FETCH_ALL_QUERY, dataSourceId })); + } + }, [dataSourceId, dataSourceEnabled]); // initial hook to populate all workflows // enrich them with dynamically-generated UI flows based on use case diff --git a/public/pages/workflows/new_workflow/quick_configure_modal.tsx b/public/pages/workflows/new_workflow/quick_configure_modal.tsx index 7949834c..5e43a1d8 100644 --- a/public/pages/workflows/new_workflow/quick_configure_modal.tsx +++ b/public/pages/workflows/new_workflow/quick_configure_modal.tsx @@ -100,8 +100,8 @@ export function QuickConfigureModal(props: QuickConfigureModalProps) { // fetching model interface if available. used to prefill some // of the input/output maps useEffect(() => { - setModelInterface(models[quickConfigureFields.modelId || '']?.interface); - }, [models, quickConfigureFields.modelId]); + setModelInterface(models[quickConfigureFields?.modelId || '']?.interface); + }, [models, quickConfigureFields?.modelId]); return ( props.onClose()} style={{ width: '30vw' }}> diff --git a/public/pages/workflows/workflows.tsx b/public/pages/workflows/workflows.tsx index 9a168e66..ff139ce0 100644 --- a/public/pages/workflows/workflows.tsx +++ b/public/pages/workflows/workflows.tsx @@ -29,7 +29,11 @@ import { FETCH_ALL_QUERY, PLUGIN_NAME } from '../../../common'; import { ImportWorkflowModal } from './import_workflow'; import { MountPoint } from '../../../../../src/core/public'; import { DataSourceSelectableConfig } from '../../../../../src/plugins/data_source_management/public'; -import { dataSourceFilterFn, getDataSourceFromURL } from '../../utils/utils'; +import { + dataSourceFilterFn, + getDataSourceFromURL, + isDataSourceReady, +} from '../../utils/utils'; import { getDataSourceManagementPlugin, getDataSourceEnabled, @@ -102,9 +106,6 @@ export function Workflows(props: WorkflowsProps) { escape(tabFromUrl) as WORKFLOWS_TAB ); - const isDataSourceReady = - !dataSourceEnabled || (dataSourceId && dataSourceId !== ''); - // If there is no selected tab or invalid tab, default to manage tab useEffect(() => { if ( @@ -120,7 +121,7 @@ export function Workflows(props: WorkflowsProps) { useEffect(() => { if (selectedTabId === WORKFLOWS_TAB.MANAGE) { // wait until selected data source is ready before doing dispatch calls if mds is enabled - if (isDataSourceReady) { + if (isDataSourceReady(dataSourceId)) { dispatch( searchWorkflows({ apiBody: FETCH_ALL_QUERY, @@ -145,7 +146,7 @@ export function Workflows(props: WorkflowsProps) { // On initial render: fetch all workflows useEffect(() => { // wait until selected data source is ready before doing dispatch calls if mds is enabled - if (isDataSourceReady) { + if (isDataSourceReady(dataSourceId)) { dispatch( searchWorkflows({ apiBody: FETCH_ALL_QUERY, @@ -168,7 +169,7 @@ export function Workflows(props: WorkflowsProps) { }); } // wait until selected data source is ready before doing dispatch calls if mds is enabled - if (isDataSourceReady) { + if (isDataSourceReady(dataSourceId)) { dispatch( searchWorkflows({ apiBody: FETCH_ALL_QUERY, diff --git a/public/utils/utils.ts b/public/utils/utils.ts index ad0d2654..6db1381e 100644 --- a/public/utils/utils.ts +++ b/public/utils/utils.ts @@ -447,6 +447,11 @@ export const getDataSourceId = () => { return mdsQueryParams.dataSourceId; }; +export const isDataSourceReady = (dataSourceId?: string) => { + const dataSourceEnabled = getDataSourceEnabled().enabled; + return !dataSourceEnabled || (dataSourceId && dataSourceId !== ''); +}; + // converts camelCase to a space-delimited string with the first word capitalized. // useful for converting config IDs (in snake_case) to a formatted form title export function camelCaseToTitleString(snakeCaseString: string): string {