1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { StyleRulesCallback, WithStyles, Typography, withStyles } from '@material-ui/core';
7 import { ArvadosTheme } from 'common/custom-theme';
8 import classNames from 'classnames';
9 import { connect, DispatchProp } from 'react-redux';
10 import { RootState } from 'store/store';
11 import { FederationConfig } from 'routes/routes';
12 import { renderLinks } from './code-snippet';
13 import { FixedSizeList } from 'react-window';
14 import AutoSizer from "react-virtualized-auto-sizer";
16 type CssRules = 'root' | 'space' | 'content' ;
18 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20 boxSizing: 'border-box',
22 padding: theme.spacing.unit,
33 export interface CodeSnippetDataProps {
35 lineFormatter?: (lines: string[], index: number) => string;
37 apiResponse?: boolean;
41 interface CodeSnippetAuthProps {
42 auth: FederationConfig;
45 type CodeSnippetProps = CodeSnippetDataProps & WithStyles<CssRules>;
47 const mapStateToProps = (state: RootState): CodeSnippetAuthProps => ({
51 export const VirtualCodeSnippet = withStyles(styles)(connect(mapStateToProps)(
52 ({ classes, lines, lineFormatter, linked, className, apiResponse, dispatch, auth }: CodeSnippetProps & CodeSnippetAuthProps & DispatchProp) => {
53 const RenderRow = ({index, style}) => {
54 const lineContents = lineFormatter ? lineFormatter(lines, index) : lines[index];
55 return <span style={style}>{linked ? renderLinks(auth, dispatch)(lineContents) : lineContents}</span>
60 className={classNames([classes.root, className])}>
61 <Typography className={classNames(classes.content, apiResponse ? classes.space : className)} component="pre">
63 {({ height, width }) =>
68 itemCount={lines.length}