<commit_before>import React from "react";

import { Pipeline, Values } from "sajari-react/controllers";
import { Response, Results, Summary, Paginator } from "sajari-react/ui/results";
import AutocompleteDropdown from "sajari-react/ui/text/AutocompleteDropdown";

import "sajari-react/ui/text/AutocompleteInput.css";
import "sajari-react/ui/text/AutocompleteDropdown.css";
import "sajari-react/ui/results/Results.css";
import "sajari-react/ui/results/Paginator.css";

const project = "sajariptyltd";
const collection = "sajari-com";
const autocompletePipeline = new Pipeline(project, collection, "autocomplete");
const websitePipeline = new Pipeline(project, collection, "website");
const autocompleteValues = new Values();
const websiteValues = new Values();

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { autocomplete: true, instant: false };
  }

  update = query => {
    if (this.state.instant && !this.state.autocomplete) {
      websiteValues.set({ q: query, "q.override": undefined });
      if (query) {
        websitePipeline.search(websiteValues.get());
        return;
      }
      websitePipeline.clearResponse(websiteValues.get());
      return;
    }
  };

  submit = query => {
    if (query) {
      websiteValues.set({ q: query, "q.override": true });
      websitePipeline.search(websiteValues.get());
      return;
    }
    websitePipeline.clearResponse();
  };

  render() {
    const { autocomplete, instant } = this.state;

    const valuesForAutocomplete = instant ? websiteValues : autocompleteValues;
    const pipelineForAutocomplete = instant
      ? websitePipeline
      : autocompletePipeline;

    const suggestionAmount = autocomplete ? 5 : 0;
    const searchAutocomplete =
      (autocomplete || instant) && !(instant && !autocomplete);
    const showCompletion = instant;

    return (
      <div className="search-app">
        <label>
          Autocomplete
          <input
            type="checkbox"
            checked={autocomplete}
            onChange={() => this.setState({ autocomplete: !autocomplete })}
          />
        </label>
        <br />
        <label>
          Instant
          <input
            type="checkbox"
            checked={instant}
            onChange={() => this.setState({ instant: !instant })}
          />
        </label>
        <AutocompleteDropdown
          values={valuesForAutocomplete}
          pipeline={pipelineForAutocomplete}
          suggestionAmount={suggestionAmount}
          handleUpdate={this.update}
          handleForceSearch={this.submit}
          search={searchAutocomplete}
          showCompletion={showCompletion}
        />
        <Response pipeline={websitePipeline}>
          <Summary values={websiteValues} pipeline={websitePipeline} />
          <Results pipeline={websitePipeline} />
          <Paginator values={websiteValues} pipeline={websitePipeline} />
        </Response>
      </div>
    );
  }
}

export default App;
<commit_msg>examples: autocomplete-search simplify logic, use new prop names for AutocompleteDropdown<commit_after>import React from "react";

import { Pipeline, Values } from "sajari-react/controllers";
import { Response, Results, Summary, Paginator } from "sajari-react/ui/results";
import AutocompleteDropdown from "sajari-react/ui/text/AutocompleteDropdown";

import "sajari-react/ui/text/AutocompleteInput.css";
import "sajari-react/ui/text/AutocompleteDropdown.css";
import "sajari-react/ui/results/Results.css";
import "sajari-react/ui/results/Paginator.css";

const project = "sajariptyltd";
const collection = "sajari-com";
const websitePipeline = new Pipeline(project, collection, "website");
const websiteValues = new Values();

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { autocomplete: true };
  }

  submit = query => {
    if (query) {
      websiteValues.set({ q: query, "q.override": true });
      websitePipeline.search(websiteValues.get());
      return;
    }
    websitePipeline.clearResponse();
  };

  toggleAutocomplete = () => {
    this.setState({ autocomplete: !this.state.autocomplete });
  };

  render() {
    const { autocomplete } = this.state;
    return (
      <div className="search-app">
        <label>
          Autocomplete
          <input
            type="checkbox"
            checked={autocomplete}
            onChange={this.toggleAutocomplete}
          />
        </label>
        <AutocompleteDropdown
          values={websiteValues}
          pipeline={websitePipeline}
          numSuggestions={autocomplete ? 5 : 0}
          handleForceSearch={this.submit}
          autocompleteOnQueryChanged={true}
          showInlineCompletion={true}
        />
        <Response pipeline={websitePipeline}>
          <Summary values={websiteValues} pipeline={websitePipeline} />
          <Results pipeline={websitePipeline} />
          <Paginator values={websiteValues} pipeline={websitePipeline} />
        </Response>
      </div>
    );
  }
}

export default App;

{'fraction_non_alphanumeric': 0.1221585293536272, 'fraction_numerical': 0.000790670092903736, 'mean_word_length': 2.9224806201550386, 'pattern_counts': {'":': 3, '<': 29, '<?xml version=': 0, '>': 35, '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': '1674964', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1375, 'n_words': 285}