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
1acb06b5
Unverified
Commit
1acb06b5
authored
1 year ago
by
Nick Fitzpatrick
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
removing prefix and suffix from formatValueRaw (#31962)
parent
cc552817
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/lib/formatting/value.tsx
+6
-5
6 additions, 5 deletions
frontend/src/metabase/lib/formatting/value.tsx
frontend/src/metabase/lib/formatting/value.unit.spec.tsx
+62
-0
62 additions, 0 deletions
frontend/src/metabase/lib/formatting/value.unit.spec.tsx
with
68 additions
and
5 deletions
frontend/src/metabase/lib/formatting/value.tsx
+
6
−
5
View file @
1acb06b5
...
...
@@ -36,7 +36,8 @@ const MARKDOWN_RENDERERS = {
),
};
export
function
formatValue
(
value
:
unknown
,
options
:
OptionsType
=
{})
{
export
function
formatValue
(
value
:
unknown
,
_options
:
OptionsType
=
{})
{
let
{
prefix
,
suffix
,
...
options
}
=
_options
;
// avoid rendering <ExternalLink> if we have click_behavior set
if
(
options
.
click_behavior
&&
...
...
@@ -76,17 +77,17 @@ export function formatValue(value: unknown, options: OptionsType = {}) {
return
formatted
;
}
}
if
(
options
.
prefix
||
options
.
suffix
)
{
if
(
prefix
||
suffix
)
{
if
(
options
.
jsx
&&
typeof
formatted
!==
"
string
"
)
{
return
(
<
span
>
{
options
.
prefix
||
""
}
{
prefix
||
""
}
{
formatted
}
{
options
.
suffix
||
""
}
{
suffix
||
""
}
</
span
>
);
}
else
{
return
`
${
options
.
prefix
||
""
}${
formatted
}${
options
.
suffix
||
""
}
`
;
return
`
${
prefix
||
""
}${
formatted
}${
suffix
||
""
}
`
;
}
}
else
{
return
formatted
;
...
...
This diff is collapsed.
Click to expand it.
frontend/src/metabase/lib/formatting/value.unit.spec.tsx
0 → 100644
+
62
−
0
View file @
1acb06b5
import
{
screen
,
render
}
from
"
__support__/ui
"
;
import
{
createMockColumn
}
from
"
metabase-types/api/mocks
"
;
import
{
formatValue
}
from
"
./value
"
;
import
type
{
OptionsType
}
from
"
./types
"
;
const
setup
=
(
value
:
any
,
overrides
:
Partial
<
OptionsType
>
=
{})
=>
{
const
column
=
createMockColumn
({
base_type
:
"
type/Float
"
,
});
const
options
:
OptionsType
=
{
view_as
:
"
auto
"
,
column
:
column
,
type
:
"
cell
"
,
jsx
:
true
,
rich
:
true
,
clicked
:
{
value
:
value
,
column
:
column
,
origin
:
{
rowIndex
:
0
,
row
:
[
value
],
cols
:
[
column
],
},
data
:
[
{
value
:
value
,
col
:
column
,
},
],
},
...
overrides
,
};
render
(<>
{
formatValue
(
value
,
options
)
}
</>);
};
describe
(
"
link
"
,
()
=>
{
it
(
"
should not apply prefix or suffix more than once for links with no link_text
"
,
()
=>
{
setup
(
23.12
,
{
view_as
:
"
link
"
,
prefix
:
"
foo
"
,
suffix
:
"
bar
"
,
link_url
:
"
http://google.ca
"
,
});
expect
(
screen
.
getByText
((
content
,
element
)
=>
content
.
startsWith
(
"
foo
"
)),
).
toBeInTheDocument
();
expect
(
screen
.
getByText
((
content
,
element
)
=>
content
.
endsWith
(
"
bar
"
)),
).
toBeInTheDocument
();
expect
(
screen
.
getByText
(
"
23.12
"
)).
toBeInTheDocument
();
});
it
(
"
should trim values to specified decimals
"
,
()
=>
{
setup
(
23.123459
,
{
decimals
:
5
,
number_style
:
"
decimal
"
,
number_separators
:
"
.
"
,
});
expect
(
screen
.
getByText
(
"
23.12346
"
)).
toBeInTheDocument
();
});
});
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