{"size": 1824, "ext": "js", "max_stars_repo_path": "assets/js/mood_log/mood_events_table.js", "max_stars_repo_name": "jeffshek/betterself", "max_stars_repo_stars_event_min_datetime": "2017-07-29T14:26:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-28T04:10:15.000Z", "max_issues_repo_path": "assets/js/mood_log/mood_events_table.js", "max_issues_repo_name": "jeffshek/betterself", "max_issues_repo_issues_event_min_datetime": "2017-05-30T00:05:56.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T12:37:06.000Z", "max_forks_repo_path": "assets/js/mood_log/mood_events_table.js", "max_forks_repo_name": "lawrendran/betterself", "max_forks_repo_forks_event_min_datetime": "2017-11-08T00:02:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-28T04:10:32.000Z"}
{"max_stars_count": 98, "max_issues_count": 1483, "max_forks_count": 13, "avg_line_length": 25.6901408451, "max_line_length": 128, "alphanum_fraction": 0.59375}
import React from "react";
import { CubeLoadingStyle } from "../constants/loading_styles";
import { BaseLogTable } from "../resources_table/resource_table";
import { MoodHistoryRow, MoodHistoryTableHeader } from "./constants";
import { MOOD_RESOURCE_URL } from "../constants/urls";

export class MoodEntryLogTable extends BaseLogTable {
  constructor() {
    super();
    this.resourceURL = MOOD_RESOURCE_URL;
  }

  confirmDelete = (uuid, time, value, notes) => {
    const answer = confirm(
      `WARNING: This will delete the following Mood Log \n\nTime: ${time} \nMood Value: ${value} \nNotes: ${notes} \n\nConfirm?`
    );

    if (answer) {
      this.deleteUUID(uuid);
    }
  };

  getTableRender() {
    const historicalData = this.props.eventHistory;
    const historicalDataKeys = Object.keys(historicalData);

    return (
      <table className="table table-bordered table-striped table-condensed">
        <MoodHistoryTableHeader />
        <tbody>
          {historicalDataKeys.map(key => (
            <MoodHistoryRow
              key={key}
              object={historicalData[key]}
              confirmDelete={this.confirmDelete}
            />
          ))}
        </tbody>
      </table>
    );
  }

  renderReady() {
    if (!this.props.renderReady) {
      return <CubeLoadingStyle />;
    }

    return (
      <div className="card-block">
        <div className="float-right">
          {this.getNavPaginationControlRender()}
        </div>
        {this.getTableRender()}
        {this.getNavPaginationControlRender()}
      </div>
    );
  }

  render() {
    return (
      <div className="card">
        <div className="card-header">
          <i className="fa fa-align-justify" />
          <strong>Mood History</strong>
        </div>
        {this.renderReady()}
      </div>
    );
  }
}
