1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { Typography } from '@mui/material';
8 import { WithStyles } from '@mui/styles';
9 import withStyles from '@mui/styles/withStyles';
10 import { ArvadosTheme } from 'common/custom-theme';
11 import classNames from 'classnames';
12 import { connect, DispatchProp } from 'react-redux';
13 import { RootState } from 'store/store';
14 import { FederationConfig } from 'routes/routes';
15 import { renderLinks } from './code-snippet';
16 import { FixedSizeList } from 'react-window';
17 import AutoSizer from "react-virtualized-auto-sizer";
19 type CssRules = 'root' | 'space' | 'content' ;
21 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
23 boxSizing: 'border-box',
25 padding: theme.spacing(1),
36 export interface CodeSnippetDataProps {
38 lineFormatter?: (lines: string[], index: number) => string;
40 apiResponse?: boolean;
44 interface CodeSnippetAuthProps {
45 auth: FederationConfig;
48 type CodeSnippetProps = CodeSnippetDataProps & WithStyles<CssRules>;
50 const mapStateToProps = (state: RootState): CodeSnippetAuthProps => ({
54 export const VirtualCodeSnippet = withStyles(styles)(connect(mapStateToProps)(
55 ({ classes, lines, lineFormatter, linked, className, apiResponse, dispatch, auth }: CodeSnippetProps & CodeSnippetAuthProps & DispatchProp) => {
56 const RenderRow = ({index, style}) => {
57 const lineContents = lineFormatter ? lineFormatter(lines, index) : lines[index];
58 return <span style={style}>{linked ? renderLinks(auth, dispatch)(lineContents) : lineContents}</span>
63 data-cy="virtual-code-snippet"
64 className={classNames([classes.root, className])}>
65 <Typography className={classNames(classes.content, apiResponse ? classes.space : className)} component="pre">
67 {({ height, width }) =>
72 itemCount={lines.length}