Conversation
b44fe84 to
43c9aa4
Compare
derrabauke
left a comment
There was a problem hiding this comment.
Generally don't scope only to analysis. That's a feature we will apply to other tables with a high probability. So all the analysis-** prefixed naming --> re-usable component.
There was a problem hiding this comment.
Could we make this more re-usable? Think of it as a service for multiple tables/components. There will be future scenarios where users need to store some UI relevant settings. And that will be the service for it. We don't want to create a new service for each UI setting topic.
I'd suggest the naming UserSettingsService. And probably it's best to store the table column configurations in a configuration file like app/config/table-columns.js so it's easy to extract this service+config in the future to the ui-core addon and we can add column configurations for other tables easily.
There was a problem hiding this comment.
As discussed:
UserSettingsServicehandles the storing/loading- We gonna provide default settings ala:
app/config/table-columns.js(this can include multiple table configurations)app/config/appearance.js
- The default setting should also define the storage (sub-) key, format: `${user-settings-key}-${sub-setting-key}
|
And of course tests are missing. :-) |
i did not write tests yet, just to get confirmation about if this is the right way to implement it |
| @@ -0,0 +1,5 @@ | |||
| <colgroup> | |||
| {{#each @columns as |column|}} | |||
| <col class={{concat "w-[" column.width "%]"}} /> | |||
There was a problem hiding this comment.
that only works if the classes w-[x%] are defined/used elsewhere (with their full name), otherwise tailwind won't include them in the CSS bundle
There was a problem hiding this comment.
This is the same issue you @MitanOmar faced with #1139 (comment)
| export default class AnalysisTableColumnsService extends Service { | ||
| localStorageKey = "hidden-analysis-table-column"; | ||
| @tracked hiddenColumns = []; | ||
| @tracked allTableColumns = [ |
There was a problem hiding this comment.
this is constant, why is it tracked?
nitpick: move it, and the localStorageKey outside of the class (and rename them so its clear they're constants, e.g. ALL_TABLE_COLUMNS and LOCAL_STORAGE_KEY)
There was a problem hiding this comment.
We could also make this more agnostic. analysis-columns-modal -> column-selector-modal
43c9aa4 to
7568aa5
Compare
cbc4c1b to
27766d1
Compare
| @action | ||
| save() { | ||
| this.userSettings.updateHiddenColumns("analysisTable", this.localhidden); | ||
| this.notify.success("The columns are updated successfully"); |
There was a problem hiding this comment.
Not necessary, only notify the user if it fails.
| constructor(userSettings) { | ||
| this.userSettings = userSettings; | ||
| this.loadConfiguration(); | ||
| } |
There was a problem hiding this comment.
What is that? Why not inject the service as normal? Or extend it?
| load(subServiceKey, defaultValue) { | ||
| const fullKey = `${USER_SETTINGS_KEY}.${subServiceKey}`; | ||
| const localStorageValue = localStorage.getItem(fullKey); | ||
| if (!localStorageValue && typeof defaultValue !== "undefined") { | ||
| localStorage.setItem(fullKey, JSON.stringify(defaultValue)); | ||
| return defaultValue; | ||
| } | ||
| return localStorageValue ? JSON.parse(localStorageValue) : defaultValue; | ||
| } |
There was a problem hiding this comment.
Drop the whole sub-service thingy. Make it flat & simple.
| return { | ||
| ...col, | ||
| isVisible: | ||
| userPreference !== undefined ? userPreference : col.isVisible, |
There was a problem hiding this comment.
| userPreference !== undefined ? userPreference : col.isVisible, | |
| userPreference !== undefined ? userPreference.isVisible : col.isVisible, |
| ...this._overrides, | ||
| [tableId]: { | ||
| ...(this._overrides[tableId] || {}), | ||
| [columnId]: isVisible, |
There was a problem hiding this comment.
| [columnId]: isVisible, | |
| [columnId]: { isVisible }, |
| export default class AnalysisColumnsModal extends Component { | ||
| @service userSettings; | ||
| @service notify; | ||
|
|
||
| /** just to not call the update with each toggle, | ||
| * we are saving a local copy, | ||
| * and updating with save function | ||
| */ | ||
| @tracked localhidden = []; | ||
|
|
||
| get hiddenColumns() { | ||
| return this.localhidden; | ||
| } | ||
|
|
||
| constructor(...args) { | ||
| super(...args); | ||
| this.localhidden = this.userSettings | ||
| .getTableColumns("analysis") | ||
| .filter((col) => !col.isVisible) | ||
| .map((col) => col.lable); | ||
| } | ||
|
|
||
| get allTableColumns() { | ||
| return this.userSettings.getTableColumns("analysis"); | ||
| } | ||
|
|
||
| @action | ||
| toggleColumn(columnLabel) { | ||
| if (this.localhidden.includes(columnLabel)) { | ||
| this.localhidden = this.localhidden.filter( | ||
| (label) => label !== columnLabel, | ||
| ); | ||
| return; | ||
| } | ||
| this.localhidden.push(columnLabel); | ||
| } | ||
|
|
||
| @action | ||
| save() { | ||
| try { | ||
| for (const column of this.allTableColumns) { | ||
| this.userSettings.updateColumnVisibility( | ||
| "analysis", | ||
| column.label, | ||
| this.localhidden.includes(column.label), | ||
| ); | ||
| } | ||
| this.args.onClose(); | ||
| } catch (error) { | ||
| console.log({ error }); | ||
| this.notify.error("An error when updating the columns visibility"); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
| export default class AnalysisColumnsModal extends Component { | |
| @service userSettings; | |
| @service notify; | |
| /** just to not call the update with each toggle, | |
| * we are saving a local copy, | |
| * and updating with save function | |
| */ | |
| @tracked localhidden = []; | |
| get hiddenColumns() { | |
| return this.localhidden; | |
| } | |
| constructor(...args) { | |
| super(...args); | |
| this.localhidden = this.userSettings | |
| .getTableColumns("analysis") | |
| .filter((col) => !col.isVisible) | |
| .map((col) => col.lable); | |
| } | |
| get allTableColumns() { | |
| return this.userSettings.getTableColumns("analysis"); | |
| } | |
| @action | |
| toggleColumn(columnLabel) { | |
| if (this.localhidden.includes(columnLabel)) { | |
| this.localhidden = this.localhidden.filter( | |
| (label) => label !== columnLabel, | |
| ); | |
| return; | |
| } | |
| this.localhidden.push(columnLabel); | |
| } | |
| @action | |
| save() { | |
| try { | |
| for (const column of this.allTableColumns) { | |
| this.userSettings.updateColumnVisibility( | |
| "analysis", | |
| column.label, | |
| this.localhidden.includes(column.label), | |
| ); | |
| } | |
| this.args.onClose(); | |
| } catch (error) { | |
| console.log({ error }); | |
| this.notify.error("An error when updating the columns visibility"); | |
| } | |
| } | |
| } | |
| import { tracked } from "tracked-built-ins"; | |
| export default class AnalysisColumnsModal extends Component { | |
| @service userSettings; | |
| @service notify; | |
| columns = tracked(this.userSettings.getTableColumns("analysis")); // that's all you need | |
| @action | |
| toggleColumn(column) { | |
| column.isVisible = !column.isVisible | |
| this.columns = [...this.columns] | |
| } | |
| @action | |
| save() { | |
| try { | |
| for (const column of this.columns) { | |
| this.userSettings.updateColumnVisibility( | |
| "analysis", | |
| column.label, | |
| column.isVisible, | |
| ); | |
| } | |
| this.args.onClose(); | |
| } catch (error) { | |
| console.log({ error }); | |
| this.notify.error("An error when updating the columns visibility"); | |
| } | |
| } | |
| } | |
fix: #1083