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

Brightspace / react-valence-ui-fileviewer / 7995792934

21 Feb 2024 09:25PM UTC coverage: 56.315% (-0.04%) from 56.35%
7995792934

Pull #117

github

web-flow
Merge c19bfe4c3 into 82efc8be8
Pull Request #117: GAUD-5048 - Use new release token

603 of 1444 branches covered (41.76%)

1623 of 2882 relevant lines covered (56.32%)

5.69 hits per line

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

46.76
/src/plugins/image/viewer.js
1
'use strict';
2

3
var React = require('react'),
1!
4
        ReactDOM = require( 'react-dom' );
5

1✔
6
var ImageViewer = React.createClass({
1✔
7
        propTypes: {
8
                src: React.PropTypes.string.isRequired,
1✔
9
                mimeType: React.PropTypes.string,
10
                token: React.PropTypes.string,
11
                resizeCallback: React.PropTypes.func
12
        },
13
        getInitialState: function() {
14
                return this.props.token
15
                        ? { src: '' }
16
                        : { src: this.props.src };
7!
17
        },
18
        componentWillMount: function() {
19
                this.updateProgress(0);
7✔
20
                if (this.props.resizeCallback) {
7✔
21
                        this.props.resizeCallback('100%', true);
1✔
22
                }
23
        },
24
        componentDidMount: function() {
25
                if (this.props.token) {
7✔
26
                        this.getDataUri(this.props.src, this.props.token)
27
                                .then(uri => {
7!
28
                                        this.setState({ src: uri });
×
29
                                        this.updateProgress(100);
×
30
                                });
×
31
                } else {
32
                        this.updateProgress(100);
33
                }
7✔
34
        },
35
        componentDidUpdate: function(prevProps) {
36
                if (this.props.src !== prevProps.src) {
37
                        if (!this.props.token) {
×
38
                                this.setState({ src: this.props.src });
39
                                return;
×
40
                        }
×
41
                        this.getDataUri(this.props.src, this.props.token)
×
42
                                .then(uri => this.setState({ src: uri }));
×
43
                }
44
        },
×
45
        updateProgress: function(progress) {
×
46
                if (this.props.progressCallback) {
47
                        this.props.progressCallback(progress, 'none');
48
                }
49
        },
50
        componentWillUnmount: function() {
14✔
51
                // without this, the file continues to download after being removed from the DOM
6✔
52
                ReactDOM.findDOMNode(this.refs.image).src = '';
53
        },
54
        getDataUri(href, token) {
55
                return fetch(href, {
56
                        headers: {
×
57
                                'Authorization': `Bearer ${token}`
58
                        }
59
                }).then(res => {
×
60
                        return res.arrayBuffer();
61
                }).then(buff => {
×
62
                        let binary = '';
63
                        const bytes = [].slice.call(new Uint8Array(buff));
64
                        bytes.forEach(byte => binary += String.fromCharCode(byte));
65
                        const base64String = window.btoa(binary);
66
                        return `data:${this.props.mimeType};base64,${base64String}`;
×
67
                });
68
        },
×
69
        render: function() {
×
70
                // Wrapped in a Div in order to prevent it from resizing to fit the dimensions of the flex-box
×
71
                return <div className="vui-fileviewer-image-container"><img ref="image" src={this.state.src} alt="" className="vui-fileviewer-image" /></div>;
×
72
        }
73
});
×
74

×
75
module.exports = ImageViewer;
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

© 2025 Coveralls, Inc