Skip to content

Commit

Permalink
feat(orchestrator): add feature flag for developer mode and config to…
Browse files Browse the repository at this point in the history
… enable/disable the integration with catalog (janus-idp#58)
  • Loading branch information
caponetto committed Jan 16, 2024
1 parent f5ae4d3 commit 05719a9
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 41 deletions.
7 changes: 7 additions & 0 deletions plugins/orchestrator-backend/src/dynamic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const dynamicPluginInstaller: BackendDynamicPluginInstaller = {
},
},
async catalog(builder, env) {
const isIntegrationEnabled = !!env.config.getOptionalBoolean(
'orchestrator.catalog.isEnabled',
);
if (!isIntegrationEnabled) {
env.logger.info('The integration with the Catalog plugin is disabled.');
return;
}
builder.addEntityProvider(
await OrchestratorEntityProvider.fromConfig({ ...env }),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const orchestratorModuleEntityProvider = createBackendModule({
catalog: catalogProcessingExtensionPoint,
},
async init({ logger, config, discovery, scheduler, catalog }) {
const isIntegrationEnabled = !!config.getOptionalBoolean(
'orchestrator.catalog.isEnabled',
);
if (!isIntegrationEnabled) {
logger.info('The integration with the Catalog plugin is disabled.');
return;
}
const winstonLogger = loggerToWinstonLogger(logger);
const eventBroker = new DefaultEventBroker(winstonLogger);
const provider = await OrchestratorEntityProvider.fromConfig({
Expand Down
5 changes: 5 additions & 0 deletions plugins/orchestrator-common/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ export interface Config {
* Configuration for the integration with the Catalog plugin.
*/
catalog?: {
/**
* Whether to enable the integration with the Catalog plugin.
* Default: false
*/
isEnabled?: boolean;
/**
* Owner of workflows to present on the component catalog.
* Default: infrastructure
Expand Down
2 changes: 2 additions & 0 deletions plugins/orchestrator-common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ export const default_workflows_path = 'workflows';

export const ASSESSMENT_WORKFLOW_TYPE = 'workflow-type/assessment';
export const INFRASTRUCTURE_WORKFLOW_TYPE = 'workflow-type/infrastructure';

export const FEATURE_FLAG_DEVELOPER_MODE = 'developer-mode';
1 change: 1 addition & 0 deletions plugins/orchestrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/core-app-api": "^1.11.0",
"@backstage/core-components": "^0.13.6",
"@backstage/core-plugin-api": "^1.7.0",
"@backstage/errors": "^1.2.3",
Expand Down
25 changes: 22 additions & 3 deletions plugins/orchestrator/src/components/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import { Route, Routes } from 'react-router-dom';

import { FeatureFlagged } from '@backstage/core-app-api';

import { FEATURE_FLAG_DEVELOPER_MODE } from '@janus-idp/backstage-plugin-orchestrator-common';

import {
createWorkflowRouteRef,
editWorkflowRouteRef,
Expand Down Expand Up @@ -40,14 +44,29 @@ export const Router = () => {
path={workflowInstanceRouteRef.path}
element={<WorkflowInstancesViewerPage />}
/>
<Route path={newWorkflowRef.path} element={<NewWorkflowViewerPage />} />
<Route
path={newWorkflowRef.path}
element={
<FeatureFlagged with={FEATURE_FLAG_DEVELOPER_MODE}>
<NewWorkflowViewerPage />
</FeatureFlagged>
}
/>
<Route
path={createWorkflowRouteRef.path}
element={<CreateWorkflowPage />}
element={
<FeatureFlagged with={FEATURE_FLAG_DEVELOPER_MODE}>
<CreateWorkflowPage />
</FeatureFlagged>
}
/>
<Route
path={editWorkflowRouteRef.path}
element={<CreateWorkflowPage />}
element={
<FeatureFlagged with={FEATURE_FLAG_DEVELOPER_MODE}>
<CreateWorkflowPage />
</FeatureFlagged>
}
/>
<Route
path={executeWorkflowRouteRef.path}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import React, { useMemo } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAsync } from 'react-use';

import { FeatureFlagged } from '@backstage/core-app-api';
import { InfoCard } from '@backstage/core-components';
import {
featureFlagsApiRef,
useApi,
useRouteRef,
useRouteRefParams,
Expand All @@ -12,6 +14,8 @@ import {
import { Button, Grid } from '@material-ui/core';
import { Skeleton } from '@material-ui/lab';

import { FEATURE_FLAG_DEVELOPER_MODE } from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef } from '../../api';
import {
editWorkflowRouteRef,
Expand All @@ -23,6 +27,7 @@ import { EditorViewKind, WorkflowEditor } from '../WorkflowEditor';
import WorkflowDefinitionDetailsCard from './WorkflowDefinitionDetailsCard';

export const WorkflowDefinitionViewerPage = () => {
const featureFlagsApi = useApi(featureFlagsApiRef);
const { workflowId, format } = useRouteRefParams(workflowDefinitionsRouteRef);
const orchestratorApi = useApi(orchestratorApiRef);
const { value: workflowOverview } = useAsync(() =>
Expand All @@ -35,6 +40,9 @@ export const WorkflowDefinitionViewerPage = () => {
() => (format === 'json' ? 'json' : 'yaml'),
[format],
);
const isDeveloperModeOn = featureFlagsApi.isActive(
FEATURE_FLAG_DEVELOPER_MODE,
);

const handleExecute = () => {
navigate(executeWorkflowLink({ workflowId }));
Expand All @@ -55,20 +63,26 @@ export const WorkflowDefinitionViewerPage = () => {
<Grid container spacing={2} direction="column" wrap="nowrap">
<Grid container item justifyContent="flex-end" spacing={1}>
<Grid item>
{loading ? (
<Skeleton variant="text" width="5rem" />
) : (
<Button variant="contained" color="primary" onClick={handleEdit}>
Edit
</Button>
)}
<FeatureFlagged with={FEATURE_FLAG_DEVELOPER_MODE}>
{loading ? (
<Skeleton variant="text" width="5rem" />
) : (
<Button
variant="contained"
color="primary"
onClick={handleEdit}
>
Edit
</Button>
)}
</FeatureFlagged>
</Grid>
<Grid item>
{loading ? (
<Skeleton variant="text" width="5rem" />
) : (
<Button
variant="outlined"
variant={isDeveloperModeOn ? 'outlined' : 'contained'}
color="primary"
onClick={handleExecute}
>
Expand Down
28 changes: 17 additions & 11 deletions plugins/orchestrator/src/components/next/WorkflowsTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { useNavigate } from 'react-router-dom';
import { useAsync } from 'react-use';

import { FeatureFlagged } from '@backstage/core-app-api';
import {
Content,
Progress,
Expand All @@ -12,7 +13,10 @@ import { useApi, useRouteRef } from '@backstage/core-plugin-api';
import Button from '@material-ui/core/Button/Button';
import Grid from '@material-ui/core/Grid/Grid';

import { WorkflowOverview } from '@janus-idp/backstage-plugin-orchestrator-common';
import {
FEATURE_FLAG_DEVELOPER_MODE,
WorkflowOverview,
} from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef } from '../../api';
import { newWorkflowRef } from '../../routes';
Expand All @@ -38,17 +42,19 @@ export const WorkflowsTabContent = () => {
{error ? <ResponseErrorPanel error={error} /> : null}
{isReady ? (
<>
<Grid container direction="row-reverse">
<Grid item>
<Button
variant="contained"
color="primary"
onClick={() => navigate(newWorkflowLink())}
>
Create new
</Button>
<FeatureFlagged with={FEATURE_FLAG_DEVELOPER_MODE}>
<Grid container direction="row-reverse">
<Grid item>
<Button
variant="contained"
color="primary"
onClick={() => navigate(newWorkflowLink())}
>
Create new
</Button>
</Grid>
</Grid>
</Grid>
</FeatureFlagged>
<Grid container direction="column">
<Grid item>
<WorkflowsTable items={value ?? []} />
Expand Down
55 changes: 36 additions & 19 deletions plugins/orchestrator/src/components/next/WorkflowsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ import {
TableColumn,
TableProps,
} from '@backstage/core-components';
import { useApi, useRouteRef } from '@backstage/core-plugin-api';
import {
featureFlagsApiRef,
useApi,
useRouteRef,
} from '@backstage/core-plugin-api';

import DeleteForever from '@material-ui/icons/DeleteForever';
import Edit from '@material-ui/icons/Edit';
import Pageview from '@material-ui/icons/Pageview';
import PlayArrow from '@material-ui/icons/PlayArrow';

import { WorkflowOverview } from '@janus-idp/backstage-plugin-orchestrator-common';
import {
FEATURE_FLAG_DEVELOPER_MODE,
WorkflowOverview,
} from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef } from '../../api';
import WorkflowOverviewFormatter, {
Expand All @@ -33,11 +40,15 @@ export interface WorkflowsTableProps {

export const WorkflowsTable = ({ items }: WorkflowsTableProps) => {
const orchestratorApi = useApi(orchestratorApiRef);
const featureFlagsApi = useApi(featureFlagsApiRef);
const navigate = useNavigate();
const definitionLink = useRouteRef(workflowDefinitionsRouteRef);
const executeWorkflowLink = useRouteRef(nextExecuteWorkflowRouteRef);
const editLink = useRouteRef(editWorkflowRouteRef);
const [data, setData] = useState<FormattedWorkflowOverview[]>([]);
const isDeveloperModeOn = featureFlagsApi.isActive(
FEATURE_FLAG_DEVELOPER_MODE,
);

const initialState = useMemo(
() => items.map(WorkflowOverviewFormatter.format),
Expand Down Expand Up @@ -88,8 +99,8 @@ export const WorkflowsTable = ({ items }: WorkflowsTableProps) => {
[orchestratorApi],
);

const actions: TableProps<FormattedWorkflowOverview>['actions'] = useMemo(
() => [
const actions = useMemo(() => {
const actionItems: TableProps<FormattedWorkflowOverview>['actions'] = [
{
icon: PlayArrow,
tooltip: 'Execute',
Expand All @@ -102,21 +113,27 @@ export const WorkflowsTable = ({ items }: WorkflowsTableProps) => {
onClick: (_, rowData) =>
handleView(rowData as FormattedWorkflowOverview),
},
{
icon: Edit,
tooltip: 'Edit',
onClick: (_, rowData) =>
handleEdit(rowData as FormattedWorkflowOverview),
},
{
icon: DeleteForever,
tooltip: 'Delete',
onClick: (_, rowData) =>
handleDelete(rowData as FormattedWorkflowOverview),
},
],
[handleDelete, handleEdit, handleExecute, handleView],
);
];

if (isDeveloperModeOn) {
actionItems.push(
{
icon: Edit,
tooltip: 'Edit',
onClick: (_, rowData) =>
handleEdit(rowData as FormattedWorkflowOverview),
},
{
icon: DeleteForever,
tooltip: 'Delete',
onClick: (_, rowData) =>
handleDelete(rowData as FormattedWorkflowOverview),
},
);
}

return actionItems;
}, [handleDelete, handleEdit, handleExecute, handleView, isDeveloperModeOn]);

const columns = useMemo<TableColumn<FormattedWorkflowOverview>[]>(
() => [
Expand Down
3 changes: 3 additions & 0 deletions plugins/orchestrator/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
discoveryApiRef,
} from '@backstage/core-plugin-api';

import { FEATURE_FLAG_DEVELOPER_MODE } from '@janus-idp/backstage-plugin-orchestrator-common';

import { orchestratorApiRef, OrchestratorClient } from './api';
import { orchestratorRootRouteRef } from './routes';

Expand All @@ -22,6 +24,7 @@ export const orchestratorPlugin = createPlugin({
routes: {
root: orchestratorRootRouteRef,
},
featureFlags: [{ name: FEATURE_FLAG_DEVELOPER_MODE }],
});

export const OrchestratorPage = orchestratorPlugin.provide(
Expand Down

0 comments on commit 05719a9

Please sign in to comment.