import { RuleAction , Aggregation, ComponentOperation, Transition, Component, ChangeAnalysisReport } from '@aws-c2a/models'; import { Tab, Tabs, AppBar } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import React, { useState } from 'react'; import AggregationsTab from './AggregationsView/AggregationsTab'; import HierarchicalTab from './HierarchicalView/HierarchicalTab'; import { findAggregationWithChange } from './selectors/aggregation-helpers'; interface AppState { changeReport: ChangeAnalysisReport, showComponentInHierarchy: (comp: Transition) => void, selectedCompTransition?: Transition, setSelectedCompTransition: React.Dispatch | undefined>>, selectedAgg?: Aggregation, setSelectedAgg: React.Dispatch | undefined>>, setSelectedChange: (op: ComponentOperation) => void, showAggregation: (agg: Aggregation) => void, setChangesApproval: (changes: ComponentOperation[], state: RuleAction) => void, approvedChanges: Map, } export const AppContext = React.createContext({} as AppState); const useStyles = makeStyles({ wrapper: { display: 'flex', flexDirection: 'column', height: '100vh', }, panel: { height: '100%', maxHeight: '100%', overflow: 'hidden', flexGrow: 1, }, }); interface AppProps { changeReport: ChangeAnalysisReport; } export default function App({changeReport}: AppProps): JSX.Element { const classes = useStyles(); const [selectedTab, setSelectedTab] = useState(0); const [selectedCompTransition, setSelectedCompTransition] = useState(undefined as Transition | undefined); const [selectedAgg, setSelectedAgg] = useState(undefined as Aggregation | undefined); const [approvedChanges, setApprovedChanges] = useState>( new Map([...changeReport.rulesOutput] .map(([op, effect]) => [op, effect.action ?? RuleAction.None]), ), ); const showComponentInHierarchy = (comp: Transition) => { setSelectedTab(1); setSelectedCompTransition(comp); }; const showAggregation = (agg: Aggregation) => { setSelectedTab(0); setSelectedAgg(agg); }; const setSelectedChange = (op: ComponentOperation) => { const agg = findAggregationWithChange(op, changeReport.aggregations); if(agg) showAggregation(agg); }; const setChangesApproval = (changes: ComponentOperation[], state: RuleAction) => { setApprovedChanges(new Map([...approvedChanges, ...changes.map(c => [c, state] as const)])); }; return (
setSelectedTab(v)} aria-label="simple tabs example">
); }