diff --git a/workspaces/resource-optimization/app-config.yaml b/workspaces/resource-optimization/app-config.yaml index 244b28fcf1..f5ef9d672a 100644 --- a/workspaces/resource-optimization/app-config.yaml +++ b/workspaces/resource-optimization/app-config.yaml @@ -45,7 +45,7 @@ integrations: proxy: endpoints: - '/resource-optimization/v1': + '/cost-management/v1': target: https://console.redhat.com/api/cost-management/v1 changeOrigin: true headers: diff --git a/workspaces/resource-optimization/plugins/resource-optimization/src/api/refs.ts b/workspaces/resource-optimization/plugins/resource-optimization/src/api/refs.ts new file mode 100644 index 0000000000..e3289edc8e --- /dev/null +++ b/workspaces/resource-optimization/plugins/resource-optimization/src/api/refs.ts @@ -0,0 +1,7 @@ +import { Apis } from "@backstage-community/plugin-resource-optimization-common"; +import { createApiRef } from "@backstage/core-plugin-api"; + + +export const optimizationsApiRef = createApiRef({ + id: 'plugin.resource-optimization.api', +}); \ No newline at end of file diff --git a/workspaces/resource-optimization/plugins/resource-optimization/src/components/ExampleComponent/ExampleComponent.tsx b/workspaces/resource-optimization/plugins/resource-optimization/src/components/ExampleComponent/ExampleComponent.tsx index dbdb4c1de7..4a8ad83008 100644 --- a/workspaces/resource-optimization/plugins/resource-optimization/src/components/ExampleComponent/ExampleComponent.tsx +++ b/workspaces/resource-optimization/plugins/resource-optimization/src/components/ExampleComponent/ExampleComponent.tsx @@ -1,38 +1,213 @@ import React from 'react'; -import { Typography, Grid } from '@material-ui/core'; +import { Typography, Grid, Chip, Box } from '@material-ui/core'; import { InfoCard, Header, + HeaderLabel, + HeaderTabs, Page, Content, ContentHeader, - HeaderLabel, - SupportButton, + Link, TrendLine, + TableColumn, Table, + SupportButton, StatusOK, GaugeCard, + Select,Progress, ResponseErrorPanel } from '@backstage/core-components'; -import { ExampleFetchComponent } from '../ExampleFetchComponent'; +import useAsync from 'react-use/lib/useAsync'; +import { useApi, configApiRef } from '@backstage/core-plugin-api'; +import { optimizationsApiRef } from '../../api/refs'; +import { Apis } from "@backstage-community/plugin-resource-optimization-common"; +import { JsonUtils } from "@backstage-community/plugin-resource-optimization-common"; +import { toCamelCaseObjectKeys } from '@backstage-community/plugin-resource-optimization-common/src/utils/json'; +import { RecommendationList, Recommendations } from '@backstage-community/plugin-resource-optimization-common/src/generated/models'; + +export default { + title: 'Plugins/Examples', + component: Page, +}; + +interface TableData { + container: string; + project: string; + workload: string; + workload_type: string; + cluster: string; + last_reported: string; +} + +export const ExampleComponent = () => { + + const config = useApi(configApiRef); + const api = useApi(optimizationsApiRef); + + const { value, loading, error } = useAsync(async () => { + return (await api.getRecommendationList({ query: {} })).text(); + }, []); + + const generateTestData = () => { + const data: Array = []; + + if(value){ + const responseData = toCamelCaseObjectKeys(JSON.parse(value)); + + responseData?.data?.map( (item: Recommendations) => { + data.push({ + container: item.container ? item.container : '', + project: item.project ? item.project : '', + workload: item.workload ? item.workload : '', + workload_type: item.workloadType ? item.workloadType : '', + cluster: item.clusterAlias ? item.clusterAlias : item.clusterUuid ? item.clusterUuid : '', + last_reported: '6 hours ago' + }); + }) + } -export const ExampleComponent = () => ( - -
- - + return data; + }; + + const columns: TableColumn[] = [ + { + title: 'Container names', + highlight: true, + render: (row: Partial) => ( + <> + {row.container} + + ), + }, + { + title: 'Project names', + render: (row: Partial) => ( + <> + {row.project} + + ), + }, + { + title: 'Workload names', + render: (row: Partial) => ( + <> + {row.workload} + + ), + }, + { + title: 'Workload types', + render: (row: Partial) => ( + <> + {row.workload_type} + + ), + }, + { + title: 'Cluster names', + render: (row: Partial) => ( + <> + {row.cluster} + + ), + }, + { + title: 'Last reported', + render: (row: Partial) => ( + <> + {row.last_reported} + + ), + } + ]; + + + const ExampleHeader = () => ( +
- - - A description of your plugin goes here. - - - - - - All content should be wrapped in a card like this. - - - - - - - - - -); + ); + + const SELECT_ITEMS = [ + { + label: 'Cluster 1', + value: 'cluster_1', + }, + { + label: 'Cluster 2', + value: 'cluster_2', + }, + { + label: 'Cluster 3', + value: 'cluster_3', + }, + ]; + + const ClusterFilter = () => ( + {}} + /> + ); + + const WorkloadFilter = () => ( + {}} + /> + ); + + return ( + loading ? + : +
+ + + +

Filters

+
+ + + + + + + + + + + + + + + + + + ); +}; \ No newline at end of file diff --git a/workspaces/resource-optimization/plugins/resource-optimization/src/plugin.ts b/workspaces/resource-optimization/plugins/resource-optimization/src/plugin.ts index fceb24c79a..e07f000703 100644 --- a/workspaces/resource-optimization/plugins/resource-optimization/src/plugin.ts +++ b/workspaces/resource-optimization/plugins/resource-optimization/src/plugin.ts @@ -1,12 +1,37 @@ import { + createApiFactory, createPlugin, createRoutableExtension, + discoveryApiRef, + fetchApiRef, } from '@backstage/core-plugin-api'; +import { Apis } from "@backstage-community/plugin-resource-optimization-common"; import { rootRouteRef } from './routes'; +import { optimizationsApiRef } from './api/refs' export const resourceOptimizationPlugin = createPlugin({ id: 'resource-optimization', + apis: [ + createApiFactory({ + api: optimizationsApiRef, + deps: { + discoveryApi: discoveryApiRef, + fetchApi: fetchApiRef, + }, + factory({ discoveryApi, fetchApi }) { + return new Apis.OptimizationsApiClient({ + discoveryApi: { + async getBaseUrl() { + const baseUrl = await discoveryApi.getBaseUrl('proxy'); + return `${baseUrl}/cost-management/v1`; + }, + }, + fetchApi, + }); + }, + }), + ], routes: { root: rootRouteRef, },