Skip to content

Save and restore table settings on vscode reload #64

Closed
@RandomFractals

Description

@RandomFractals

Use webview state to store and retrieve table columns and other table config settings.

See webview persistance docs: https://code.visualstudio.com/api/extension-guides/webview#persistence

Tabulator settings persistence in localStorage was added in #22.

This enhancement should enable restoring table columns configuraton for open table views between vscode restarts.

Pertinent code in tableView.js Tabulator config: https://github.com/RandomFractals/tabular-data-viewer/blob/main/web/scripts/tableView.js#L297

// add table setting save/restore handlers
    persistenceWriterFunc: (id, type, data) => saveTableSetting(id, type, data),
    persistenceReaderFunc: (id, type) => restoreTableSetting(id, type),

Update these table persistence handlers to use view state instead: https://github.com/RandomFractals/tabular-data-viewer/blob/main/web/scripts/tableView.js#L424

/**
 * Saves updated table setting/config for table view reload and restore later.
 * 
 * @param {*} id Table config persistence id.
 * @param {*} type Type of table setting to save: sort, filter, group, page or columns.
 * @param {*} data Array or object of data for the table options config save.
 */
function saveTableSetting(id, type, data) {
  // create table setting key
  const tableSettingKey = `${id}-${type}`;
  console.log(`tableView.saveTableSetting(): ${tableSettingKey}=`, data);

  // save table settings in local storage for now
  localStorage.setItem(tableSettingKey, JSON.stringify(data));
}

/**
 * Restores table setting on table view reload.
 * 
 * @param {*} id Table config persistence id.
 * @param {*} type Type of table setting to restore: sort, filter, group, page or columns.
 * @returns 
 */
function restoreTableSetting(id, type) {
  // create table setting key
  const tableSettingKey = `${id}-${type}`;

  // try to get requested table setting from local storage
  const tableSetting = localStorage.getItem(tableSettingKey);
  if (tableSetting) {
    console.log(`tableView.restoreTableSetting(): ${tableSettingKey}=`, tableSetting);
  }
  return tableSetting ? JSON.parse(tableSetting) : false;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions