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

Fixing MDS Support #2

Merged
merged 1 commit into from
Aug 2, 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
11 changes: 7 additions & 4 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Node, Edge } from 'reactflow';
import { FormikValues } from 'formik';
import { ObjectSchema } from 'yup';
import { COMPONENT_CLASS, PROCESSOR_TYPE, WORKFLOW_TYPE } from './constants';
import { MDSQueryParams } from '../server/types';

export type Index = {
name: string;
Expand All @@ -17,12 +16,16 @@ export type Index = {
/**
********** WORKFLOW TYPES/INTERFACES **********
*/
export type MDSQueryParams = {
dataSourceId: string;
};

export interface MDSStates {
export interface MDSStates {
queryParams: MDSQueryParams;
selectedDataSourceId: string | undefined;
selectedDataSourceId?: string;
}
export type ConfigFieldType =

export type ConfigFieldType =
| 'string'
| 'json'
| 'jsonArray'
Expand Down
15 changes: 15 additions & 0 deletions common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@

import moment from 'moment';
import { DATE_FORMAT_PATTERN } from './';
import { isEmpty } from 'lodash';

export function toFormattedDate(timestampMillis: number): String {
return moment(new Date(timestampMillis)).format(DATE_FORMAT_PATTERN);
}

const PERMISSIONS_ERROR_PATTERN = /no permissions for \[(.+)\] and User \[name=(.+), backend_roles/;

export const prettifyErrorMessage = (rawErrorMessage: string) => {
if (isEmpty(rawErrorMessage) || rawErrorMessage === 'undefined') {
return 'Unknown error is returned.';
}
const match = rawErrorMessage.match(PERMISSIONS_ERROR_PATTERN);
if (isEmpty(match)) {
return rawErrorMessage;
} else {
return `User ${match[2]} has no permissions to [${match[1]}].`;
}
};
42 changes: 25 additions & 17 deletions public/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ import {
} from './pages';
import { MountPoint } from '../../../src/core/public';
import queryString from 'query-string';
import { constructHrefWithDataSourceId } from './utils/helpers';
import { constructHrefWithDataSourceId } from './utils/utils';

// styling
import './global-styles.scss';

interface Props extends RouteComponentProps {
setHeaderActionMenu: (menuMount: MountPoint | undefined) => void;
setHeaderActionMenu: (menuMount?: MountPoint) => void;
}

export const FlowFrameworkDashboardsApp = (props: Props) => {
const { setHeaderActionMenu } = props;
const queryParams = queryString.parse(location.search) as { [key: string]: string };
const dataSourceId = queryParams.dataSourceId === undefined ? undefined : queryParams.dataSourceId;
const queryParams = queryString.parse(location.search) as {
[key: string]: string;
};
const dataSourceId = queryParams.dataSourceId;
const sidebar = (
<EuiPageSideBar style={{ minWidth: 190 }} hidden={false} paddingSize="l">
<EuiSideNav
Expand Down Expand Up @@ -71,21 +73,24 @@ export const FlowFrameworkDashboardsApp = (props: Props) => {
<Switch>
<Route
path={APP_PATH.WORKFLOW_DETAIL}
render={(routeProps: RouteComponentProps<WorkflowDetailRouterProps>) => (
<WorkflowDetail
setActionMenu={setHeaderActionMenu}
landingDataSourceId={dataSourceId}
{...routeProps}
/>
render={(
routeProps: RouteComponentProps<WorkflowDetailRouterProps>
) => (
<WorkflowDetail
setActionMenu={setHeaderActionMenu}
landingDataSourceId={dataSourceId}
{...routeProps}
/>
)}
/>
<Route
path={APP_PATH.WORKFLOWS}
render={(routeProps: RouteComponentProps<WorkflowsRouterProps>) => (
<Workflows
setActionMenu={setHeaderActionMenu}
landingDataSourceId={dataSourceId}
{...routeProps} />
setActionMenu={setHeaderActionMenu}
landingDataSourceId={dataSourceId}
{...routeProps}
/>
)}
/>
{/*
Expand All @@ -101,10 +106,13 @@ export const FlowFrameworkDashboardsApp = (props: Props) => {
pathname: APP_PATH.WORKFLOWS,
});
}
return <Workflows
setActionMenu={setHeaderActionMenu}
landingDataSourceId={dataSourceId}
{...routeProps} />;
return (
<Workflows
setActionMenu={setHeaderActionMenu}
landingDataSourceId={dataSourceId}
{...routeProps}
/>
);
}}
/>
</Switch>
Expand Down
27 changes: 12 additions & 15 deletions public/pages/workflow_detail/workflow_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React, { useEffect, ReactElement } from 'react';
import { RouteComponentProps, useLocation } from 'react-router-dom';
import { RouteComponentProps } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { ReactFlowProvider } from 'reactflow';
import { EuiPage, EuiPageBody } from '@elastic/eui';
Expand All @@ -22,15 +22,13 @@ import {
DEFAULT_NEW_WORKFLOW_NAME,
FETCH_ALL_QUERY_BODY,
} from '../../../common';
import { MountPoint } from '../../../../../src/core/public';

// styling
import './workflow-detail-styles.scss';
import '../../global-styles.scss';
import { MountPoint } from '../../../../../src/core/public';

import {
getDataSourceFromURL,
} from '../../utils/helpers';
import { getDataSourceId } from '../../utils/utils';

import {
getDataSourceManagementPlugin,
Expand All @@ -46,9 +44,9 @@ export interface WorkflowDetailRouterProps {

interface WorkflowDetailProps
extends RouteComponentProps<WorkflowDetailRouterProps> {
setActionMenu: (menuMount: MountPoint | undefined) => void;
landingDataSourceId: string | undefined;
}
setActionMenu: (menuMount?: MountPoint) => void;
landingDataSourceId?: string;
}

/**
* The workflow details page. This is where users will configure, create, and
Expand All @@ -58,10 +56,8 @@ interface WorkflowDetailProps

export function WorkflowDetail(props: WorkflowDetailProps) {
const dispatch = useAppDispatch();
const location = useLocation();
const MDSQueryParams = getDataSourceFromURL(location);
const dataSourceEnabled = getDataSourceEnabled().enabled;
const dataSourceId = MDSQueryParams.dataSourceId;
const dataSourceId = getDataSourceId();
const { workflows } = useSelector((state: AppState) => state.workflows);

// selected workflow state
Expand Down Expand Up @@ -89,14 +85,15 @@ export function WorkflowDetail(props: WorkflowDetailProps) {
// - fetch workflow
// - fetch available models as their IDs may be used when building flows
useEffect(() => {
dispatch(getWorkflow({workflowId, dataSourceId} ));
dispatch(searchModels({body:FETCH_ALL_QUERY_BODY, dataSourceId}));
dispatch(getWorkflow({ workflowId, dataSourceId }));
dispatch(searchModels({ apiBody: FETCH_ALL_QUERY_BODY, dataSourceId }));
}, []);

let renderDataSourceComponent: ReactElement | null = null;
if (dataSourceEnabled) {
const DataSourceMenu =
getDataSourceManagementPlugin()?.ui.getDataSourceMenu<DataSourceViewConfig>();
const DataSourceMenu = getDataSourceManagementPlugin()?.ui.getDataSourceMenu<
DataSourceViewConfig
>();
renderDataSourceComponent = (
<DataSourceMenu
setMenuMountPoint={props.setActionMenu}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import {
} from '../../../../utils';
import { simulatePipeline, useAppDispatch } from '../../../../store';
import { getCore } from '../../../../services';
import { useLocation } from 'react-router-dom';
import { getDataSourceFromURL } from '../../../../utils/helpers';
import { getDataSourceId } from '../../../../utils/utils';
import { MapArrayField } from '../input_fields';

interface InputTransformModalProps {
Expand All @@ -65,9 +64,7 @@ interface InputTransformModalProps {
*/
export function InputTransformModal(props: InputTransformModalProps) {
const dispatch = useAppDispatch();
const location = useLocation();
const MDSQueryParams = getDataSourceFromURL(location);
const dataSourceId = MDSQueryParams.dataSourceId;
const dataSourceId = getDataSourceId();
const { values } = useFormikContext<WorkflowFormValues>();

// source input / transformed output state
Expand Down Expand Up @@ -119,10 +116,13 @@ export function InputTransformModal(props: InputTransformModalProps) {
values.ingest.index.name
);
await dispatch(
simulatePipeline({body:{
pipeline: curIngestPipeline as IngestPipelineConfig,
docs: curDocs,
}, dataSourceId: dataSourceId})
simulatePipeline({
apiBody: {
pipeline: curIngestPipeline as IngestPipelineConfig,
docs: curDocs,
},
dataSourceId,
})
)
.unwrap()
.then((resp: SimulateIngestPipelineResponse) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
import { simulatePipeline, useAppDispatch } from '../../../../store';
import { getCore } from '../../../../services';
import { MapArrayField } from '../input_fields';
import { getDataSourceId } from '../../../../utils/utils';

interface OutputTransformModalProps {
uiConfig: WorkflowConfig;
Expand All @@ -59,6 +60,7 @@ interface OutputTransformModalProps {
*/
export function OutputTransformModal(props: OutputTransformModalProps) {
const dispatch = useAppDispatch();
const dataSourceId = getDataSourceId();
const { values } = useFormikContext<WorkflowFormValues>();

// source input / transformed output state
Expand Down Expand Up @@ -114,10 +116,11 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
values.ingest.index.name
);
await dispatch(
simulatePipeline({
simulatePipeline({apiBody:{
pipeline: curIngestPipeline,
docs: curDocs,
})
},
dataSourceId})
)
.unwrap()
.then((resp: SimulateIngestPipelineResponse) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ import {
} from '@elastic/eui';
import { WorkspaceFormValues } from '../../../../../common';
import { JsonField } from '../input_fields';
import { useLocation } from 'react-router-dom';
import { getDataSourceFromURL } from '../../../../utils/helpers';
import {
AppState,
catIndices,
searchIndex,
useAppDispatch,
} from '../../../../store';
import { getDataSourceId } from '../../../../utils/utils';

interface ConfigureSearchRequestProps {
setQuery: (query: string) => void;
Expand All @@ -44,9 +43,7 @@ interface ConfigureSearchRequestProps {
*/
export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
const dispatch = useAppDispatch();
const location = useLocation();
const MDSQueryParams = getDataSourceFromURL(location);
const dataSourceId = MDSQueryParams.dataSourceId;
const dataSourceId = getDataSourceId();

// Form state
const { values } = useFormikContext<WorkspaceFormValues>();
Expand Down Expand Up @@ -76,7 +73,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
useEffect(() => {
if (!ingestEnabled) {
// Fetch all indices besides system indices
dispatch(catIndices({pattern:'*,-.*',dataSourceId: dataSourceId}));
dispatch(catIndices({ pattern: '*,-.*',dataSourceId }));
}
}, []);

Expand Down Expand Up @@ -169,11 +166,11 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
// for this test query, we don't want to involve any configured search pipelines, if any exist
// see https://opensearch.org/docs/latest/search-plugins/search-pipelines/using-search-pipeline/#disabling-the-default-pipeline-for-a-request
dispatch(
searchIndex({
searchIndex({apiBody:{
index: indexName,
body: values.search.request,
searchPipeline: '_none',
})
}, dataSourceId})
)
.unwrap()
.then(async (resp) => {
Expand Down
Loading
Loading