export function TraceTab()

in karavan-app/src/main/webui/src/project/trace/TraceTab.tsx [35:100]


export function TraceTab() {

    const [project, refreshTrace, setRefreshTrace] = useProjectStore((state) =>
        [state.project, state.refreshTrace, state.setRefreshTrace], shallow);
    const [containers] = useStatusesStore((state) => [state.containers], shallow);
    const [containerName, setContainerName] = useState<string>();

    const camelContainers = containers
        .filter(c => c.projectId === project.projectId && ['devmode', 'packaged'].includes(c.type));

    function getContainer() {
        return containerName ? containerName : camelContainers.at(0)?.containerName;
    }

    return (
        <PageSection className="project-tab-panel" padding={{default: "padding"}}>
            <Panel>
                <PanelHeader>
                    <Flex direction={{default: "row"}} justifyContent={{default: "justifyContentSpaceBetween"}}>
                        <FlexItem>
                            <Flex direction={{default: "row"}}>
                                <FlexItem>
                                    <TextContent>
                                        <Text component={TextVariants.h6}>Container</Text>
                                    </TextContent>
                                </FlexItem>
                                <FlexItem>
                                    <ToggleGroup>
                                        {camelContainers.map((containerStatus, index) =>
                                            <ToggleGroupItem
                                                text={containerStatus.containerName}
                                                isSelected={getContainer() === containerStatus.containerName}
                                                onChange={(_, selected) => {
                                                    if (selected) {
                                                        setContainerName(containerStatus.containerName);
                                                    }
                                                }}
                                            />
                                        )}
                                    </ToggleGroup>
                                </FlexItem>
                            </Flex>
                        </FlexItem>
                        <FlexItem>
                            <Flex direction={{default: "row"}}>
                                <FlexItem>
                                    <TextContent>
                                        <Text component={TextVariants.h6}>Auto refresh</Text>
                                    </TextContent>
                                </FlexItem>
                                <FlexItem>
                                    <Switch aria-label="refresh"
                                            id="refresh"
                                            isChecked={refreshTrace}
                                            onChange={(_, checked) => setRefreshTrace(checked)}
                                    />
                                </FlexItem>
                            </Flex>
                        </FlexItem>
                    </Flex>
                </PanelHeader>
            </Panel>
            <TraceTable containerName={getContainer()}/>
        </PageSection>
    )
}