<commit_before>import { find, findIndex, isEmpty } from 'lodash'
import Vue from 'vue/dist/vue.js'

import './registration/appearance_panel'
import './registration/form_error_summary'
import './registration/form_field_error'
import './registration/piece_panel'
import { flattenChangesetValues } from '../utils/changesets'

const registrationForm = params => new Vue({
  el: '#registration-form',

  data() {
    const {
      changeset,
      contest_category_options,
      birthdate_year_options,
      birthdate_month_options,
      role_options,
      instrument_options,
      epoch_options,
      vocabulary,
    } = params

    const {
      contest_category_id,
      appearances,
      pieces,
    } = flattenChangesetValues(changeset)

    const errors = isEmpty(changeset.errors) ? {} : changeset.errors

    return {
      contest_category_id: contest_category_id || '',
      appearances: (appearances || []).map(normalizeAppearance),
      pieces: (pieces || []).map(normalizePiece),
      contest_category_options,
      birthdate_year_options,
      birthdate_month_options,
      role_options,
      instrument_options,
      epoch_options,
      vocabulary,
      errors,
      expandedAppearancePanelIndex: getExpandedAppearancePanelIndex(errors),
      expandedPiecePanelIndex: getExpandedPiecePanelIndex(errors),
    }
  },

  methods: {
    contestCategoryChanged() {
      const {
        appearances,
        contest_category_id: cc_id,
        contest_category_options: cc_options,
      } = this

      if (isEmpty(appearances)) {
        const cc = find(cc_options, o => o.id === cc_id)

        switch (cc.type) {
          case "solo":
            this.appearances.push(normalizeAppearance({role: 'soloist'}))
            this.appearances.push(normalizeAppearance({role: 'accompanist'}))
            break
          case "ensemble":
            this.appearances.push(normalizeAppearance({role: 'ensemblist'}))
            this.appearances.push(normalizeAppearance({role: 'ensemblist'}))
            break
        }
      }
    },
    addAppearance() {
      this.appearances.push(normalizeAppearance({}))
    },
    removeAppearance(index) {
      const { appearances, errors } = this
      appearances.splice(index, 1)
      errors.appearances && errors.appearances.splice(index, 1)
    },
    addPiece() {
      this.pieces.push(normalizePiece({}))
    },
    removePiece(index) {<commit_msg>Clean up code that populates appearance panels in registration form<commit_after>import { find, findIndex, isEmpty } from 'lodash'
import Vue from 'vue/dist/vue.js'

import './registration/appearance_panel'
import './registration/form_error_summary'
import './registration/form_field_error'
import './registration/piece_panel'
import { flattenChangesetValues } from '../utils/changesets'

const registrationForm = params => new Vue({
  el: '#registration-form',

  data() {
    const {
      changeset,
      contest_category_options,
      birthdate_year_options,
      birthdate_month_options,
      role_options,
      instrument_options,
      epoch_options,
      vocabulary,
    } = params

    const {
      contest_category_id,
      appearances,
      pieces,
    } = flattenChangesetValues(changeset)

    const errors = isEmpty(changeset.errors) ? {} : changeset.errors

    return {
      contest_category_id: contest_category_id || '',
      appearances: (appearances || []).map(normalizeAppearance),
      pieces: (pieces || []).map(normalizePiece),
      contest_category_options,
      birthdate_year_options,
      birthdate_month_options,
      role_options,
      instrument_options,
      epoch_options,
      vocabulary,
      errors,
      expandedAppearancePanelIndex: getExpandedAppearancePanelIndex(errors),
      expandedPiecePanelIndex: getExpandedPiecePanelIndex(errors),
    }
  },

  methods: {
    contestCategoryChanged() {
      const {
        appearances,
        contest_category_id: cc_id,
        contest_category_options: cc_options,
      } = this

      if (isEmpty(appearances)) {
        const cc = find(cc_options, o => o.id === cc_id)

        switch (cc.type) {
          case "solo":
            this.appearances = [
              normalizeAppearance({role: 'soloist'}),
              normalizeAppearance({role: 'accompanist'}),
            ]
            break
          case "ensemble":
            this.appearances = [
              normalizeAppearance({role: 'ensemblist'}),
              normalizeAppearance({role: 'ensemblist'}),
            ]
        }
      }
    },
    addAppearance() {
      this.appearances.push(normalizeAppearance({}))
    },
    removeAppearance(index) {
      const { appearances, errors } = this
      appearances.splice(index, 1)
      errors.appearances && errors.appearances.splice(index, 1)
    },
    addPiece() {
      this.pieces.push(normalizePiece({}))
    },
    removePiece(index) {
{'fraction_non_alphanumeric': 0.10866013071895425, 'fraction_numerical': 0.0008169934640522876, 'mean_word_length': 2.7467482785003825, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 7, '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': '2466427', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1469, 'n_words': 246}