Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] mds bug fixes #539

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading