Skip to content

Commit

Permalink
Connect to redux store
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Sep 22, 2023
1 parent 25ccc63 commit db360ff
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 172 deletions.
2 changes: 2 additions & 0 deletions common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*/

export * from './constants';
export * from './interfaces';
export { IComponent } from '../public/component_types';
11 changes: 11 additions & 0 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

// TODO: this will grow as more fields are defined and what frontend reqts there will be
export interface Workflow {
name: string;
id: string;
description: string;
}
2 changes: 1 addition & 1 deletion public/pages/use_cases/components/use_case.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function UseCase(props: UseCaseProps) {
disabled={false}
isLoading={false}
onClick={() => {
// TODO: possibly link to the workflow builder with a pre-configured flow
// TODO: possibly link to the workflow details with a pre-configured flow
}}
>
Go
Expand Down
68 changes: 0 additions & 68 deletions public/pages/workflow_builder/workflow_builder.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions public/pages/workflow_detail/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@

import React from 'react';
import { EuiPageHeader, EuiButton } from '@elastic/eui';
import { Workflow } from '../../../../common';

interface WorkflowDetailHeaderProps {
componentName: string;
workflow: Workflow | undefined;
}

export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
return (
<div>
<EuiPageHeader
pageTitle={props.componentName}
description="Some description of this workflow..."
pageTitle={props.workflow ? props.workflow.name : ''}
description={props.workflow ? props.workflow.description : ''}
rightSideItems={[
<EuiButton fill={false} onClick={() => {}}>
Prototype
Expand Down
30 changes: 10 additions & 20 deletions public/pages/workflow_detail/workflow_detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@

import React, { useEffect } from 'react';
import { RouteComponentProps } from 'react-router-dom';
// import { useSelector, useDispatch } from 'react-redux';
import { useSelector } from 'react-redux';
import { EuiSpacer } from '@elastic/eui';
import { BREADCRUMBS } from '../../utils';
import { getCore } from '../../services';
import { WorkflowDetailHeader } from './components';
import {
TextEmbeddingProcessor,
IComponent,
KnnIndex,
} from '../../component_types';
import { Workspace } from './workspace';
// import { AppState, removeDirty, setComponents } from '../../store';
import { AppState } from '../../store';

export interface WorkflowDetailRouterProps {
workflowId: string;
Expand All @@ -27,31 +22,26 @@ interface WorkflowDetailProps
extends RouteComponentProps<WorkflowDetailRouterProps> {}

export function WorkflowDetail(props: WorkflowDetailProps) {
// TODO: below commented out lines can be used for fetching & setting global redux state
// const dispatch = useDispatch();
// const { isDirty, components } = useSelector(
// (state: AppState) => state.workspace
// );
const { workflows } = useSelector((state: AppState) => state.workflows);

// TODO: Should be fetched from global state. Using some defaults for testing purposes
const curComponents = [
new TextEmbeddingProcessor(),
new KnnIndex(),
] as IComponent[];
const workflow = workflows.find(
(wf) => wf.id === props.match?.params?.workflowId
);
const workflowName = workflow ? workflow.name : '';

useEffect(() => {
getCore().chrome.setBreadcrumbs([
BREADCRUMBS.AI_APPLICATION_BUILDER,
BREADCRUMBS.WORKFLOWS,
{ text: 'workflow-name-placeholder' },
{ text: workflowName },
]);
});

return (
<div>
<WorkflowDetailHeader componentName="component 1" />
<WorkflowDetailHeader workflow={workflow} />
<EuiSpacer size="l" />
<Workspace components={curComponents} />
<Workspace />
</div>
);
}
11 changes: 5 additions & 6 deletions public/pages/workflow_detail/workspace/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
*/

import React from 'react';
import { useSelector } from 'react-redux';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { AppState } from '../../../store';
import { WorkspaceComponent } from '../workspace_component';
import { IComponent } from '../../../component_types';

interface WorkspaceProps {
components: IComponent[];
}
export function Workspace() {
const { components } = useSelector((state: AppState) => state.workspace);

export function Workspace(props: WorkspaceProps) {
return (
<EuiFlexGroup direction="row">
{props.components.map((component, idx) => {
{components.map((component, idx) => {
return (
<EuiFlexItem key={idx}>
<WorkspaceComponent component={component} />
Expand Down
29 changes: 29 additions & 0 deletions public/pages/workflows/components/columns.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { EuiLink } from '@elastic/eui';
import { PLUGIN_ID, Workflow } from '../../../../common';

export const columns = [
{
field: 'name',
name: 'Name',
sortable: true,
render: (name: string, workflow: Workflow) => (
<EuiLink href={`${PLUGIN_ID}#/workflows/${workflow.id}`}>{name}</EuiLink>
),
},
{
field: 'id',
name: 'ID',
sortable: true,
},
{
field: 'description',
name: 'Description',
sortable: false,
},
];
85 changes: 13 additions & 72 deletions public/pages/workflows/components/workflow_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,93 +3,34 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useState } from 'react';
import { EuiBasicTable, EuiLink } from '@elastic/eui';
import { PLUGIN_ID } from '../../../../common';
import React from 'react';
import { useSelector } from 'react-redux';
import { EuiInMemoryTable, Direction } from '@elastic/eui';
import { AppState } from '../../../store';
import { Workflow } from '../../../../common';
import { columns } from './columns';

// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface WorkflowListProps {}

interface WorkflowItem {
name: string;
id: string;
description: string;
}

export function WorkflowList(props: WorkflowListProps) {
const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(5);
const [sortField, setSortField] = useState('name');
const [sortDirection, setSortDirection] = useState('asc');

// TODO: move column details to separate file
const columns = [
{
field: 'name',
name: 'Name',
sortable: true,
render: (name: string, workflow: WorkflowItem) => (
<EuiLink href={`${PLUGIN_ID}#/workflows/${workflow.id}`}>
{name}
</EuiLink>
),
},
{
field: 'id',
name: 'ID',
sortable: false,
},
{
field: 'description',
name: 'Description',
sortable: false,
},
];

// TODO: remove items and fetch from store
const items = [
{
name: 'Workflow-1',
id: 'workflow-1-id',
description: 'some test description',
},
] as WorkflowItem[];
const { workflows } = useSelector((state: AppState) => state.workflows);

const sorting = {
sort: {
field: sortField,
direction: sortDirection,
field: 'name',
direction: 'asc' as Direction,
},
enableAllColumns: false,
readOnly: false,
};

const pagination = {
pageIndex,
pageSize,
totalItemCount: items.length,
pageSizeOptions: [5, 10, 20],
};

const onTableChange = ({ page = {}, sort = {} }) => {
const { index, size } = page;
const { field, direction } = sort;

setPageIndex(index);
setPageSize(size);
setSortField(field);
setSortDirection(direction);
};

return (
<EuiBasicTable<WorkflowItem>
items={items}
<EuiInMemoryTable<Workflow>
items={workflows}
rowHeader="name"
columns={columns}
sorting={sorting}
pagination={pagination}
onChange={onTableChange}
noItemsMessage={'No existing workflows found'}
pagination={true}
message={'No existing workflows found'}
/>
);
}
1 change: 1 addition & 0 deletions public/store/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*/

export * from './workspace_reducer';
export * from './workflows_reducer';
40 changes: 40 additions & 0 deletions public/store/reducers/workflows_reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { createSlice } from '@reduxjs/toolkit';
import { Workflow } from '../../../common';

const initialState = {
// TODO: fetch from server-side later
workflows: [
{
name: 'Workflow-1',
id: 'workflow-1-id',
description: 'description for workflow 1',
},
{
name: 'Workflow-2',
id: 'workflow-2-id',
description: 'description for workflow 2',
},
] as Workflow[],
loading: false,
};

const workflowsSlice = createSlice({
name: 'workflows',
initialState,
reducers: {
setWorkflows(state, action) {
state.workflows = action.payload;
},
setLoading(state, action) {
state.loading = action.payload;
},
},
});

export const workflowsReducer = workflowsSlice.reducer;
export const { setWorkflows, setLoading } = workflowsSlice.actions;
Loading

0 comments on commit db360ff

Please sign in to comment.