<commit_before>const db = require('./clients/postgrest')
const pick = require('lodash/pick')
const mapValues = require('lodash/mapValues')

module.exports = function store (state, emitter) {
  state.store = {
    sheets: [],
    activeSheet: {
      fields: null,
      rows: null,
      name: null
    }
  }

  emitter.on('pushState', function (location) {
    const sheet = location.split('/').pop()
    emitter.emit('store:selectSheet', sheet)
  })

  emitter.on('store:getList', async function () {
    try {
      state.store.sheets = await db.getTables()
      const activeSheetName = getActiveSheet()
      emitter.emit('store:selectSheet', activeSheetName)
    } catch (err) {
      console.error(err)
      emitter.emit('ui:notify', { msg: 'Error fetching list of sheets' })
    }
  })

  emitter.on('store:selectSheet', async function (table) {
    try {
      const fields = await db.getSchema(table)
      const fieldsWithEditable = fields.map(addEditable)<commit_msg>if no sheets, dont try to select one. fixes #53<commit_after>const db = require('./clients/postgrest')
const pick = require('lodash/pick')
const mapValues = require('lodash/mapValues')

module.exports = function store (state, emitter) {
  state.store = {
    sheets: [],
    activeSheet: {
      fields: null,
      rows: null,
      name: null
    }
  }

  emitter.on('pushState', function (location) {
    const sheet = location.split('/').pop()
    emitter.emit('store:selectSheet', sheet)
  })

  emitter.on('store:getList', async function () {
    try {
      state.store.sheets = await db.getTables()
      const activeSheetName = getActiveSheet()
      if (activeSheetName) emitter.emit('store:selectSheet', activeSheetName)
    } catch (err) {
      console.error(err)
      emitter.emit('ui:notify', { msg: 'Error fetching list of sheets' })
    }
  })

  emitter.on('store:selectSheet', async function (table) {
    try {
      const fields = await db.getSchema(table)
      const fieldsWithEditable = fields.map(addEditable)
{'fraction_non_alphanumeric': 0.13945409429280398, 'fraction_numerical': 0.0009925558312655087, 'mean_word_length': 3.2802547770700636, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2315473', 'n_tokens_mistral': 635, 'n_tokens_neox': 609, 'n_words': 140}