diff --git a/ember-headless-table/src/-private/interfaces/preferences.ts b/ember-headless-table/src/-private/interfaces/preferences.ts index 062304ce..a402f07d 100644 --- a/ember-headless-table/src/-private/interfaces/preferences.ts +++ b/ember-headless-table/src/-private/interfaces/preferences.ts @@ -10,10 +10,6 @@ export interface PreferencesAdapter { * This could allow for saving the data off to an API or local storage. */ export interface TablePreferencesData { - /** - * @deprecated columns have no configuration outside of what is provided by plugins - */ - columns?: Record; /** * Every plugin has its own namespace for preferences storage. * @@ -83,21 +79,3 @@ export interface PluginPreferences { [columnKey: string]: Record; }; } - -/** - * @deprecated columns have no configuration outside of what is provided by plugins - */ -export interface ColumnPreferences { - /** - * @deprecated columns have no configuration outside of what is provided by plugins - */ - isVisible?: boolean; - /** - * @deprecated columns have no configuration outside of what is provided by plugins - */ - width?: number; - /** - * @deprecated columns have no configuration outside of what is provided by plugins - */ - position?: number; -} diff --git a/ember-headless-table/src/-private/preferences.ts b/ember-headless-table/src/-private/preferences.ts index 9eb2c7a3..1062cdcd 100644 --- a/ember-headless-table/src/-private/preferences.ts +++ b/ember-headless-table/src/-private/preferences.ts @@ -1,7 +1,6 @@ import { TrackedMap } from 'tracked-built-ins'; import type { - ColumnPreferences, PluginPreferenceFor, PluginPreferences, PreferencesAdapter as Adapter, @@ -12,11 +11,6 @@ import type { export class TablePreferences { storage = new TrackedPreferences(); - /** - * @deprecated - preferences must be plugin-based - */ - columnPreferences = new TrackedMap(); - constructor(private key: string, private adapter?: Adapter) { if (this.adapter) { this.restore(this.adapter); @@ -27,88 +21,10 @@ export class TablePreferences { return this.adapter !== undefined; } - /** - * @deprecated - preferences must be plugin-based - */ - deleteColumnPreference(columnKey: string, key: K) { - let preferences = this.getColumnPreferences(columnKey); - - if (!(key in preferences)) { - return false; - } - - let newPreferences = { ...this.getColumnPreferences(columnKey) }; - - delete newPreferences[key]; - - if (Object.keys(newPreferences).length === 0) { - this.columnPreferences.delete(columnKey); - } else { - this.columnPreferences.set(columnKey, newPreferences); - } - - this.persist(); - - return true; - } - - /** - * @deprecated - preferences must be plugin-based - */ - getColumnPreferences(columnKey: string): ColumnPreferences { - return this.columnPreferences.get(columnKey) ?? {}; - } - getIsAtDefault() { return this.storage.isAtDefault; } - /** - * @deprecated - preferences must be plugin-based - */ - setColumnPreferences(columnKey: string, value: ColumnPreferences) { - this.columnPreferences.set(columnKey, value); - this.persist(); - } - - /** - * @deprecated - preferences must be plugin-based - */ - setColumnPreference( - columnKey: string, - key: K, - value: ColumnPreferences[K] - ) { - let preferences = this.getColumnPreferences(columnKey); - let newValue = { ...preferences, [key]: value }; - - this.columnPreferences.set(columnKey, newValue); - - this.persist(); - } - - /** - * @deprecated - preferences must be plugin-based - * use storage.serialize() instead - */ - toTablePreferencesData() { - let data: TablePreferencesData = {}; - - let columns: Record = {}; - - for (let [key, preferences] of this.columnPreferences) { - if (Object.keys(preferences).length > 0) { - columns[key] = preferences; - } - } - - if (Object.keys(columns).length > 0) { - data.columns = columns; - } - - return data; - } - /** * Passes a JSON-compatible structure to `adapter.persist` * @@ -118,7 +34,6 @@ export class TablePreferences { */ persist() { return this.adapter?.persist?.(this.key, { - ...this.toTablePreferencesData(), ...this.storage.serialize(), }); } @@ -132,10 +47,6 @@ export class TablePreferences { if (!data) return; - for (let [key, preferences] of Object.entries(data.columns ?? {})) { - this.columnPreferences.set(key, preferences); - } - return this.storage.restore(data); } } diff --git a/ember-headless-table/src/-private/table.ts b/ember-headless-table/src/-private/table.ts index 263c3da7..639bf113 100644 --- a/ember-headless-table/src/-private/table.ts +++ b/ember-headless-table/src/-private/table.ts @@ -16,7 +16,7 @@ import { composeFunctionModifiers } from './utils'; import type { Plugin } from '../plugins'; import type { Class } from '[private-types]'; -import type { ColumnKey, ColumnPreferences, Destructor, TableConfig } from '#interfaces'; +import type { Destructor, TableConfig } from '#interfaces'; const DEFAULT_COLUMN_CONFIG = { isVisible: true, @@ -342,16 +342,6 @@ export class Table extends Resource> { this.#page = this.pagination?.page; } - /** - * @deprecated - */ - getColumnPreference( - columnKey: ColumnKey, - key: K - ): ColumnPreferences[K] { - return this.preferences.getColumnPreferences(columnKey)[key]; - } - /** * @private */ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 05b5cd2d..acc2bde7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -346,10 +346,10 @@ importers: '@embroider/test-setup': ^1.7.1 '@glimmer/component': ^1.1.2 '@glimmer/tracking': ^1.1.2 - '@glint/core': ^0.9.4 - '@glint/environment-ember-loose': ^0.9.4 - '@glint/environment-ember-template-imports': ^0.9.4 - '@glint/template': ^0.9.4 + '@glint/core': ^0.9.5 + '@glint/environment-ember-loose': ^0.9.5 + '@glint/environment-ember-template-imports': ^0.9.5 + '@glint/template': ^0.9.5 '@nullvoxpopuli/eslint-configs': ^2.2.57 '@tsconfig/ember': ^1.0.1 '@types/ember': ^4.0.1 @@ -421,18 +421,18 @@ importers: ember-auto-import: 2.4.2_webpack@5.74.0 ember-cached-decorator-polyfill: 1.0.1_ptmptcjlczeu7fwi6i5ecogy5u ember-functions-as-helper-polyfill: 2.1.1_ember-source@3.28.9 - ember-headless-table: file:ember-headless-table_hxuenzbkgezuh6qyaygw72kt34 - ember-resources: 5.4.0_4ec4fcuatet4y5vxzy4njwllwy + ember-headless-table: file:ember-headless-table_gea6srzlnkl2qogbcjlul4uqmi + ember-resources: 5.4.0_itjoionlcsu5pi6ambocxkrlcq devDependencies: '@babel/core': 7.19.3 '@ember/optional-features': 2.0.0 '@embroider/test-setup': 1.8.3 '@glimmer/component': 1.1.2_@babel+core@7.19.3 '@glimmer/tracking': 1.1.2 - '@glint/core': 0.9.4_typescript@4.8.4 - '@glint/environment-ember-loose': 0.9.4_t5ycb63yys2yccfcq5mlxlwezm - '@glint/environment-ember-template-imports': 0.9.4_iyj4dyv5mvlfaurk3za62xqgme - '@glint/template': 0.9.4_@glimmer+component@1.1.2 + '@glint/core': 0.9.5_typescript@4.8.4 + '@glint/environment-ember-loose': 0.9.5_t5ycb63yys2yccfcq5mlxlwezm + '@glint/environment-ember-template-imports': 0.9.5_lnwxnliv3x7lc2w3tdyyvqhmga + '@glint/template': 0.9.5_@glimmer+component@1.1.2 '@nullvoxpopuli/eslint-configs': 2.2.59_typescript@4.8.4 '@tsconfig/ember': 1.0.1 '@types/ember': 4.0.1_@babel+core@7.19.3 @@ -2518,6 +2518,17 @@ packages: - supports-color dev: true + /@glint/config/0.9.5: + resolution: {integrity: sha512-n57V4EgEG2SGqd71CBh4NMjgWuiyM1zzM7sDmXsZ9mAvP38RRBOKjRNBfyWh8/FHX5AAPE7QD2o5GdprafRXFw==} + dependencies: + escape-string-regexp: 4.0.0 + minimatch: 3.1.2 + resolve: 1.22.1 + silent-error: 1.1.1 + transitivePeerDependencies: + - supports-color + dev: true + /@glint/core/0.9.4_typescript@4.8.4: resolution: {integrity: sha512-7n7nUV/kbRQ6y5AhWyO2NO1J79/h3zaBn2BJ1NXaguUvQY70/YvM15CeA4JfsrFjR8Yr2Y175QfP0Ug4MSD89Q==} hasBin: true @@ -2537,6 +2548,25 @@ packages: - supports-color dev: true + /@glint/core/0.9.5_typescript@4.8.4: + resolution: {integrity: sha512-U7Fgkc2wtEXxmL6o6SgxlhUB9daFAGko7of2GisvkqKYxfPw3ximFu12ZK9aEaWEpn23p2Wrc5AAgvW1zBxUfA==} + hasBin: true + peerDependencies: + typescript: ^4.7.0 + dependencies: + '@glint/config': 0.9.5 + '@glint/transform': 0.9.5 + resolve: 1.22.1 + typescript: 4.8.4 + uuid: 8.3.2 + vscode-languageserver: 8.0.2 + vscode-languageserver-textdocument: 1.0.7 + vscode-uri: 3.0.6 + yargs: 17.6.0 + transitivePeerDependencies: + - supports-color + dev: true + /@glint/environment-ember-loose/0.9.4_q3dyqagzoarn5fdnpc2fuow56q: resolution: {integrity: sha512-70S8BwpfoOuoGRUvmsIF1be5vmYhzVzSnXRraa0UG6ZJm4WyrP1OqJEdl5sXTsKLsF/Gp8Fb5hc3dibP4GluNw==} peerDependencies: @@ -2558,8 +2588,8 @@ packages: - supports-color dev: true - /@glint/environment-ember-loose/0.9.4_t5ycb63yys2yccfcq5mlxlwezm: - resolution: {integrity: sha512-70S8BwpfoOuoGRUvmsIF1be5vmYhzVzSnXRraa0UG6ZJm4WyrP1OqJEdl5sXTsKLsF/Gp8Fb5hc3dibP4GluNw==} + /@glint/environment-ember-loose/0.9.5_t5ycb63yys2yccfcq5mlxlwezm: + resolution: {integrity: sha512-dQX8nmDNVCAfYMSRzCaXEXFaJL4Woib1cCeziX0dPvacG4ASC2VoUR32kh4/km7UokGsHQylb40vQzWNir6NSQ==} peerDependencies: '@glimmer/component': ^1.1.2 ember-cli-htmlbars: ^6.0.1 @@ -2571,8 +2601,8 @@ packages: optional: true dependencies: '@glimmer/component': 1.1.2_@babel+core@7.19.3 - '@glint/config': 0.9.4 - '@glint/template': 0.9.4_@glimmer+component@1.1.2 + '@glint/config': 0.9.5 + '@glint/template': 0.9.5_@glimmer+component@1.1.2 ember-cli-htmlbars: 6.1.1 transitivePeerDependencies: - supports-color @@ -2591,14 +2621,14 @@ packages: - '@glimmer/component' dev: true - /@glint/environment-ember-template-imports/0.9.4_iyj4dyv5mvlfaurk3za62xqgme: - resolution: {integrity: sha512-LRkBgzyT8VThfM9vJqauSKJIyHeNavfsWoiIIl6/cbzuThACQGQWSp5sOyCifTJiMMMs34Z9p8LKaAFSX0MQ+Q==} + /@glint/environment-ember-template-imports/0.9.5_lnwxnliv3x7lc2w3tdyyvqhmga: + resolution: {integrity: sha512-QBcNlfMaVTg+rGTCWPDroVFOhtcNVfEhQikeH1izP9kUYfakSRF/vJVIpRjgINyvlQc0z1r9kdiqIVKPaWL8rQ==} peerDependencies: - '@glint/environment-ember-loose': ^0.9.4 + '@glint/environment-ember-loose': ^0.9.5 ember-template-imports: ^3.0.0 dependencies: - '@glint/environment-ember-loose': 0.9.4_t5ycb63yys2yccfcq5mlxlwezm - '@glint/template': 0.9.4_@glimmer+component@1.1.2 + '@glint/environment-ember-loose': 0.9.5_t5ycb63yys2yccfcq5mlxlwezm + '@glint/template': 0.9.5_@glimmer+component@1.1.2 ember-template-imports: 3.1.1_ember-cli-htmlbars@6.1.1 transitivePeerDependencies: - '@glimmer/component' @@ -2611,6 +2641,13 @@ packages: dependencies: '@glimmer/component': 1.1.2_@babel+core@7.19.3 + /@glint/template/0.9.5_@glimmer+component@1.1.2: + resolution: {integrity: sha512-Snaw+U/BLqJl39JnWI0TNWo8CiyTvTn7PA+onBM/jXcl8NMIP+H6WNNdTyue0mBkYIrnW7oBaXsrrLKMg9ddNQ==} + peerDependencies: + '@glimmer/component': ^1.1.2 + dependencies: + '@glimmer/component': 1.1.2_@babel+core@7.19.3 + /@glint/transform/0.9.4: resolution: {integrity: sha512-RgK+Rm2fs+djH5jur5KGTcOTWMoPMJx1GB/6ksIXBDq8jA4l4V0ZKZR/GQ5B2NBlfzf7UqWPRb0LNff7grAVHg==} dependencies: @@ -2620,6 +2657,15 @@ packages: - supports-color dev: true + /@glint/transform/0.9.5: + resolution: {integrity: sha512-AHtXqQE16zV6VDDcC0ntYptitRVKe3hZveUqsKGGli+uOLIc0Ni/AhahaWgig/GwNXzGZy0qj3GU+hKvXSU8ng==} + dependencies: + '@glimmer/syntax': 0.84.2 + '@glint/config': 0.9.5 + transitivePeerDependencies: + - supports-color + dev: true + /@handlebars/parser/2.0.0: resolution: {integrity: sha512-EP9uEDZv/L5Qh9IWuMUGJRfwhXJ4h1dqKTT4/3+tY0eu7sPis7xh23j61SYUnNF4vqCQvvUXpDo9Bh/+q1zASA==} dev: true @@ -7746,7 +7792,7 @@ packages: - supports-color dev: true - /ember-resources/5.4.0_4ec4fcuatet4y5vxzy4njwllwy: + /ember-resources/5.4.0_gv6j52yonbqt3c433e2sdxgmyu: resolution: {integrity: sha512-6rgzmLOzpRaFELhrC2uSd+6ZdkFu/1b5dv+W5ZDSjySm7yffKelj4tnXCq4BP9PeGZDfM7Zo7xH12y/cu/qvRg==} peerDependencies: '@ember/test-waiters': ^3.0.0 @@ -7770,12 +7816,12 @@ packages: '@glimmer/component': 1.1.2_@babel+core@7.19.3 '@glimmer/tracking': 1.1.2 '@glint/template': 0.9.4_@glimmer+component@1.1.2 - ember-source: 3.28.9_@babel+core@7.19.3 + ember-source: 4.7.0_@babel+core@7.19.3 transitivePeerDependencies: - supports-color dev: false - /ember-resources/5.4.0_gv6j52yonbqt3c433e2sdxgmyu: + /ember-resources/5.4.0_itjoionlcsu5pi6ambocxkrlcq: resolution: {integrity: sha512-6rgzmLOzpRaFELhrC2uSd+6ZdkFu/1b5dv+W5ZDSjySm7yffKelj4tnXCq4BP9PeGZDfM7Zo7xH12y/cu/qvRg==} peerDependencies: '@ember/test-waiters': ^3.0.0 @@ -7798,8 +7844,8 @@ packages: '@embroider/macros': 1.8.3 '@glimmer/component': 1.1.2_@babel+core@7.19.3 '@glimmer/tracking': 1.1.2 - '@glint/template': 0.9.4_@glimmer+component@1.1.2 - ember-source: 4.7.0_@babel+core@7.19.3 + '@glint/template': 0.9.5_@glimmer+component@1.1.2 + ember-source: 3.28.9_@babel+core@7.19.3 transitivePeerDependencies: - supports-color dev: false @@ -15887,7 +15933,7 @@ packages: /zwitch/1.0.5: resolution: {integrity: sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==} - file:ember-headless-table_hxuenzbkgezuh6qyaygw72kt34: + file:ember-headless-table_gea6srzlnkl2qogbcjlul4uqmi: resolution: {directory: ember-headless-table, type: directory} id: file:ember-headless-table name: ember-headless-table @@ -15911,10 +15957,10 @@ packages: '@ember/test-waiters': 3.0.2 '@embroider/addon-shim': 1.8.3 '@glimmer/component': 1.1.2_@babel+core@7.19.3 - '@glint/template': 0.9.4_@glimmer+component@1.1.2 + '@glint/template': 0.9.5_@glimmer+component@1.1.2 ember-cached-decorator-polyfill: 1.0.1_ptmptcjlczeu7fwi6i5ecogy5u ember-modifier: 3.2.7_@babel+core@7.19.3 - ember-resources: 5.4.0_4ec4fcuatet4y5vxzy4njwllwy + ember-resources: 5.4.0_itjoionlcsu5pi6ambocxkrlcq ember-source: 3.28.9_@babel+core@7.19.3 ember-tracked-storage-polyfill: 1.0.0 tracked-built-ins: 3.1.0 diff --git a/test-app/package.json b/test-app/package.json index 5036ac2b..e2cfca54 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -44,10 +44,10 @@ "@embroider/test-setup": "^1.7.1", "@glimmer/component": "^1.1.2", "@glimmer/tracking": "^1.1.2", - "@glint/core": "^0.9.4", - "@glint/environment-ember-loose": "^0.9.4", - "@glint/environment-ember-template-imports": "^0.9.4", - "@glint/template": "^0.9.4", + "@glint/core": "^0.9.5", + "@glint/environment-ember-loose": "^0.9.5", + "@glint/environment-ember-template-imports": "^0.9.5", + "@glint/template": "^0.9.5", "@nullvoxpopuli/eslint-configs": "^2.2.57", "@tsconfig/ember": "^1.0.1", "@types/ember": "^4.0.1", diff --git a/test-app/tests/unit/preferences-test.ts b/test-app/tests/unit/preferences-test.ts index ce4ab4ea..307e1c27 100644 --- a/test-app/tests/unit/preferences-test.ts +++ b/test-app/tests/unit/preferences-test.ts @@ -12,451 +12,233 @@ import type { PreferencesData } from 'ember-headless-table'; module('Unit | -private | table-preferences', function (hooks) { setupTest(hooks); - module('deprecated APIs', function () { - test('#columnPreferences: is empty by default', async function (assert) { - assert.strictEqual(new TablePreferences('preferences-key').columnPreferences.size, 0); - }); - - test('#getColumnPreferences: returns preferences for a column by key', async function (assert) { - let preferences = new TablePreferences('preferences-key'); - - preferences.setColumnPreferences('foo', { isVisible: true }); - preferences.setColumnPreferences('bar', { isVisible: false }); - - assert.deepEqual(preferences.getColumnPreferences('foo'), { isVisible: true }); - assert.deepEqual(preferences.getColumnPreferences('bar'), { isVisible: false }); - }); - - test('#getColumnPreferences: returns {} when column does not have any preferences', async function (assert) { - let preferences = new TablePreferences('preferences-key'); - - preferences.setColumnPreferences('foo', { isVisible: true }); - preferences.setColumnPreferences('bar', { isVisible: false }); - - assert.deepEqual(preferences.getColumnPreferences('baz'), {}); - }); - - test('#setColumnPreferences: sets preferences for a column', async function (assert) { - let preferences = new TablePreferences('preferences-key'); + module('#restore', function () { + test('@adapter#restore(): returns initial data for table preferences', async function (assert) { + assert.expect(1); - preferences.setColumnPreferences('foo', { isVisible: true }); + let preferences = new TablePreferences('preferences-key', { + // Deliberately testing incorrect type + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + restore: () => ({ + columns: { + foo: { isVisible: true }, + bar: { isVisible: false }, + }, + }), + persist: (_key, data) => { + assert.deepEqual(data, { + plugins: {}, + }); + }, + }); - assert.deepEqual(preferences.getColumnPreferences('foo'), { isVisible: true }); + preferences.persist(); }); + }); - test('#setColumnPreferences: replaces existing preferences for a column', async function (assert) { - let preferences = new TablePreferences('preferences-key'); - - preferences.setColumnPreferences('foo', { isVisible: false }); + module('#restore and #persist are inverses', function () { + test('with plugin data', async function (assert) { + assert.expect(2); + + let data: PreferencesData = { + plugins: { + 'column-visibility': { + table: { + foo: 2, + }, + columns: { + foo: { isVilable: true }, + bar: { isVilable: true }, + }, + }, + }, + }; - preferences.setColumnPreferences('foo', { isVisible: true }); + let preferences = new TablePreferences('preferences-key', { + restore: () => data, + persist: (key, toPersist) => { + assert.strictEqual(key, 'preferences-key'); + assert.deepEqual(toPersist, data); + }, + }); - assert.deepEqual(preferences.getColumnPreferences('foo'), { isVisible: true }); + preferences.persist(); }); - test('#setColumnPreference: sets a single preference for a column', async function (assert) { - let preferences = new TablePreferences('preferences-key'); + test('unexpected keys are omitted from persist', async function (assert) { + assert.expect(2); - preferences.setColumnPreferences('foo', { isVisible: false }); - - preferences.setColumnPreference('foo', 'isVisible', true); - - assert.deepEqual( - preferences.getColumnPreferences('foo'), - { isVisible: true }, - 'existing preference updated succesfully' - ); + let data = { + foo: 1, + bar: 2, + }; - preferences.setColumnPreference('bar', 'isVisible', false); + let preferences = new TablePreferences('preferences-key', { + // Deliberately testing incorrect type + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + restore: () => data, + persist: (key, toPersist) => { + assert.strictEqual(key, 'preferences-key'); + assert.deepEqual(toPersist, { plugins: {} }); + }, + }); - assert.deepEqual( - preferences.getColumnPreferences('bar'), - { isVisible: false }, - 'preference for column without previous preferences set correctly' - ); + preferences.persist(); }); + }); - test('#deleteColumnPreference: deletes a single preference for a column', async function (assert) { - let preferences = new TablePreferences('preferences-key'); + module('plugins', function () { + test('can interact with the TrackedMaps (get and set)', async function (assert) { + assert.expect(5); + + let data: PreferencesData = { + plugins: { + 'column-visibility': { + table: { + foo: 2, + }, + columns: { + foo: { woop: false }, + bar: { woop: true }, + }, + }, + }, + }; + let preferences = new TablePreferences('preferences-key', { + restore: () => data, + persist: (key, toPersist) => { + assert.deepEqual(toPersist, { + plugins: { + 'column-visibility': { + table: { foo: 3 }, + columns: { + bar: { woop: true }, + foo: { woop: true }, + }, + }, + }, + }); + }, + }); - preferences.setColumnPreferences('foo', { isVisible: true }); + let foo = preferences.storage.forPlugin('column-visibility').table.get('foo'); + let woop = preferences.storage.forPlugin('column-visibility').forColumn('foo').get('woop'); - let result = preferences.deleteColumnPreference('foo', 'isVisible'); + assert.strictEqual(foo, 2); + assert.false(woop); - assert.true(result, 'returns true when preference is successfully deleted'); + preferences.storage.forPlugin('column-visibility').forColumn('foo').set('woop', true); + preferences.storage.forPlugin('column-visibility').table.set('foo', 3); - assert.deepEqual( - preferences.getColumnPreferences('foo'), - {}, - 'preference was successfully deleted' - ); + foo = preferences.storage.forPlugin('column-visibility').table.get('foo'); + woop = preferences.storage.forPlugin('column-visibility').forColumn('foo').get('woop'); - assert.false( - preferences.deleteColumnPreference('bar', 'isVisible'), - 'returns false when preference for column does not exist' - ); + assert.strictEqual(foo, 3); + assert.true(woop); + preferences.persist(); }); - test('#toTablePreferencesData: returns preferences in shape of TablePreferencesData', async function (assert) { - let preferences = new TablePreferences('preferences-key'); - - preferences.setColumnPreferences('foo', { isVisible: false }); - preferences.setColumnPreferences('bar', { isVisible: true }); - - let result: PreferencesData = preferences.toTablePreferencesData(); - - assert.deepEqual(result, { - columns: { - foo: { isVisible: false }, - bar: { isVisible: true }, + test('can be deleted', async function (assert) { + assert.expect(3); + + let data: PreferencesData = { + plugins: { + 'column-visibility': { + table: { + foo: 2, + }, + columns: { + foo: { woop: false }, + bar: { woop: true }, + }, + }, + }, + }; + let preferences = new TablePreferences('preferences-key', { + restore: () => data, + persist: (key, toPersist) => { + assert.deepEqual(toPersist, { + plugins: { + 'column-visibility': { + table: {}, + columns: { + foo: {}, + bar: { woop: true }, + }, + }, + }, + }); }, }); - }); - test('#toTablePreferencesData: excludes empty column preferences', async function (assert) { - let preferences = new TablePreferences('preferences-key'); + preferences.storage.forPlugin('column-visibility').table.delete('foo'); + preferences.storage.forPlugin('column-visibility').forColumn('foo').delete('woop'); - preferences.setColumnPreferences('foo', { isVisible: true }); - preferences.setColumnPreferences('bar', {}); - preferences.setColumnPreferences('baz', {}); + let foo = preferences.storage.forPlugin('column-visibility').table.get('foo'); + let woop = preferences.storage.forPlugin('column-visibility').forColumn('foo').get('woop'); - let result: PreferencesData = preferences.toTablePreferencesData(); - - assert.deepEqual(result, { - columns: { - foo: { isVisible: true }, - }, - }); + assert.strictEqual(foo, undefined); + assert.strictEqual(woop, undefined); + preferences.persist(); }); - }); - module('#restore', function () { - test('@adapter#restore(): returns initial data for table preferences', async function (assert) { - let adapter = { - restore: () => ({ - columns: { - foo: { isVisible: true }, - bar: { isVisible: false }, + test(`do not interfere with other plugin's data`, async function (assert) { + assert.expect(1); + + let data: PreferencesData = { + plugins: { + 'column-visibility': { + table: { + foo: 2, + }, + columns: { + foo: { woop: false }, + bar: { woop: true }, + }, }, - }), + }, }; - let preferences = new TablePreferences('preferences-key', adapter); - - assert.deepEqual(Object.fromEntries(preferences.columnPreferences), { - foo: { isVisible: true }, - bar: { isVisible: false }, + let preferences = new TablePreferences('preferences-key', { + restore: () => data, + persist: (key, toPersist) => { + assert.deepEqual(toPersist, { + plugins: { + 'column-visibility': { + table: { foo: 2 }, + columns: { + bar: { woop: true }, + foo: { woop: true }, + }, + }, + 'old-plugin': { + table: {}, + columns: { + foo: { + woop: 2, + }, + }, + }, + 'test-plugin': { + table: {}, + columns: { + foo: { + woop: '1', + }, + }, + }, + }, + }); + }, }); - }); - }); - - module('#restore and #persist are inverses', function () { - // test('mixed top-level keys along with plugin data', async function (assert) { - // let persist = sinon.fake(); - // let data: PreferencesData = { - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // }, - // plugins: { - // 'column-visibility': { - // table: { - // foo: 2, - // }, - // columns: { - // foo: { isVilable: true }, - // bar: { isVilable: true }, - // }, - // }, - // }, - // }; - // let preferences = new TablePreferences('preferences-key', { - // restore: () => data, - // persist, - // }); - // preferences.persist(); - // assert.deepEqual(persist.getCall(0).args[1], data); - // }); - // test('unexpected keys are omitted from persist', async function (assert) { - // let persist = sinon.fake(); - // let data = { - // foo: 1, - // bar: 2, - // }; - // let preferences = new TablePreferences('preferences-key', { - // // Deliberately testing incorrect type - // // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // // @ts-ignore - // restore: () => data, - // persist, - // }); - // preferences.persist(); - // assert.deepEqual(persist.getCall(0).args[1], { plugins: {} }); - // }); - }); - - module('#persist', function () { - // test('@adapter#persist(): is called when deleteColumnPreference', async function (assert) { - // let persist = sinon.fake(); - // let preferences = new TablePreferences('preferences-key', { - // restore: () => ({ - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // baz: { isVisible: true }, - // }, - // }), - // persist, - // }); - // preferences.deleteColumnPreference('foo', 'isVisible'); - // preferences.deleteColumnPreference('bar', 'isVisible'); - // preferences.deleteColumnPreference('baz', 'isVisible'); - // assert.strictEqual(persist.callCount, 3, 'persist was called 3 times'); - // assert.deepEqual(persist.getCall(0).args, [ - // 'preferences-key', - // { - // columns: { - // bar: { isVisible: false }, - // baz: { isVisible: true }, - // }, - // plugins: {}, - // }, - // ]); - // assert.deepEqual(persist.getCall(1).args, [ - // 'preferences-key', - // { - // columns: { - // baz: { isVisible: true }, - // }, - // plugins: {}, - // }, - // ]); - // assert.deepEqual(persist.getCall(2).args, ['preferences-key', { plugins: {} }]); - // }); - // test('@adapter#persist(): is not called when deleteColumnPreference for non-existant preference', async function (assert) { - // let persist = sinon.fake(); - // let preferences = new TablePreferences('preferences-key', { - // restore: () => ({ - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // }, - // }), - // persist, - // }); - // preferences.deleteColumnPreference('baz', 'isVisible'); - // assert.true(persist.notCalled, 'persist was not called'); - // }); - // test('@adapter#persist(): is called when setColumnPreference', async function (assert) { - // let persist = sinon.fake(); - // let preferences = new TablePreferences('preferences-key', { persist }); - // preferences.setColumnPreference('foo', 'isVisible', true); - // preferences.setColumnPreference('bar', 'isVisible', false); - // preferences.setColumnPreference('baz', 'isVisible', true); - // assert.strictEqual(persist.callCount, 3, 'persist was called 3 times'); - // assert.deepEqual(persist.getCall(0).args, [ - // 'preferences-key', - // { - // columns: { - // foo: { isVisible: true }, - // }, - // plugins: {}, - // }, - // ]); - // assert.deepEqual(persist.getCall(1).args, [ - // 'preferences-key', - // { - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // }, - // plugins: {}, - // }, - // ]); - // assert.deepEqual(persist.getCall(2).args, [ - // 'preferences-key', - // { - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // baz: { isVisible: true }, - // }, - // plugins: {}, - // }, - // ]); - // }); - // test('@adapter#persist(): is called when setColumnPreferences', async function (assert) { - // let persist = sinon.fake(); - // let preferences = new TablePreferences('preferences-key', { persist }); - // preferences.setColumnPreferences('foo', { isVisible: true }); - // preferences.setColumnPreferences('bar', { isVisible: false }); - // preferences.setColumnPreferences('baz', { isVisible: true }); - // assert.strictEqual(persist.callCount, 3, 'persist was called 3 times'); - // assert.deepEqual(persist.getCall(0).args, [ - // 'preferences-key', - // { - // columns: { - // foo: { isVisible: true }, - // }, - // plugins: {}, - // }, - // ]); - // assert.deepEqual(persist.getCall(1).args, [ - // 'preferences-key', - // { - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // }, - // plugins: {}, - // }, - // ]); - // assert.deepEqual(persist.getCall(2).args, [ - // 'preferences-key', - // { - // columns: { - // foo: { isVisible: true }, - // bar: { isVisible: false }, - // baz: { isVisible: true }, - // }, - // plugins: {}, - // }, - // ]); - // }); - }); - module('plugins', function () { - // test('can interact with the TrackedMaps (get and set)', async function (assert) { - // let persist = sinon.fake(); - // let data: PreferencesData = { - // plugins: { - // 'column-visibility': { - // table: { - // foo: 2, - // }, - // columns: { - // foo: { woop: false }, - // bar: { woop: true }, - // }, - // }, - // }, - // }; - // let preferences = new TablePreferences('preferences-key', { - // restore: () => data, - // persist, - // }); - // let foo = preferences.storage.forPlugin('column-visibility').table.get('foo'); - // let woop = preferences.storage.forPlugin('column-visibility').forColumn('foo').get('woop'); - // assert.strictEqual(foo, 2); - // assert.false(woop); - // preferences.storage.forPlugin('column-visibility').forColumn('foo').set('woop', true); - // preferences.storage.forPlugin('column-visibility').table.set('foo', 3); - // foo = preferences.storage.forPlugin('column-visibility').table.get('foo'); - // woop = preferences.storage.forPlugin('column-visibility').forColumn('foo').get('woop'); - // assert.strictEqual(foo, 3); - // assert.true(woop); - // preferences.persist(); - // assert.deepEqual(persist.getCall(0).args[1], { - // plugins: { - // 'column-visibility': { - // table: { foo: 3 }, - // columns: { - // bar: { woop: true }, - // foo: { woop: true }, - // }, - // }, - // }, - // }); - // }); - // test('can be deleted', async function (assert) { - // let persist = sinon.fake(); - // let data: PreferencesData = { - // plugins: { - // 'column-visibility': { - // table: { - // foo: 2, - // }, - // columns: { - // foo: { woop: false }, - // bar: { woop: true }, - // }, - // }, - // }, - // }; - // let preferences = new TablePreferences('preferences-key', { - // restore: () => data, - // persist, - // }); - // preferences.storage.forPlugin('column-visibility').table.delete('foo'); - // preferences.storage.forPlugin('column-visibility').forColumn('foo').delete('woop'); - // let foo = preferences.storage.forPlugin('column-visibility').table.get('foo'); - // let woop = preferences.storage.forPlugin('column-visibility').forColumn('foo').get('woop'); - // assert.strictEqual(foo, undefined); - // assert.strictEqual(woop, undefined); - // preferences.persist(); - // assert.deepEqual(persist.getCall(0).args[1], { - // plugins: { - // 'column-visibility': { - // table: {}, - // columns: { - // foo: {}, - // bar: { woop: true }, - // }, - // }, - // }, - // }); - // }); - // test(`do not interfere with other plugin's data`, async function (assert) { - // let persist = sinon.fake(); - // let data: PreferencesData = { - // plugins: { - // 'column-visibility': { - // table: { - // foo: 2, - // }, - // columns: { - // foo: { woop: false }, - // bar: { woop: true }, - // }, - // }, - // }, - // }; - // let preferences = new TablePreferences('preferences-key', { - // restore: () => data, - // persist, - // }); - // preferences.storage.forPlugin('column-visibility').forColumn('foo').set('woop', true); - // preferences.storage.forPlugin('test-plugin').forColumn('foo').set('woop', '1'); - // preferences.storage.forPlugin('old-plugin').forColumn('foo').set('woop', 2); - // preferences.persist(); - // assert.deepEqual(persist.getCall(0).args[1], { - // plugins: { - // 'column-visibility': { - // table: { foo: 2 }, - // columns: { - // bar: { woop: true }, - // foo: { woop: true }, - // }, - // }, - // 'old-plugin': { - // table: {}, - // columns: { - // foo: { - // woop: 2, - // }, - // }, - // }, - // 'test-plugin': { - // table: {}, - // columns: { - // foo: { - // woop: '1', - // }, - // }, - // }, - // }, - // }); - // }); + preferences.storage.forPlugin('column-visibility').forColumn('foo').set('woop', true); + preferences.storage.forPlugin('test-plugin').forColumn('foo').set('woop', '1'); + preferences.storage.forPlugin('old-plugin').forColumn('foo').set('woop', 2); + preferences.persist(); + }); }); }); @@ -465,10 +247,6 @@ module('Preferences | rendering', function (hooks) { test('restored preferences are reactive', async function (assert) { let data: PreferencesData = { - columns: { - foo: { isVisible: true }, - bar: { isVisible: false }, - }, plugins: { 'column-visibility': { table: { @@ -487,10 +265,6 @@ module('Preferences | rendering', function (hooks) { }); class Context { - get deprecatedInfo() { - return preferences.getColumnPreferences('foo').isVisible; - } - get tableInfo() { return preferences.storage.forPlugin('column-visibility').table.get('foo'); } @@ -509,25 +283,20 @@ module('Preferences | rendering', function (hooks) { // @ts-ignore hbs` {{! @glint-ignore }} - {{this.ctx.deprecatedInfo}} - {{! @glint-ignore }} {{this.ctx.tableInfo}} {{! @glint-ignore }} {{this.ctx.columnInfo}} ` ); - assert.dom('#deprecated').hasText('true'); assert.dom('#table').hasText('2'); assert.dom('#column').hasText('false'); - preferences.setColumnPreference('foo', 'isVisible', false); preferences.storage.forPlugin('column-visibility').forColumn('foo').set('woop', true); preferences.storage.forPlugin('column-visibility').table.set('foo', 3); await settled(); - assert.dom('#deprecated').hasText('false'); assert.dom('#table').hasText('3'); assert.dom('#column').hasText('true'); });