Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore(cleanup): remove deprecated preferences code #11

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions ember-headless-table/src/-private/interfaces/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ColumnPreferences>;
/**
* Every plugin has its own namespace for preferences storage.
*
Expand Down Expand Up @@ -83,21 +79,3 @@ export interface PluginPreferences {
[columnKey: string]: Record<string, unknown>;
};
}

/**
* @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;
}
89 changes: 0 additions & 89 deletions ember-headless-table/src/-private/preferences.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { TrackedMap } from 'tracked-built-ins';

import type {
ColumnPreferences,
PluginPreferenceFor,
PluginPreferences,
PreferencesAdapter as Adapter,
Expand All @@ -12,11 +11,6 @@ import type {
export class TablePreferences {
storage = new TrackedPreferences();

/**
* @deprecated - preferences must be plugin-based
*/
columnPreferences = new TrackedMap<string, ColumnPreferences>();

constructor(private key: string, private adapter?: Adapter) {
if (this.adapter) {
this.restore(this.adapter);
Expand All @@ -27,88 +21,10 @@ export class TablePreferences {
return this.adapter !== undefined;
}

/**
* @deprecated - preferences must be plugin-based
*/
deleteColumnPreference<K extends keyof ColumnPreferences>(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<K extends keyof ColumnPreferences>(
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<string, ColumnPreferences> = {};

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`
*
Expand All @@ -118,7 +34,6 @@ export class TablePreferences {
*/
persist() {
return this.adapter?.persist?.(this.key, {
...this.toTablePreferencesData(),
...this.storage.serialize(),
});
}
Expand All @@ -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);
}
}
Expand Down
12 changes: 1 addition & 11 deletions ember-headless-table/src/-private/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -342,16 +342,6 @@ export class Table<DataType = unknown> extends Resource<Signature<DataType>> {
this.#page = this.pagination?.page;
}

/**
* @deprecated
*/
getColumnPreference<K extends keyof ColumnPreferences>(
columnKey: ColumnKey<DataType>,
key: K
): ColumnPreferences[K] {
return this.preferences.getColumnPreferences(columnKey)[key];
}

/**
* @private
*/
Expand Down
100 changes: 73 additions & 27 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading