<commit_before>/*
Settings and configuration for editing this file.
*/

import { Map } from "immutable";

import { React, Rendered, Component } from "../../app-framework";

import { is_different } from "smc-util/misc2";

// import from icon only necessary for testing via Jest
// Change to import from r_misc when it's all typescript
import { Icon } from "../../r_misc/icon";

import { SpellCheck } from "./spell-check";

import { Available as AvailableFeatures } from "../../project_configuration";

interface Props {
  id: string;
  actions: any;
  settings: Map<string, any>;
  available_features: AvailableFeatures;
}

export class Settings extends Component<Props, {}> {
  shouldComponentUpdate(props): boolean {
    return is_different(this.props, props, ["settings", "available_features"]);
  }

  render_settings(): Rendered[] {
    const v: Rendered[] = [];
    this.props.settings.forEach((value, key) => {
      switch (key) {
        case "spell":
          v.push(
            <SpellCheck
              key={key}
              value={value}
              available={this.props.available_features.spellcheck}
              set={value => this.props.actions.set_settings({ [key]: value })}
            />
          );
          return;
        default:
          console.warn(`UNKNOWN setting ${key} -- ignoring`);
        // we could delete it like so -- this.props.actions.set_settings({[key]:null});
      }<commit_msg>webapp/editor: available features could be undefined<commit_after>/*
Settings and configuration for editing this file.
*/

import { Map } from "immutable";

import { React, Rendered, Component } from "../../app-framework";

import { is_different } from "smc-util/misc2";

// import from icon only necessary for testing via Jest
// Change to import from r_misc when it's all typescript
import { Icon } from "../../r_misc/icon";
import { Loading } from "../../r_misc/loading";

import { SpellCheck } from "./spell-check";

import { Available as AvailableFeatures } from "../../project_configuration";

interface Props {
  id: string;
  actions: any;
  settings: Map<string, any>;
  available_features?: AvailableFeatures;
}

export class Settings extends Component<Props, {}> {
  shouldComponentUpdate(props): boolean {
    return is_different(this.props, props, ["settings", "available_features"]);
  }

  render_settings(): Rendered[] {
    const af = this.props.available_features;
    if (af == null) {
      return [<Loading key={"loading"} />];
    }
    const v: Rendered[] = [];
    this.props.settings.forEach((value, key) => {
      switch (key) {
        case "spell":
          v.push(
            <SpellCheck
              key={key}
              value={value}
              available={af.spellcheck}
              set={value => this.props.actions.set_settings({ [key]: value })}
            />
          );
          return;
        default:
          console.warn(`UNKNOWN setting ${key} -- ignoring`);
        // we could delete it like so -- this.props.actions.set_settings({[key]:null});
      }
{'fraction_non_alphanumeric': 0.14196516595465003, 'fraction_numerical': 0.0006572461386789353, 'mean_word_length': 2.6630565583634174, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4733027', 'n_tokens_mistral': 853, 'n_tokens_neox': 849, 'n_words': 238}