<commit_before>import * as React from 'react'
import * as classNames from 'classnames'
import { BaseModel } from '../utils/manager'
import produce from 'immer'
import './table.css'

interface Column<T> {
  key: string
  title: string
  format: (t: T, i: number) => React.ReactNode
  compare?: (a: T, b: T) => number
}

interface TableProps<T> {
  name?: string | number
  title?: string
  subtitle?: React.ReactNode
  rows: T[]
  columns: Column<T>[]
}

interface TableState {
  sortKey?: string
  sortAsc?: boolean
}

class Table<T extends BaseModel> extends React.Component<TableProps<T>, TableState> {

  state: TableState = JSON.parse(localStorage.getItem(`table-state-${this.props.name}`) || '{}')

  sortColumn = (column: Column<T>) => {
    const next = produce(this.state, draftState => {
      if (this.state.sortKey === column.key) {
        draftState.sortAsc = this.state.sortAsc !== true
      } else {
        draftState.sortAsc = true
        draftState.sortKey = column.key
      }
    })
    localStorage.setItem(`table-state-${this.props.name}`, JSON.stringify(next))
    this.setState(next)
  }

  render() {
    const {title, subtitle, rows, columns} = this.props

    const finalRows = produce(rows, draftState => {
      if (this.state.sortKey) {
        const findColumn = this.props.columns.find(c => c.key === this.state.sortKey)
        if (findColumn) {
          draftState.sort(findColumn.compare)
        }
        if (this.state.sortAsc === false) {
          draftState.reverse()
        }
      }
    })

    return (<commit_msg>feat(table): Change Local to Session<commit_after>import * as React from 'react'
import * as classNames from 'classnames'
import { BaseModel } from '../utils/manager'
import produce from 'immer'
import './table.css'

interface Column<T> {
  key: string
  title: string
  format: (t: T, i: number) => React.ReactNode
  compare?: (a: T, b: T) => number
}

interface TableProps<T> {
  name?: string | number
  title?: string
  subtitle?: React.ReactNode
  rows: T[]
  columns: Column<T>[]
}

interface TableState {
  sortKey?: string
  sortAsc?: boolean
}

class Table<T extends BaseModel> extends React.Component<TableProps<T>, TableState> {

  state: TableState = JSON.parse(sessionStorage.getItem(`table-state-${this.props.name}`) || '{}')

  sortColumn = (column: Column<T>) => {
    const next = produce(this.state, draftState => {
      if (this.state.sortKey === column.key) {
        draftState.sortAsc = this.state.sortAsc !== true
      } else {
        draftState.sortAsc = true
        draftState.sortKey = column.key
      }
    })
    sessionStorage.setItem(`table-state-${this.props.name}`, JSON.stringify(next))
    this.setState(next)
  }

  render() {
    const {title, subtitle, rows, columns} = this.props

    const finalRows = produce(rows, draftState => {
      if (this.state.sortKey) {
        const findColumn = this.props.columns.find(c => c.key === this.state.sortKey)
        if (findColumn) {
          draftState.sort(findColumn.compare)
        }
        if (this.state.sortAsc === false) {
          draftState.reverse()
        }
      }
    })

    return (
{'fraction_non_alphanumeric': 0.14503332275468106, 'fraction_numerical': 0.0, 'mean_word_length': 2.9548306148055206, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, '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': '5748693', 'n_tokens_mistral': 1008, 'n_tokens_neox': 994, 'n_words': 232}