Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
8e81f12e
Unverified
Commit
8e81f12e
authored
1 year ago
by
Nick Fitzpatrick
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Merging table.columns for dashcards (#35259)
* temp * Adding unit test
parent
b2b9e168
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/visualizations/lib/settings.js
+25
-0
25 additions, 0 deletions
frontend/src/metabase/visualizations/lib/settings.js
frontend/src/metabase/visualizations/lib/settings.unit.spec.js
+78
-0
78 additions, 0 deletions
...end/src/metabase/visualizations/lib/settings.unit.spec.js
with
103 additions
and
0 deletions
frontend/src/metabase/visualizations/lib/settings.js
+
25
−
0
View file @
8e81f12e
...
...
@@ -243,9 +243,34 @@ export function mergeSettings(first = {}, second = {}) {
}
}
}
if
(
first
[
"
table.columns
"
]
&&
second
[
"
table.columns
"
])
{
merged
[
"
table.columns
"
]
=
mergeTableColumns
(
first
[
"
table.columns
"
],
second
[
"
table.columns
"
],
);
}
return
merged
;
}
const
mergeTableColumns
=
(
firstTableColumns
,
secondTableColumns
)
=>
{
const
addedColumns
=
firstTableColumns
.
filter
(
({
name
})
=>
secondTableColumns
.
findIndex
(
col
=>
col
.
name
===
name
)
===
-
1
,
);
const
removedColumns
=
secondTableColumns
.
filter
(
({
name
})
=>
firstTableColumns
.
findIndex
(
col
=>
col
.
name
===
name
)
===
-
1
,
)
.
map
(({
name
})
=>
name
);
return
[
...
secondTableColumns
.
filter
(({
name
})
=>
!
removedColumns
.
includes
(
name
)),
...
addedColumns
,
];
};
export
function
getClickBehaviorSettings
(
settings
)
{
const
newSettings
=
{};
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/visualizations/lib/settings.unit.spec.js
+
78
−
0
View file @
8e81f12e
import
{
ORDERS
}
from
"
metabase-types/api/mocks/presets
"
;
import
{
createMockTableColumnOrderSetting
}
from
"
metabase-types/api/mocks
"
;
// NOTE: need to load visualizations first for getSettings to work
import
"
metabase/visualizations/index
"
;
...
...
@@ -196,6 +199,81 @@ describe("settings framework", () => {
mergeSettings
({},
{
column_settings
:
{
col1
:
{
set1
:
"
val
"
}
}
}),
).
toEqual
({
column_settings
:
{
col1
:
{
set1
:
"
val
"
}
}
});
});
describe
(
"
table.columns
"
,
()
=>
{
const
ID_COLUMN
=
createMockTableColumnOrderSetting
({
name
:
"
ID
"
,
fieldRef
:
[
"
field
"
,
ORDERS
.
ID
,
null
],
});
const
QUANTITY_COLUMN
=
createMockTableColumnOrderSetting
({
name
:
"
QUANTITY
"
,
fieldRef
:
[
"
field
"
,
ORDERS
.
QUANTITY
,
null
],
});
const
TAX_COLUMN
=
createMockTableColumnOrderSetting
({
name
:
"
TAX
"
,
fieldRef
:
[
"
field
"
,
ORDERS
.
TAX
,
null
],
});
const
DISCOUNT_COLUMN
=
createMockTableColumnOrderSetting
({
name
:
"
DISCOUNT
"
,
fieldRef
:
[
"
field
"
,
ORDERS
.
DISCOUNT
,
null
],
});
it
(
"
should remove columns that don't appear in the first settings
"
,
()
=>
{
expect
(
mergeSettings
(
{
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
],
},
{
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
,
TAX_COLUMN
],
},
),
).
toEqual
({
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
],
});
});
it
(
"
should add new columns that don't appear in the second settings
"
,
()
=>
{
expect
(
mergeSettings
(
{
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
,
DISCOUNT_COLUMN
],
},
{
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
],
},
),
).
toEqual
({
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
,
DISCOUNT_COLUMN
],
});
});
it
(
"
should preserve settings and order from the second settings
"
,
()
=>
{
expect
(
mergeSettings
(
{
"
table.columns
"
:
[
ID_COLUMN
,
QUANTITY_COLUMN
,
DISCOUNT_COLUMN
],
},
{
"
table.columns
"
:
[
DISCOUNT_COLUMN
,
{
...
ID_COLUMN
,
enabled
:
false
},
QUANTITY_COLUMN
,
TAX_COLUMN
,
],
},
),
).
toEqual
({
"
table.columns
"
:
[
DISCOUNT_COLUMN
,
{
...
ID_COLUMN
,
enabled
:
false
},
QUANTITY_COLUMN
,
],
});
});
});
});
describe
(
"
getClickBehaviorSettings
"
,
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment