/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import style from "./hiplot.scss"; import React from "react"; import { HiPlotLoadStatus, IDatasets } from "./types"; import { HiPlotDataControlProps, RestoreDataBtn, ExcludeDataBtn, ExportDataCSVBtn, KeepDataBtn } from "./controls"; import { DataProviderClass, DataProviderComponentClass, DataProviderProps} from "./plugin"; //@ts-ignore import IconSVG from "../hiplot/static/icon.svg"; //@ts-ignore import IconSVGW from "../hiplot/static/icon-w.svg"; import { HiPlotTutorial } from "./tutorial/tutorial"; import { PersistentState } from "./lib/savedstate"; interface HeaderBarProps extends IDatasets, HiPlotDataControlProps { loadStatus: HiPlotLoadStatus; // Should not allow to load an xp when already loading another xp persistentState: PersistentState; onLoadExperiment: (load_promise: Promise) => void; dark: boolean; dataProvider: DataProviderClass; }; interface HeaderBarState { isTextareaFocused: boolean; hasTutorial: boolean; }; export class HeaderBar extends React.Component { dataProviderRef = React.createRef(); selected_count_ref: React.RefObject = React.createRef(); selected_pct_ref: React.RefObject = React.createRef(); total_count_ref: React.RefObject = React.createRef(); controls_root_ref: React.RefObject = React.createRef(); constructor(props: HeaderBarProps) { super(props); this.state = { isTextareaFocused: false, hasTutorial: false, }; } recomputeMetrics() { if (!this.selected_count_ref.current) { return; } const selected_count = this.props.rows_selected.length; const total_count = this.props.rows_filtered.length; this.selected_count_ref.current.innerText = '' + selected_count; this.selected_pct_ref.current.innerText = '' + (100 * selected_count / total_count).toPrecision(3); this.total_count_ref.current.innerText = '' + total_count; } componentDidMount() { this.recomputeMetrics(); } componentDidUpdate() { this.recomputeMetrics(); } onToggleTutorial() { this.setState(function(prevState, prevProps) { return { hasTutorial: !prevState.hasTutorial }; }); } onRefresh() { const promise = this.dataProviderRef.current.refresh(); if (promise !== null) { this.props.onLoadExperiment(promise); } } renderControls() { const dataProviderProps: React.ClassAttributes & DataProviderProps = { ref: this.dataProviderRef, persistentState: this.props.persistentState, loadStatus: this.props.loadStatus, hasFocus: this.state.isTextareaFocused, onFocusChange: (hasFocus: boolean) => this.setState({isTextareaFocused: hasFocus}), onLoadExperiment: this.props.onLoadExperiment, }; return ( {React.createElement(this.props.dataProvider, dataProviderProps)} {this.props.loadStatus == HiPlotLoadStatus.Loaded && !this.state.isTextareaFocused &&
{this.dataProviderRef.current && this.dataProviderRef.current.refresh && }
Selected: ?? /?? ( ??%)
}
); } render() { return (
{this.renderControls()}
{this.state.hasTutorial && this.setState({hasTutorial: false})).bind(this)}/>}
); } }; interface ErrorDisplayProps { error: string; } export class ErrorDisplay extends React.Component { render() { return (

{this.props.error}

HiPlot encountered the error above - more information might be available in your browser's developer web console, or in the server output

); } }