Skip to content

Commit

Permalink
fix: remove saved setting of disabled column
Browse files Browse the repository at this point in the history
  • Loading branch information
hassanalbaaj authored and cristinecula committed Aug 28, 2024
1 parent 3e5400f commit 686542b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
11 changes: 11 additions & 0 deletions demo/helpers/x-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ class XPage extends translatable(PolymerElement) {
<paper-toggle-button checked="{{ loading }}">
Loading</paper-toggle-button
>
<paper-toggle-button
checked="{{ hidden }}"
style="margin-left: 10px;"
>
Hide Sub-property column
</paper-toggle-button>
</div>
<cosmoz-omnitable
Expand Down Expand Up @@ -200,6 +206,7 @@ class XPage extends translatable(PolymerElement) {
group-on="sub.subProp"
flex="5"
width="200px"
disabled="[[ hidden ]]"
>
</cosmoz-omnitable-column>
<cosmoz-omnitable-column
Expand Down Expand Up @@ -264,6 +271,10 @@ class XPage extends translatable(PolymerElement) {
hashParam: {
type: String,
},
hidden: {
type: Number,
value: false,
},
};
}

Expand Down
19 changes: 11 additions & 8 deletions lib/settings/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ const byName = (name) => (item) => item.name === name;
export const normalizeColumns = (
columns = [],
settings = [],
savedSettings = []
savedSettings = [],
) => {
const cols = columns.filter(
const _settings = settings.filter((setting) =>
columns.some(byName(setting.name)),
),
cols = columns.filter(
(column) =>
!settings.some(byName(column.name)) &&
!savedSettings.some(byName(column.name))
!savedSettings.some(byName(column.name)),
),
_savedSettings = savedSettings.filter(
(column) => !settings.some(byName(column.name))
(column) => !settings.some(byName(column.name)),
);

return [
...settings,
..._settings,
..._savedSettings.flatMap((setting) => {
const column = columns.find((c) => c.name === setting.name);

Expand Down Expand Up @@ -52,13 +55,13 @@ export const normalizeStore = (settings, current) => ({
...current,
...props(sgProps)(settings),
columns: settings.columns?.map(
props(['name', 'priority', 'width', 'flex', 'disabled'])
props(['name', 'priority', 'width', 'flex', 'disabled']),
),
});

export default ({ columns, settings, savedSettings, initial }) => {
const init = Object.fromEntries(
sgProps.flatMap((k) => (initial[k] != null ? [[k, initial[k]]] : []))
sgProps.flatMap((k) => (initial[k] != null ? [[k, initial[k]]] : [])),
);

return {
Expand All @@ -68,7 +71,7 @@ export default ({ columns, settings, savedSettings, initial }) => {
columns: normalizeColumns(
columns,
settings?.columns,
savedSettings?.columns
savedSettings?.columns,
),
};
};

0 comments on commit 686542b

Please sign in to comment.