Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Save and restore table settings on vscode reload #64

Closed
RandomFractals opened this issue Jan 10, 2022 · 0 comments
Closed

Save and restore table settings on vscode reload #64

RandomFractals opened this issue Jan 10, 2022 · 0 comments
Labels
feature release Release task

Comments

@RandomFractals
Copy link
Owner

RandomFractals commented Jan 10, 2022

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;
}
RandomFractals added a commit that referenced this issue Jan 10, 2022
@RandomFractals RandomFractals added the release Release task label Jan 10, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
feature release Release task
Projects
None yet
Development

No branches or pull requests

1 participant