-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(orchestrator): add workflow runs tab
- Loading branch information
1 parent
d6c3908
commit 8897e33
Showing
9 changed files
with
254 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@red-hat-developer-hub/backstage-plugin-orchestrator': patch | ||
--- | ||
|
||
add workflow tabs - details and runs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
workspaces/orchestrator/plugins/orchestrator/src/components/WorkflowPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2024 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React from 'react'; | ||
|
||
import { TabbedLayout } from '@backstage/core-components'; | ||
import { useRouteRefParams } from '@backstage/core-plugin-api'; | ||
|
||
import { workflowRouteRef, workflowRunsRouteRef } from '../routes'; | ||
import { BaseOrchestratorPage } from './BaseOrchestratorPage'; | ||
import { WorkflowDefinitionViewerPage } from './WorkflowDefinitionViewerPage'; | ||
import { WorkflowRunsTabContentFiltered } from './WorkflowRunsTabContentFiltered'; | ||
|
||
export const WorkflowPage = () => { | ||
const { workflowId } = useRouteRefParams(workflowRouteRef); | ||
return ( | ||
<BaseOrchestratorPage title={workflowId} noPadding> | ||
<TabbedLayout> | ||
<TabbedLayout.Route path="/" title="Workflow details"> | ||
<WorkflowDefinitionViewerPage /> | ||
</TabbedLayout.Route> | ||
<TabbedLayout.Route | ||
path={workflowRunsRouteRef.path} | ||
title="Workflow runs" | ||
> | ||
<WorkflowRunsTabContentFiltered /> | ||
</TabbedLayout.Route> | ||
</TabbedLayout> | ||
</BaseOrchestratorPage> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
...paces/orchestrator/plugins/orchestrator/src/components/WorkflowRunsTabContentFiltered.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Copyright 2024 The Backstage Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import React, { useState } from 'react'; | ||
|
||
import { | ||
ErrorPanel, | ||
InfoCard, | ||
Link, | ||
SelectItem, | ||
TableColumn, | ||
} from '@backstage/core-components'; | ||
import { | ||
useApi, | ||
useRouteRef, | ||
useRouteRefParams, | ||
} from '@backstage/core-plugin-api'; | ||
|
||
import { Grid } from '@material-ui/core'; | ||
|
||
import { | ||
capitalize, | ||
ellipsis, | ||
ProcessInstanceState, | ||
ProcessInstanceStatusDTO, | ||
} from '@red-hat-developer-hub/backstage-plugin-orchestrator-common'; | ||
|
||
import { orchestratorApiRef } from '../api'; | ||
import { DEFAULT_TABLE_PAGE_SIZE, VALUE_UNAVAILABLE } from '../constants'; | ||
import usePolling from '../hooks/usePolling'; | ||
import { workflowInstanceRouteRef, workflowRouteRef } from '../routes'; | ||
import { Selector } from './Selector'; | ||
import OverrideBackstageTable from './ui/OverrideBackstageTable'; | ||
import { mapProcessInstanceToDetails } from './WorkflowInstancePageContent'; | ||
import { WorkflowInstanceStatusIndicator } from './WorkflowInstanceStatusIndicator'; | ||
import { WorkflowRunDetail } from './WorkflowRunDetail'; | ||
|
||
const makeSelectItemsFromProcessInstanceValues = () => | ||
[ | ||
ProcessInstanceState.Active, | ||
ProcessInstanceState.Error, | ||
ProcessInstanceState.Completed, | ||
ProcessInstanceState.Aborted, | ||
ProcessInstanceState.Suspended, | ||
].map( | ||
(status): SelectItem => ({ | ||
label: capitalize(status), | ||
value: status, | ||
}), | ||
); | ||
|
||
export const WorkflowRunsTabContentFiltered = () => { | ||
const { workflowId } = useRouteRefParams(workflowRouteRef); | ||
|
||
const orchestratorApi = useApi(orchestratorApiRef); | ||
const workflowInstanceLink = useRouteRef(workflowInstanceRouteRef); | ||
const [statusSelectorValue, setStatusSelectorValue] = useState<string>( | ||
Selector.AllItems, | ||
); | ||
|
||
const fetchInstances = React.useCallback(async () => { | ||
// TODO: use pagination with generic permission, skip (or use FE-only) for specific permissions | ||
const instances = await orchestratorApi.listInstances({}); | ||
const clonedData: WorkflowRunDetail[] = | ||
instances.data.items?.map(mapProcessInstanceToDetails) || []; | ||
return clonedData.filter(item => item.workflowId === workflowId); | ||
}, [orchestratorApi, workflowId]); | ||
|
||
const { loading, error, value } = usePolling(fetchInstances); | ||
|
||
const columns = React.useMemo( | ||
(): TableColumn<WorkflowRunDetail>[] => [ | ||
{ | ||
title: 'ID', | ||
field: 'id', | ||
render: data => ( | ||
<Link to={workflowInstanceLink({ instanceId: data.id })}> | ||
{ellipsis(data.id)} | ||
</Link> | ||
), | ||
sorting: false, | ||
}, | ||
{ | ||
title: 'Workflow name', | ||
field: 'name', | ||
}, | ||
{ | ||
title: 'Status', | ||
field: 'status', | ||
render: data => ( | ||
<WorkflowInstanceStatusIndicator | ||
status={data.status as ProcessInstanceStatusDTO} | ||
/> | ||
), | ||
}, | ||
{ | ||
title: 'Category', | ||
field: 'category', | ||
render: data => capitalize(data.category ?? VALUE_UNAVAILABLE), | ||
}, | ||
{ title: 'Started', field: 'started', defaultSort: 'desc' }, | ||
{ title: 'Duration', field: 'duration' }, | ||
], | ||
[workflowInstanceLink], | ||
); | ||
|
||
const statuses = React.useMemo(makeSelectItemsFromProcessInstanceValues, []); | ||
|
||
const filteredData = React.useMemo( | ||
() => | ||
(value ?? []).filter( | ||
(row: WorkflowRunDetail) => | ||
statusSelectorValue === Selector.AllItems || | ||
row.status?.toLocaleLowerCase('en-US') === statusSelectorValue, | ||
), | ||
[statusSelectorValue, value], | ||
); | ||
|
||
const selectors = React.useMemo( | ||
() => ( | ||
<Grid container alignItems="center"> | ||
<Grid item> | ||
<Selector | ||
label="Status" | ||
items={statuses} | ||
onChange={setStatusSelectorValue} | ||
selected={statusSelectorValue} | ||
/> | ||
</Grid> | ||
</Grid> | ||
), | ||
[statusSelectorValue, statuses], | ||
); | ||
const paging = (value?.length || 0) > DEFAULT_TABLE_PAGE_SIZE; // this behavior fits the backstage catalog table behavior https://github.com/backstage/backstage/blob/v1.14.0/plugins/catalog/src/components/CatalogTable/CatalogTable.tsx#L228 | ||
|
||
return error ? ( | ||
<ErrorPanel error={error} /> | ||
) : ( | ||
<InfoCard noPadding title={selectors}> | ||
<OverrideBackstageTable | ||
title="Workflow Runs" | ||
options={{ | ||
paging, | ||
search: true, | ||
pageSize: DEFAULT_TABLE_PAGE_SIZE, | ||
}} | ||
isLoading={loading} | ||
columns={columns} | ||
data={filteredData} | ||
/> | ||
</InfoCard> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters