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

Brightspace / react-valence-ui-fileviewer / 7111280825

06 Dec 2023 07:04AM UTC coverage: 56.35% (-32.8%) from 89.198%
7111280825

push

github

web-flow
Merge pull request #114 from Brightspace/venkata/node-sass-update-2

adding npm i in release.yml

604 of 1444 branches covered (0.0%)

1624 of 2882 relevant lines covered (56.35%)

11.45 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'),
2!
4
        ReactDOM = require( 'react-dom' );
5

2✔
6
var ImageViewer = React.createClass({
2✔
7
        propTypes: {
8
                src: React.PropTypes.string.isRequired,
2✔
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 };
15!
17
        },
18
        componentWillMount: function() {
19
                this.updateProgress(0);
15✔
20
                if (this.props.resizeCallback) {
15✔
21
                        this.props.resizeCallback('100%', true);
2✔
22
                }
23
        },
24
        componentDidMount: function() {
25
                if (this.props.token) {
15✔
26
                        this.getDataUri(this.props.src, this.props.token)
27
                                .then(uri => {
15!
28
                                        this.setState({ src: uri });
×
29
                                        this.updateProgress(100);
×
30
                                });
×
31
                } else {
32
                        this.updateProgress(100);
33
                }
15✔
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() {
30✔
51
                // without this, the file continues to download after being removed from the DOM
12✔
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