Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | 4x 31x 31x 31x 31x 1x 4x 1x | import {
Box,
ButtonBase,
FontWeight,
TextColor,
Text as TextComponent,
TextVariant,
} from '@metamask/design-system-react';
import { stringify } from '@metamask/kernel-utils';
import { useMemo, useState } from 'react';
import type { VatRecord } from '../types.ts';
import { Accordion } from './shared/Accordion.tsx';
import { Modal } from './shared/Modal.tsx';
import { VatTable } from './VatTable.tsx';
export const SubclusterAccordion: React.FC<{
id: string;
vats: VatRecord[];
config: unknown;
onPingVat: (id: string) => void;
onRestartVat: (id: string) => void;
onTerminateVat: (id: string) => void;
onTerminateSubcluster: (id: string) => void;
}> = ({
id,
vats,
config,
onPingVat,
onRestartVat,
onTerminateVat,
onTerminateSubcluster,
}) => {
const [isExpanded, setIsExpanded] = useState(false);
const [isConfigModalOpen, setIsConfigModalOpen] = useState(false);
const formattedConfig = useMemo(() => stringify(config, 2), [config]);
return (
<>
<Accordion
title={
<>
<TextComponent
variant={TextVariant.BodySm}
fontWeight={FontWeight.Medium}
color={TextColor.TextDefault}
>
Subcluster {id} -{' '}
</TextComponent>
<TextComponent
variant={TextVariant.BodySm}
color={TextColor.TextMuted}
fontWeight={FontWeight.Regular}
className="ml-1"
>
{vats.length} Vat{vats.length === 1 ? '' : 's'}
</TextComponent>
</>
}
isExpanded={isExpanded}
onToggle={setIsExpanded}
testId={`subcluster-accordion-${id}`}
>
<Box className="flex gap-2 px-3">
<ButtonBase
className="h-auto flex-row justify-center rounded-md bg-error-default py-1 hover:bg-error-default-pressed active:bg-error-default-pressed"
onClick={() => onTerminateSubcluster(id)}
data-testid="terminate-subcluster-button"
>
<TextComponent
variant={TextVariant.BodySm}
color={TextColor.ErrorInverse}
>
Terminate
</TextComponent>
</ButtonBase>
<ButtonBase
className="h-auto flex-row justify-center rounded-md bg-muted py-1 hover:bg-muted-hover active:bg-muted-pressed"
onClick={() => setIsConfigModalOpen(true)}
data-testid="view-config-button"
>
<TextComponent
variant={TextVariant.BodySm}
color={TextColor.TextDefault}
>
View Config
</TextComponent>
</ButtonBase>
</Box>
<VatTable
vats={vats}
onPingVat={onPingVat}
onRestartVat={onRestartVat}
onTerminateVat={onTerminateVat}
/>
</Accordion>
<Modal
isOpen={isConfigModalOpen}
onClose={() => setIsConfigModalOpen(false)}
title={`Subcluster ${id} Configuration`}
size="md"
>
<Box className="flex flex-col gap-4">
<textarea
className="font-mono text-sm border border-border-default rounded-md p-4 bg-background-alternative text-text-default resize-none w-full min-h-[350px] leading-relaxed whitespace-pre overflow-auto"
value={formattedConfig}
readOnly
rows={20}
data-testid="config-textarea"
/>
</Box>
</Modal>
</>
);
};
|