{"size": 1500, "ext": "js", "max_stars_repo_path": "client/src/actions/table.test/utils.js", "max_stars_repo_name": "kengho/react-redux-spreadsheet", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/actions/table.test/utils.js", "max_issues_repo_name": "kengho/react-redux-spreadsheet", "max_issues_repo_issues_event_min_datetime": "2020-02-28T18:54:22.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-30T22:13:52.000Z", "max_forks_repo_path": "client/src/actions/table.test/utils.js", "max_forks_repo_name": "kengho/react-redux-spreadsheet", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 17, "max_forks_count": null, "avg_line_length": 30.612244898, "max_line_length": 98, "alphanum_fraction": 0.642}
import { convertTableToPlainArray } from '../../core';
import { ROW, COLUMN } from '../../constants';
import * as TableActions from '../table';

export const getRowsList = (store) => store.getState().table.present.major.layout[ROW].list;
export const getColumnsList = (store) => store.getState().table.present.major.layout[COLUMN].list;

export const setCellsValues = (store, cellsArray) => {
  // Example for cellsArray:
  // const cellsArray = [
  //   ['00', '' ],
  //   ['' , '11'],
  // ];

  store.dispatch(TableActions.insertLines({ lineType: ROW, index: cellsArray.length - 1 }));
  store.dispatch(TableActions.insertLines({ lineType: COLUMN, index: cellsArray[0].length - 1 }));
  cellsArray.forEach((row, rowIndex) => {
    row.forEach((value, columnIndex) => {
      store.dispatch(TableActions.setProp({
        [ROW]: {
          index: rowIndex,
        },
        [COLUMN]: {
          index: columnIndex,
        },
        prop: 'value',
        value,
      }));
    });
  });

  return store;
}

export const getPointer = (store) => store.getState().table.present.major.session.pointer;

export const getPointerPosition = (store) => {
  const pointer = getPointer(store);
  return {
    rowIndex: pointer[ROW].index,
    columnIndex: pointer[COLUMN].index,
  };
};

export const getSelection = (store) => store.getState().table.present.major.session.selection;

export const getCellsValues = (store) =>
  convertTableToPlainArray({ table: store.getState().table.present.major });
