Skip to content

Commit

Permalink
mds bug fixes (#538)
Browse files Browse the repository at this point in the history
Signed-off-by: saimedhi <[email protected]>
  • Loading branch information
saimedhi authored Dec 16, 2024
1 parent 40966de commit 292d4ec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
12 changes: 8 additions & 4 deletions public/pages/workflows/new_workflow/new_workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand All @@ -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(
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions public/pages/workflows/new_workflow/quick_configure_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EuiModal onClose={() => props.onClose()} style={{ width: '30vw' }}>
Expand Down
15 changes: 8 additions & 7 deletions public/pages/workflows/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 292d4ec

Please sign in to comment.