// jshint esversion: 6 import React from "react"; import _ from "lodash"; import { Button, Tooltip, InputGroup, Dialog, Classes, MenuItem } from "@blueprintjs/core"; import { Select } from "@blueprintjs/select"; import { connect } from "react-redux"; import * as globals from "../../globals"; import Category from "./category"; @connect(state => ({ categoricalSelection: state.categoricalSelection, writableCategoriesEnabled: state.config?.parameters?.["label_file"] ?? false, schema: state.world?.schema })) class Categories extends React.Component { constructor(props) { super(props); this.state = { createAnnoModeActive: false, newCategoryText: "", categoryToDuplicate: null }; } handleCreateUserAnno = () => { const { dispatch } = this.props; const { newCategoryText, categoryToDuplicate } = this.state; dispatch({ type: "annotation: create category", data: newCategoryText, categoryToDuplicate }); this.setState({ createAnnoModeActive: false, categoryToDuplicate: null, newCategoryText: "" }); }; handleEnableAnnoMode = () => { this.setState({ createAnnoModeActive: true }); }; handleDisableAnnoMode = () => { this.setState({ createAnnoModeActive: false }); }; handleModalDuplicateCategorySelection = d => { this.setState({ categoryToDuplicate: d }); }; render() { const { createAnnoModeActive, categoryToDuplicate } = this.state; const { categoricalSelection, writableCategoriesEnabled, schema } = this.props; if (!categoricalSelection) return null; /* all names, sorted in display order. Will be rendered in this order */ const allCategoryNames = Object.keys(categoricalSelection).sort(); return (