Skip to content
Snippets Groups Projects
Unverified Commit 1acb06b5 authored by Nick Fitzpatrick's avatar Nick Fitzpatrick Committed by GitHub
Browse files

removing prefix and suffix from formatValueRaw (#31962)

parent cc552817
Branches
Tags
No related merge requests found
......@@ -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;
......
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();
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment