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
c8704344
Unverified
Commit
c8704344
authored
2 years ago
by
Dalton
Committed by
GitHub
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convert metabase/parameters/utils/ui to TypeScript (#24566)
parent
32002457
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/parameters/utils/ui.ts
+10
-4
10 additions, 4 deletions
frontend/src/metabase/parameters/utils/ui.ts
frontend/src/metabase/parameters/utils/ui.unit.spec.ts
+106
-0
106 additions, 0 deletions
frontend/src/metabase/parameters/utils/ui.unit.spec.ts
with
116 additions
and
4 deletions
frontend/src/metabase/parameters/utils/ui.
j
s
→
frontend/src/metabase/parameters/utils/ui.
t
s
+
10
−
4
View file @
c8704344
import
_
from
"
underscore
"
;
import
{
isEqualsOperator
}
from
"
metabase/lib/schema_metadata
"
;
import
{
UiParameter
}
from
"
metabase/parameters/types
"
;
import
{
getParameterType
}
from
"
./parameter-type
"
;
import
{
deriveFieldOperatorFromParameter
}
from
"
./operators
"
;
export
function
getParameterIconName
(
parameter
)
{
export
function
getParameterIconName
(
parameter
:
UiParameter
)
{
const
type
=
getParameterType
(
parameter
);
switch
(
type
)
{
case
"
date
"
:
...
...
@@ -21,20 +22,25 @@ export function getParameterIconName(parameter) {
}
}
export
function
buildHiddenParametersSlugSet
(
hiddenParameterSlugs
)
{
export
function
buildHiddenParametersSlugSet
(
hiddenParameterSlugs
:
string
|
undefined
,
)
{
return
_
.
isString
(
hiddenParameterSlugs
)
?
new
Set
(
hiddenParameterSlugs
.
split
(
"
,
"
))
:
new
Set
();
}
export
function
getVisibleParameters
(
parameters
,
hiddenParameterSlugs
)
{
export
function
getVisibleParameters
(
parameters
:
UiParameter
[],
hiddenParameterSlugs
:
string
|
undefined
,
)
{
const
hiddenParametersSlugSet
=
buildHiddenParametersSlugSet
(
hiddenParameterSlugs
);
return
parameters
.
filter
(
p
=>
!
hiddenParametersSlugSet
.
has
(
p
.
slug
));
}
export
function
getParameterWidgetTitle
(
parameter
)
{
export
function
getParameterWidgetTitle
(
parameter
:
UiParameter
)
{
const
operator
=
deriveFieldOperatorFromParameter
(
parameter
);
const
{
verboseName
}
=
operator
||
{};
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/parameters/utils/ui.unit.spec.
j
s
→
frontend/src/metabase/parameters/utils/ui.unit.spec.
t
s
+
106
−
0
View file @
c8704344
...
...
@@ -5,15 +5,23 @@ import {
getParameterWidgetTitle
,
}
from
"
./ui
"
;
import
{
createMockUiParameter
}
from
"
metabase/parameters/mock
"
;
describe
(
"
parameters/utils/ui
"
,
()
=>
{
describe
(
"
getParameterIconName
"
,
()
=>
{
it
(
"
should return an icon name for the given parameter
"
,
()
=>
{
expect
(
getParameterIconName
({
type
:
"
category
"
})).
toEqual
(
"
string
"
);
expect
(
getParameterIconName
({
type
:
"
date/single
"
})).
toEqual
(
"
calendar
"
);
expect
(
getParameterIconName
(
createMockUiParameter
({
type
:
"
category
"
})),
).
toEqual
(
"
string
"
);
expect
(
getParameterIconName
(
createMockUiParameter
({
type
:
"
date/single
"
})),
).
toEqual
(
"
calendar
"
);
});
it
(
"
should safely default
"
,
()
=>
{
expect
(
getParameterIconName
({
type
:
"
???
"
})).
toEqual
(
"
label
"
);
expect
(
getParameterIconName
(
createMockUiParameter
({
type
:
"
???
"
})),
).
toEqual
(
"
label
"
);
});
});
...
...
@@ -24,66 +32,75 @@ describe("parameters/utils/ui", () => {
);
});
it
(
"
should return an empty set for an
y input
that is
not a string
"
,
()
=>
{
it
(
"
should return an empty set for an
arg
that is
undefined
"
,
()
=>
{
expect
(
buildHiddenParametersSlugSet
(
undefined
)).
toEqual
(
new
Set
());
expect
(
buildHiddenParametersSlugSet
(
111111
)).
toEqual
(
new
Set
());
});
});
describe
(
"
getVisibleParameters
"
,
()
=>
{
const
parameters
=
[
{
id
:
1
,
createMockUiParameter
(
{
id
:
"
1
"
,
slug
:
"
foo
"
,
},
{
id
:
2
,
}
)
,
createMockUiParameter
(
{
id
:
"
2
"
,
slug
:
"
bar
"
,
},
{
id
:
3
,
}
)
,
createMockUiParameter
(
{
id
:
"
3
"
,
slug
:
"
baz
"
,
},
{
id
:
4
,
}
)
,
createMockUiParameter
(
{
id
:
"
4
"
,
slug
:
"
qux
"
,
},
}
)
,
];
const
hiddenParameterSlugs
=
"
bar,baz
"
;
it
(
"
should return the parameters that are not hidden
"
,
()
=>
{
expect
(
getVisibleParameters
(
parameters
,
hiddenParameterSlugs
)).
toEqual
([
{
id
:
1
,
expect
.
objectContaining
(
{
id
:
"
1
"
,
slug
:
"
foo
"
,
},
{
id
:
4
,
}
)
,
expect
.
objectContaining
(
{
id
:
"
4
"
,
slug
:
"
qux
"
,
},
}
)
,
]);
});
});
describe
(
"
getParameterWidgetTitle
"
,
()
=>
{
it
(
"
should return a title for the given parameter
"
,
()
=>
{
expect
(
getParameterWidgetTitle
({
type
:
"
string/starts-with
"
})).
toEqual
(
"
Starts with…
"
,
);
expect
(
getParameterWidgetTitle
(
createMockUiParameter
({
type
:
"
string/starts-with
"
}),
),
).
toEqual
(
"
Starts with…
"
);
expect
(
getParameterWidgetTitle
({
type
:
"
number/between
"
})).
toEqual
(
"
Between…
"
,
);
expect
(
getParameterWidgetTitle
(
createMockUiParameter
({
type
:
"
number/between
"
}),
),
).
toEqual
(
"
Between…
"
);
});
it
(
"
should not return a title for equal operator parameters
"
,
()
=>
{
expect
(
getParameterWidgetTitle
({
type
:
"
string/=
"
})).
toBeUndefined
();
expect
(
getParameterWidgetTitle
({
type
:
"
number/=
"
})).
toBeUndefined
();
expect
(
getParameterWidgetTitle
(
createMockUiParameter
({
type
:
"
string/=
"
})),
).
toBeUndefined
();
expect
(
getParameterWidgetTitle
(
createMockUiParameter
({
type
:
"
number/=
"
})),
).
toBeUndefined
();
});
it
(
"
should default to undefined for parameters without operators
"
,
()
=>
{
expect
(
getParameterWidgetTitle
({
type
:
"
category
"
})).
toBeUndefined
();
expect
(
getParameterWidgetTitle
(
createMockUiParameter
({
type
:
"
category
"
})),
).
toBeUndefined
();
});
});
});
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