<commit_before>// @flow

import React from "react";
import Button from "react-bootstrap/Button";
import { ReactSortable } from "react-sortablejs";

import ConfirmationModal from "../common/confirmation/ConfirmationModal.jsx";
import { PositionInfo } from "./PositionInfo.jsx";
import PositionEntryModal from "./PositionEntryModal.jsx";
import { GlyphStyles } from "../utils/glyphs.js";
import PositionListEntry from "./PositionListEntry.jsx";
import promiseHelper from "../utils/promise.js";
import _ from "lodash";

export type NewPositionInfo = PositionInfo & {| tempId: ?number |};

type Props = {|
  positions: $ReadOnlyArray<PositionInfo>,
  elementid: string,
|};
type State = {|
  showAddEditModal: boolean,
  showDeleteModal: boolean,
  showHideModal: boolean,
  existingPosition: ?NewPositionInfo,
  selectedPosition: ?NewPositionInfo,
  positionToActUpon: ?NewPositionInfo,
  positions: Array<NewPositionInfo>,
|};

type OnChooseEvent = Event & {| oldIndex: number |};

/**
 * Lists project positions and provides add/edit functionality for them
 */
class PositionList extends React.PureComponent<Props, State> {
  constructor(props: Props): void {
    super(props);
    this.state = {
      positions: this.props.positions || [],
      selectedPosition: null,
      showAddEditModal: false,
      showDeleteModal: false,
      showHideModal: false,
      existingPosition: null,
      positionToActUpon: null,
    };
  }

  componentWillReceiveProps(nextProps: Props): void {
    if (nextProps.positions !== this.state.positions) {
      this.setState({ positions: nextProps.positions || [] });
      this.updatePositionsField();
    }
  }

  savePositionOrdering(positions: $ReadOnlyArray<NewPositionInfo>): void {
    for (let i = 0; i < positions.length; ++i) {
      positions[i].orderNumber = i;
    }
    this.setState(
      { positions: positions, selectedPosition: this.state.selectedPosition },
      this.updatePositionsField
    );
  }

  createNewPosition(): void {
    this.openModal(null);
  }

  onModalCancel(): void {
    this.setState({ showAddEditModal: false });
  }<commit_msg>Create Project: Fix issue where old position list flashes on screen after clicking Next<commit_after>// @flow

import React from "react";
import Button from "react-bootstrap/Button";
import { ReactSortable } from "react-sortablejs";

import ConfirmationModal from "../common/confirmation/ConfirmationModal.jsx";
import { PositionInfo } from "./PositionInfo.jsx";
import PositionEntryModal from "./PositionEntryModal.jsx";
import { GlyphStyles } from "../utils/glyphs.js";
import PositionListEntry from "./PositionListEntry.jsx";
import promiseHelper from "../utils/promise.js";
import _ from "lodash";

export type NewPositionInfo = PositionInfo & {| tempId: ?number |};

type Props = {|
  positions: $ReadOnlyArray<PositionInfo>,
  elementid: string,
|};
type State = {|
  positionsInitialized: boolean,
  showAddEditModal: boolean,
  showDeleteModal: boolean,
  showHideModal: boolean,
  existingPosition: ?NewPositionInfo,
  selectedPosition: ?NewPositionInfo,
  positionToActUpon: ?NewPositionInfo,
  positions: Array<NewPositionInfo>,
|};

type OnChooseEvent = Event & {| oldIndex: number |};

/**
 * Lists project positions and provides add/edit functionality for them
 */
class PositionList extends React.PureComponent<Props, State> {
  constructor(props: Props): void {
    super(props);
    const positions: $ReadOnlyArray<NewPositionInfo> =
      this.props.positions || [];
    this.state = {
      positions: positions,
      positionsInitialized: !_.isEmpty(positions),
      selectedPosition: null,
      showAddEditModal: false,
      showDeleteModal: false,
      showHideModal: false,
      existingPosition: null,
      positionToActUpon: null,
    };
  }

  componentWillReceiveProps(nextProps: Props): void {
    if (
      !this.state.positionsInitialized &&
      nextProps.positions !== this.state.positions
    ) {
      this.setState({
        positions: nextProps.positions || [],
        positionsInitialized: !_.isEmpty(positions),
      });
      this.updatePositionsField();
    }
  }

  savePositionOrdering(positions: $ReadOnlyArray<NewPositionInfo>): void {
    for (let i = 0; i < positions.length; ++i) {
      positions[i].orderNumber = i;
    }
    this.setState(
      { positions: positions, selectedPosition: this.state.selectedPosition },
      this.updatePositionsField
    );
  }

  createNewPosition(): void {
    this.openModal(null);
  }

  onModalCancel(): void {
    this.setState({ showAddEditModal: false });
  }
{'fraction_non_alphanumeric': 0.1205161854768154, 'fraction_numerical': 0.0004374453193350831, 'mean_word_length': 3.9869138495092695, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 12, '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': '513135', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1307, 'n_words': 310}