• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mac-s-g / react-json-view / #2828

18 Mar 2024 12:10PM UTC coverage: 15.895% (-67.8%) from 83.718%
#2828

push

loredanacirstea
1.21.6

57 of 368 branches covered (15.49%)

Branch coverage included in aggregate %.

101 of 626 relevant lines covered (16.13%)

0.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/js/components/DataTypes/Function.js
1
import React from 'react';
2
import DataTypeLabel from './DataTypeLabel';
3

4
//theme
5
import Theme from './../../themes/getStyle';
6

7
//attribute store for storing collapsed state
8
import AttributeStore from './../../stores/ObjectAttributes';
9

10
export default class extends React.PureComponent {
11
    constructor(props) {
12
        super(props);
×
13
        this.state = {
×
14
            collapsed: AttributeStore.get(
15
                props.rjvId,
16
                props.namespace,
17
                'collapsed',
18
                true
19
            )
20
        };
21
    }
22

23
    toggleCollapsed = () => {
×
24
        this.setState(
×
25
            {
26
                collapsed: !this.state.collapsed
27
            },
28
            () => {
29
                // will be called after setState takes effect.
30
                AttributeStore.set(
×
31
                    this.props.rjvId,
32
                    this.props.namespace,
33
                    'collapsed',
34
                    this.state.collapsed
35
                );
36
            }
37
        );
38
    };
39

40
    render() {
41
        const type_name = 'function';
×
42
        const { props } = this;
×
43
        const { collapsed } = this.state;
×
44

45
        return (
×
46
            <div {...Theme(props.theme, 'function')}>
47
                <DataTypeLabel type_name={type_name} {...props} />
48
                <span
49
                    {...Theme(props.theme, 'function-value')}
50
                    class="rjv-function-container"
51
                    onClick={this.toggleCollapsed}
52
                >
53
                    {this.getFunctionDisplay(collapsed)}
54
                </span>
55
            </div>
56
        );
57
    }
58

59
    getFunctionDisplay = collapsed => {
×
60
        const { props } = this;
×
61
        if (collapsed) {
×
62
            return (
×
63
                <span>
64
                    {this.props.value
65
                        .toString()
66
                        .slice(9, -1)
67
                        .replace(/\{[\s\S]+/, '')}
68
                    <span
69
                        class="function-collapsed"
70
                        style={{ fontWeight: 'bold' }}
71
                    >
72
                        <span>{'{'}</span>
73
                        <span {...Theme(props.theme, 'ellipsis')}>...</span>
74
                        <span>{'}'}</span>
75
                    </span>
76
                </span>
77
            );
78
        } else {
79
            return this.props.value.toString().slice(9, -1);
×
80
        }
81
    };
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc