Skip to content

Commit ac1df60

Browse files
Add deletion to table (#90) (#91)
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> (cherry picked from commit 7043c11) Co-authored-by: Tyler Ohlsen <ohltyler@amazon.com>
1 parent dadbc78 commit ac1df60

File tree

6 files changed

+58
-29
lines changed

6 files changed

+58
-29
lines changed

public/pages/workflows/workflow_list/columns.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react';
77
import { EuiLink } from '@elastic/eui';
88
import { PLUGIN_ID, Workflow } from '../../../../common';
99

10-
export const columns = [
10+
export const columns = (actions: any[]) => [
1111
{
1212
field: 'name',
1313
name: 'Name',
@@ -36,4 +36,8 @@ export const columns = [
3636
name: 'Last launched',
3737
sortable: true,
3838
},
39+
{
40+
name: 'Actions',
41+
actions,
42+
},
3943
];

public/pages/workflows/workflow_list/workflow_list.tsx

+30-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import React, { useState, useEffect } from 'react';
7-
import { useSelector } from 'react-redux';
7+
import { useDispatch, useSelector } from 'react-redux';
88
import { debounce } from 'lodash';
99
import {
1010
EuiInMemoryTable,
@@ -13,8 +13,9 @@ import {
1313
EuiFlexItem,
1414
EuiFilterSelectItem,
1515
EuiFieldSearch,
16+
EuiLoadingSpinner,
1617
} from '@elastic/eui';
17-
import { AppState } from '../../../store';
18+
import { AppState, deleteWorkflow } from '../../../store';
1819
import { Workflow } from '../../../../common';
1920
import { columns } from './columns';
2021
import { MultiSelectFilter } from '../../../general_components';
@@ -33,7 +34,10 @@ const sorting = {
3334
* The searchable list of created workflows.
3435
*/
3536
export function WorkflowList(props: WorkflowListProps) {
36-
const { workflows } = useSelector((state: AppState) => state.workflows);
37+
const dispatch = useDispatch();
38+
const { workflows, loading } = useSelector(
39+
(state: AppState) => state.workflows
40+
);
3741

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

65+
const tableActions = [
66+
{
67+
name: 'Delete',
68+
description: 'Delete this workflow',
69+
type: 'icon',
70+
icon: 'trash',
71+
color: 'danger',
72+
onClick: (item: Workflow) => {
73+
dispatch(deleteWorkflow(item.id));
74+
},
75+
},
76+
];
77+
6178
return (
6279
<EuiFlexGroup direction="column">
6380
<EuiFlexItem>
@@ -80,10 +97,18 @@ export function WorkflowList(props: WorkflowListProps) {
8097
<EuiInMemoryTable<Workflow>
8198
items={filteredWorkflows}
8299
rowHeader="name"
83-
columns={columns}
100+
// @ts-ignore
101+
columns={columns(tableActions)}
84102
sorting={sorting}
85103
pagination={true}
86-
message={'No existing workflows found'}
104+
message={
105+
loading === true ? (
106+
<EuiLoadingSpinner size="xl" />
107+
) : (
108+
'No existing workflows found'
109+
)
110+
}
111+
hasActions={true}
87112
/>
88113
</EuiFlexItem>
89114
</EuiFlexGroup>

public/pages/workflows/workflows.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export function Workflows(props: WorkflowsProps) {
7272
}
7373
}, [selectedTabId, workflows]);
7474

75+
// If the user navigates back to the manage tab, re-fetch workflows
76+
useEffect(() => {
77+
if (selectedTabId === WORKFLOWS_TAB.MANAGE) {
78+
dispatch(searchWorkflows({ query: { match_all: {} } }));
79+
}
80+
}, [selectedTabId]);
81+
7582
useEffect(() => {
7683
getCore().chrome.setBreadcrumbs([
7784
BREADCRUMBS.FLOW_FRAMEWORK,

public/store/reducers/workflows_reducer.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,8 @@ const workflowsSlice = createSlice({
233233
state.errorMessage = '';
234234
})
235235
.addCase(deleteWorkflow.fulfilled, (state, action) => {
236-
// TODO: add logic to mutate state
237-
// const workflow = action.payload;
238-
// state.workflows = {
239-
// ...state.workflows,
240-
// [workflow.id]: workflow,
241-
// };
236+
const workflowId = action.payload.id;
237+
delete state.workflows[workflowId];
242238
state.loading = false;
243239
state.errorMessage = '';
244240
})

server/routes/flow_framework_routes_service.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,12 @@ export class FlowFrameworkRoutesService {
172172
const response = await this.client
173173
.asScoped(req)
174174
.callAsCurrentUser('flowFramework.createWorkflow', { body });
175-
console.log('response from create workflow: ', response);
176-
// TODO: format response
177-
return res.ok({ body: response });
175+
return res.ok({ body: { id: response._id } });
178176
} catch (err: any) {
179177
return generateCustomError(res, err);
180178
}
181179
};
182180

183-
// TODO: test e2e
184181
deleteWorkflow = async (
185182
context: RequestHandlerContext,
186183
req: OpenSearchDashboardsRequest,
@@ -191,9 +188,7 @@ export class FlowFrameworkRoutesService {
191188
const response = await this.client
192189
.asScoped(req)
193190
.callAsCurrentUser('flowFramework.deleteWorkflow', { workflow_id });
194-
console.log('response from delete workflow: ', response);
195-
// TODO: format response
196-
return res.ok({ body: response });
191+
return res.ok({ body: { id: response._id } });
197192
} catch (err: any) {
198193
return generateCustomError(res, err);
199194
}

server/routes/helpers.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,18 @@ export function getWorkflowsFromResponses(
5050
const workflowStateHit = workflowStateHits.find(
5151
(workflowStateHit) => workflowStateHit._id === workflowHit._id
5252
);
53-
const workflowState = workflowStateHit._source
54-
.state as typeof WORKFLOW_STATE;
55-
workflowDict[workflowHit._id] = {
56-
...workflowDict[workflowHit._id],
57-
// @ts-ignore
58-
state: WORKFLOW_STATE[workflowState],
59-
// TODO: this needs to be persisted by backend. Tracking issue:
60-
// https://github.com/opensearch-project/flow-framework/issues/548
61-
lastLaunched: 1234,
62-
};
53+
if (workflowStateHit) {
54+
const workflowState = workflowStateHit._source
55+
.state as typeof WORKFLOW_STATE;
56+
workflowDict[workflowHit._id] = {
57+
...workflowDict[workflowHit._id],
58+
// @ts-ignore
59+
state: WORKFLOW_STATE[workflowState],
60+
// TODO: this needs to be persisted by backend. Tracking issue:
61+
// https://github.com/opensearch-project/flow-framework/issues/548
62+
lastLaunched: 1234,
63+
};
64+
}
6365
});
6466
return workflowDict;
6567
}

0 commit comments

Comments
 (0)