All files / owid-grapher/grapher/noDataModal NoDataModal.tsx

97.3% Statements 72/74
85.71% Branches 6/7
66.67% Functions 2/3
97.3% Lines 72/74

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 681x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 4x 4x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x
import * as React from "react"
import { action, computed } from "mobx"
import { observer } from "mobx-react"
import { Bounds, DEFAULT_BOUNDS } from "../../clientUtils/Bounds"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faPlus } from "@fortawesome/free-solid-svg-icons/faPlus"
import { faExchangeAlt } from "@fortawesome/free-solid-svg-icons/faExchangeAlt"
 
export interface NoDataModalManager {
    canChangeEntity?: boolean
    canAddData?: boolean
    isSelectingData?: boolean
    entityType?: string
}
 
@observer
export class NoDataModal extends React.Component<{
    bounds?: Bounds
    message?: string
    manager: NoDataModalManager
}> {
    @action.bound private onDataSelect(): void {
        this.props.manager.isSelectingData = true
    }
 
    @computed private get bounds(): Bounds {
        return this.props.bounds ?? DEFAULT_BOUNDS
    }
 
    render(): JSX.Element {
        const { message, manager } = this.props
        const entityType = manager.entityType
        const { bounds } = this
        return (
            <foreignObject
                x={bounds.left}
                y={bounds.top}
                width={bounds.width}
                height={bounds.height}
            >
                <div className="NoData">
                    <p className="message">{message || "No available data"}</p>
                    <div className="actions">
                        {manager.canAddData && (
                            <button
                                className="action"
                                onClick={this.onDataSelect}
                            >
                                <FontAwesomeIcon icon={faPlus} /> Add{" "}
                                {entityType}
                            </button>
                        )}
                        {manager.canChangeEntity && (
                            <button
                                className="action"
                                onClick={this.onDataSelect}
                            >
                                <FontAwesomeIcon icon={faExchangeAlt} /> Change{" "}
                                {entityType}
                            </button>
                        )}
                    </div>
                </div>
            </foreignObject>
        )
    }
}