X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/6ddc4f58120358fa12de736c49be69f8373b4068..cc6952cee5f114b62b851adcbc667ed20a3946ce:/src/views/process-panel/process-log-code-snippet.tsx diff --git a/src/views/process-panel/process-log-code-snippet.tsx b/src/views/process-panel/process-log-code-snippet.tsx index 4f19f917..2b7391c2 100644 --- a/src/views/process-panel/process-log-code-snippet.tsx +++ b/src/views/process-panel/process-log-code-snippet.tsx @@ -2,25 +2,42 @@ // // SPDX-License-Identifier: AGPL-3.0 -import React from 'react'; -import { MuiThemeProvider, createMuiTheme, StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core/styles'; -import { CodeSnippet } from 'components/code-snippet/code-snippet'; +import React, { useEffect, useRef, useState } from 'react'; +import { + MuiThemeProvider, + createMuiTheme, + StyleRulesCallback, + withStyles, + WithStyles +} from '@material-ui/core/styles'; import grey from '@material-ui/core/colors/grey'; import { ArvadosTheme } from 'common/custom-theme'; import { Link, Typography } from '@material-ui/core'; -import { navigateTo } from 'store/navigation/navigation-action'; +import { navigationNotAvailable } from 'store/navigation/navigation-action'; import { Dispatch } from 'redux'; import { connect, DispatchProp } from 'react-redux'; +import classNames from 'classnames'; +import { FederationConfig, getNavUrl } from 'routes/routes'; +import { RootState } from 'store/store'; -type CssRules = 'wordWrap' | 'codeSnippetContainer'; +type CssRules = 'root' | 'wordWrap' | 'logText'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ + root: { + boxSizing: 'border-box', + overflow: 'auto', + backgroundColor: '#000', + height: `calc(100% - ${theme.spacing.unit * 4}px)`, // so that horizontal scollbar is visible + "& a": { + color: theme.palette.primary.main, + }, + }, + logText: { + padding: theme.spacing.unit * 0.5, + }, wordWrap: { whiteSpace: 'pre-wrap', }, - codeSnippetContainer: { - height: `calc(100% - ${theme.spacing.unit * 4}px)`, // so that horizontal scollbar is visible - }, }); const theme = createMuiTheme({ @@ -28,9 +45,6 @@ const theme = createMuiTheme({ MuiTypography: { body2: { color: grey["200"] - }, - root: { - backgroundColor: '#000' } } }, @@ -46,7 +60,11 @@ interface ProcessLogCodeSnippetProps { wordWrap?: boolean; } -const renderLinks = (fontSize: number, dispatch: Dispatch) => (text: string) => { +interface ProcessLogCodeSnippetAuthProps { + auth: FederationConfig; +} + +const renderLinks = (fontSize: number, auth: FederationConfig, dispatch: Dispatch) => (text: string) => { // Matches UUIDs & PDHs const REGEX = /[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}|[0-9a-f]{32}\+\d+/g; const links = text.match(REGEX); @@ -58,7 +76,14 @@ const renderLinks = (fontSize: number, dispatch: Dispatch) => (text: string) => {part} {links[index] && - dispatch(navigateTo(links[index]))} + { + const url = getNavUrl(links[index], auth) + if (url) { + window.open(`${window.location.origin}${url}`, '_blank'); + } else { + dispatch(navigationNotAvailable(links[index])); + } + }} style={ {cursor: 'pointer'} }> {links[index]} } @@ -67,11 +92,38 @@ const renderLinks = (fontSize: number, dispatch: Dispatch) => (text: string) => ; }; -export const ProcessLogCodeSnippet = withStyles(styles)(connect()( - (props: ProcessLogCodeSnippetProps & WithStyles & DispatchProp) => - - - )); \ No newline at end of file +const mapStateToProps = (state: RootState): ProcessLogCodeSnippetAuthProps => ({ + auth: state.auth, +}); + +export const ProcessLogCodeSnippet = withStyles(styles)(connect(mapStateToProps)( + ({classes, lines, fontSize, auth, dispatch, wordWrap}: ProcessLogCodeSnippetProps & WithStyles & ProcessLogCodeSnippetAuthProps & DispatchProp) => { + const [followMode, setFollowMode] = useState(true); + const scrollRef = useRef(null); + + useEffect(() => { + if (followMode && scrollRef.current && lines.length > 0) { + // Scroll to bottom + scrollRef.current.scrollTop = scrollRef.current.scrollHeight; + } + }, [followMode, lines, scrollRef]); + + return +
{ + const elem = e.target as HTMLDivElement; + if (elem.scrollTop + (elem.clientHeight*1.1) >= elem.scrollHeight) { + setFollowMode(true); + } else { + setFollowMode(false); + } + }}> + { lines.map((line: string, index: number) => + + {renderLinks(fontSize, auth, dispatch)(line)} + + ) } +
+
+ })); \ No newline at end of file