mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
09.43.2018 1a21e0d3baca3870611a1fe712027a559d9a4b93
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
import React from 'react';
import PropTypes from 'prop-types';
import {Table} from 'reactstrap';
import LogEntry from './LogEntry';
import {IconSortDown, IconSortUp} from '../../general/IconComponents';
import I18n from '../../general/translation/I18n';
 
const getLocationString = (locationFormat, entry) => {
    switch (locationFormat) {
        case 'short':
            return `${entry.javaClassSimpleName}:${entry.methodName}:${entry.lineNumber}`;
        case 'normal':
            return `${entry.javaClass}:${entry.methodName}:${entry.lineNumber}`;
        default:
            return null;
    }
};
 
function LogTable({locationFormat, showStackTrace, entries, search, ascendingOrder, toggleOrder}) {
    const lowercaseSearch = search.toLowerCase();
    let sort = ascendingOrder === 'true' ? <IconSortUp/> : <IconSortDown/>;
    return (
        <Table striped bordered hover size={'sm'} responsive>
            <thead>
            <tr>
                <th style={{whiteSpace: 'nowrap'}}>
                    <I18n name={'logviewer.timestamp'}>Timestamp</I18n>{' '}
                    <button
                        onClick={toggleOrder}
                        type="button"
                        className="btn btn-outline-primary btn-sm"
                    >
                        {sort}
                    </button>
                </th>
                <th><I18n name={'logviewer.level'}>Level</I18n></th>
                <th><I18n name={'logviewer.message'}>Message</I18n></th>
                {locationFormat !== 'none' ? <th><I18n name={'logviewer.location'}>Location</I18n></th> : null}
            </tr>
            </thead>
            <tbody>
            {entries
                .filter(entry => [entry.message, (showStackTrace === 'true') ? entry.stackTrace : '', getLocationString(locationFormat, entry), entry.level, entry.logDate]
                    .join('|#|').toLowerCase()
                    .indexOf(lowercaseSearch) !== -1)
                .map((entry, index) => <LogEntry
                    entry={entry}
                    search={lowercaseSearch}
                    locationString={getLocationString(locationFormat, entry)}
                    showStackTrace={showStackTrace}
                    key={index}
                />)}
            </tbody>
        </Table>
    );
}
 
LogTable.propTypes = {
    locationFormat: PropTypes.oneOf(['none', 'short', 'normal']),
    entries: PropTypes.array,
    ascendingOrder: PropTypes.oneOf(['true', 'false']),
    search: PropTypes.string
};
 
LogTable.defaultProps = {
    locationFormat: 'none',
    ascendingOrder: 'false',
    entries: [],
    search: ''
};
 
export default LogTable;