INFRA-3746 | Abhishek | Allow features in diagnostics based on language

This commit is contained in:
Abhishek Katiyar
2024-12-24 00:59:51 +05:30
parent a200316919
commit fdfd16fab6

View File

@@ -8,12 +8,19 @@ import { AccountTree as AccountTreeIcon, Waves as WavesIcon } from '@material-ui
import { setCurrentStep, setDiagnosticType } from '../../slices/diagnosticSlice';
import CpuIcon from '../assets/images/CpuIcon.svg';
import { DiagnosticType } from './utils';
import { useFormikContext } from 'formik';
interface Button {
id: DiagnosticType;
icon: React.ReactNode;
label: string;
}
const languageFeatureMap = {
Golang: [DiagnosticType.HeapDump, DiagnosticType.CpuProfile],
Java: [DiagnosticType.HeapDump, DiagnosticType.ThreadDump, DiagnosticType.CpuProfile],
Kotlin: [DiagnosticType.HeapDump, DiagnosticType.ThreadDump, DiagnosticType.CpuProfile],
};
const buttons: Button[] = [
{
id: DiagnosticType.HeapDump,
@@ -35,6 +42,12 @@ const buttons: Button[] = [
const DefaultDiagnosticStep: React.FC = (): React.JSX.Element => {
const dispatch = useDispatch();
const { values }: { values: any } = useFormikContext();
const allowedButtons = buttons.filter(b =>
languageFeatureMap[values.metadata?.language].includes(b.id),
);
console.log(allowedButtons);
const handleDiagnosticSelection = (
e: React.MouseEvent<HTMLButtonElement>,
buttonId: DiagnosticType,
@@ -47,7 +60,7 @@ const DefaultDiagnosticStep: React.FC = (): React.JSX.Element => {
<>
<Typography variant="body1">Please choose one of the following options:</Typography>
<Grid container spacing={2} justifyContent="center" style={{ marginTop: '16px' }}>
{buttons.map(button => (
{allowedButtons.map(button => (
<Grid item key={button.id}>
<IconButton onClick={e => handleDiagnosticSelection(e, button.id)} color="primary">
{button.icon}