Skip to content

Commit

Permalink
Add deletion to table
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Feb 29, 2024
1 parent 96e2f1a commit 317c117
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 29 deletions.
6 changes: 5 additions & 1 deletion public/pages/workflows/workflow_list/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from 'react';
import { EuiLink } from '@elastic/eui';
import { PLUGIN_ID, Workflow } from '../../../../common';

export const columns = [
export const columns = (actions: any[]) => [
{
field: 'name',
name: 'Name',
Expand Down Expand Up @@ -36,4 +36,8 @@ export const columns = [
name: 'Last launched',
sortable: true,
},
{
name: 'Actions',
actions,
},
];
35 changes: 30 additions & 5 deletions public/pages/workflows/workflow_list/workflow_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React, { useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { debounce } from 'lodash';
import {
EuiInMemoryTable,
Expand All @@ -13,8 +13,9 @@ import {
EuiFlexItem,
EuiFilterSelectItem,
EuiFieldSearch,
EuiLoadingSpinner,
} from '@elastic/eui';
import { AppState } from '../../../store';
import { AppState, deleteWorkflow } from '../../../store';
import { Workflow } from '../../../../common';
import { columns } from './columns';
import { MultiSelectFilter } from '../../../general_components';
Expand All @@ -33,7 +34,10 @@ const sorting = {
* The searchable list of created workflows.
*/
export function WorkflowList(props: WorkflowListProps) {
const { workflows } = useSelector((state: AppState) => state.workflows);
const dispatch = useDispatch();
const { workflows, loading } = useSelector(
(state: AppState) => state.workflows
);

// search bar state
const [searchQuery, setSearchQuery] = useState<string>('');
Expand All @@ -58,6 +62,19 @@ export function WorkflowList(props: WorkflowListProps) {
);
}, [selectedStates, searchQuery, workflows]);

const tableActions = [
{
name: 'Delete',
description: 'Delete this workflow',
type: 'icon',
icon: 'trash',
color: 'danger',
onClick: (item: Workflow) => {
dispatch(deleteWorkflow(item.id));
},
},
];

return (
<EuiFlexGroup direction="column">
<EuiFlexItem>
Expand All @@ -80,10 +97,18 @@ export function WorkflowList(props: WorkflowListProps) {
<EuiInMemoryTable<Workflow>
items={filteredWorkflows}
rowHeader="name"
columns={columns}
// @ts-ignore
columns={columns(tableActions)}
sorting={sorting}
pagination={true}
message={'No existing workflows found'}
message={
loading === true ? (
<EuiLoadingSpinner size="xl" />
) : (
'No existing workflows found'
)
}
hasActions={true}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
7 changes: 7 additions & 0 deletions public/pages/workflows/workflows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ export function Workflows(props: WorkflowsProps) {
}
}, [selectedTabId, workflows]);

// If the user navigates back to the manage tab, re-fetch workflows
useEffect(() => {
if (selectedTabId === WORKFLOWS_TAB.MANAGE) {
dispatch(searchWorkflows({ query: { match_all: {} } }));
}
}, [selectedTabId]);

useEffect(() => {
getCore().chrome.setBreadcrumbs([
BREADCRUMBS.FLOW_FRAMEWORK,
Expand Down
8 changes: 2 additions & 6 deletions public/store/reducers/workflows_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,8 @@ const workflowsSlice = createSlice({
state.errorMessage = '';
})
.addCase(deleteWorkflow.fulfilled, (state, action) => {
// TODO: add logic to mutate state
// const workflow = action.payload;
// state.workflows = {
// ...state.workflows,
// [workflow.id]: workflow,
// };
const workflowId = action.payload.id;
delete state.workflows[workflowId];
state.loading = false;
state.errorMessage = '';
})
Expand Down
9 changes: 2 additions & 7 deletions server/routes/flow_framework_routes_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,12 @@ export class FlowFrameworkRoutesService {
const response = await this.client
.asScoped(req)
.callAsCurrentUser('flowFramework.createWorkflow', { body });
console.log('response from create workflow: ', response);
// TODO: format response
return res.ok({ body: response });
return res.ok({ body: { id: response._id } });
} catch (err: any) {
return generateCustomError(res, err);
}
};

// TODO: test e2e
deleteWorkflow = async (
context: RequestHandlerContext,
req: OpenSearchDashboardsRequest,
Expand All @@ -191,9 +188,7 @@ export class FlowFrameworkRoutesService {
const response = await this.client
.asScoped(req)
.callAsCurrentUser('flowFramework.deleteWorkflow', { workflow_id });
console.log('response from delete workflow: ', response);
// TODO: format response
return res.ok({ body: response });
return res.ok({ body: { id: response._id } });
} catch (err: any) {
return generateCustomError(res, err);
}
Expand Down
22 changes: 12 additions & 10 deletions server/routes/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ export function getWorkflowsFromResponses(
const workflowStateHit = workflowStateHits.find(
(workflowStateHit) => workflowStateHit._id === workflowHit._id

Check failure on line 51 in server/routes/helpers.ts

View workflow job for this annotation

GitHub Actions / Run lint script

'workflowStateHit' is already declared in the upper scope
);
const workflowState = workflowStateHit._source
.state as typeof WORKFLOW_STATE;
workflowDict[workflowHit._id] = {
...workflowDict[workflowHit._id],
// @ts-ignore
state: WORKFLOW_STATE[workflowState],
// TODO: this needs to be persisted by backend. Tracking issue:
// https://github.com/opensearch-project/flow-framework/issues/548
lastLaunched: 1234,
};
if (workflowStateHit) {
const workflowState = workflowStateHit._source
.state as typeof WORKFLOW_STATE;
workflowDict[workflowHit._id] = {
...workflowDict[workflowHit._id],
// @ts-ignore
state: WORKFLOW_STATE[workflowState],
// TODO: this needs to be persisted by backend. Tracking issue:
// https://github.com/opensearch-project/flow-framework/issues/548
lastLaunched: 1234,
};
}
});
return workflowDict;
}

0 comments on commit 317c117

Please sign in to comment.