Skip to content
Snippets Groups Projects
Unverified Commit 9d1b4f21 authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Configure show download button in embedding (#23479)

* Configure show download button in embedding

* Address review + fix tests
parent 2d36fd21
No related branches found
No related tags found
No related merge requests found
...@@ -41,6 +41,7 @@ export const ToggleRoot = styled.input<ToggleRootProps>` ...@@ -41,6 +41,7 @@ export const ToggleRoot = styled.input<ToggleRootProps>`
background-color: ${color("bg-medium")}; background-color: ${color("bg-medium")};
background-color: ${getBackgroundColor}; background-color: ${getBackgroundColor};
transition: background-color 0.3s; transition: background-color 0.3s;
flex-shrink: 0;
&:after { &:after {
content: ""; content: "";
......
...@@ -43,12 +43,13 @@ class EmbedFrame extends Component { ...@@ -43,12 +43,13 @@ class EmbedFrame extends Component {
} = this.props; } = this.props;
const { innerScroll } = this.state; const { innerScroll } = this.state;
const showFooter = !MetabaseSettings.hideEmbedBranding() || actionButtons; const { bordered, titled, theme, hide_parameters, hide_download_button } = {
const { bordered, titled, theme, hide_parameters } = {
...DEFAULT_OPTIONS, ...DEFAULT_OPTIONS,
...parseHashOptions(location.hash), ...parseHashOptions(location.hash),
}; };
const showFooter =
!MetabaseSettings.hideEmbedBranding() ||
(!hide_download_button && actionButtons);
const name = titled ? this.props.name : null; const name = titled ? this.props.name : null;
......
...@@ -6,6 +6,8 @@ import { connect } from "react-redux"; ...@@ -6,6 +6,8 @@ import { connect } from "react-redux";
import Radio from "metabase/core/components/Radio/"; import Radio from "metabase/core/components/Radio/";
import CheckBox from "metabase/core/components/CheckBox"; import CheckBox from "metabase/core/components/CheckBox";
import Select from "metabase/core/components/Select"; import Select from "metabase/core/components/Select";
import Toggle from "metabase/core/components/Toggle";
import { useUniqueId } from "metabase/hooks/use-unique-id";
import MetabaseSettings from "metabase/lib/settings"; import MetabaseSettings from "metabase/lib/settings";
import { PLUGIN_SELECTORS } from "metabase/plugins"; import { PLUGIN_SELECTORS } from "metabase/plugins";
import { t } from "ttag"; import { t } from "ttag";
...@@ -14,6 +16,8 @@ import { ...@@ -14,6 +16,8 @@ import {
StyleContainer, StyleContainer,
DisplayOption, DisplayOption,
DisplayOptionTitle, DisplayOptionTitle,
ToggleContainer,
ToggleLabel,
} from "./DisplayOptionsPane.styled"; } from "./DisplayOptionsPane.styled";
const THEME_OPTIONS = [ const THEME_OPTIONS = [
...@@ -30,63 +34,88 @@ const DisplayOptionsPane = ({ ...@@ -30,63 +34,88 @@ const DisplayOptionsPane = ({
displayOptions, displayOptions,
onChangeDisplayOptions, onChangeDisplayOptions,
canWhitelabel, canWhitelabel,
}) => ( }) => {
<div className={className}> const toggleId = useUniqueId("show-download-data-button");
<DisplayOptionSection title={t`Style`}>
<StyleContainer> return (
<CheckBox <div className={className}>
label={t`Border`} <DisplayOptionSection title={t`Style`}>
checked={displayOptions.bordered} <StyleContainer>
onChange={e => <CheckBox
onChangeDisplayOptions({ label={t`Border`}
...displayOptions, checked={displayOptions.bordered}
bordered: e.target.checked, onChange={e =>
}) onChangeDisplayOptions({
} ...displayOptions,
/> bordered: e.target.checked,
<CheckBox })
label={t`Title`} }
checked={displayOptions.titled} />
onChange={e => <CheckBox
onChangeDisplayOptions({ label={t`Title`}
...displayOptions, checked={displayOptions.titled}
titled: e.target.checked, onChange={e =>
}) onChangeDisplayOptions({
...displayOptions,
titled: e.target.checked,
})
}
/>
</StyleContainer>
</DisplayOptionSection>
<DisplayOptionSection title={t`Appearance`}>
<Radio
value={displayOptions.theme}
options={THEME_OPTIONS}
onChange={value =>
onChangeDisplayOptions({ ...displayOptions, theme: value })
} }
/> variant="normal"
</StyleContainer> showButtons
</DisplayOptionSection> vertical
<DisplayOptionSection title={t`Appearance`}>
<Radio
value={displayOptions.theme}
options={THEME_OPTIONS}
onChange={value =>
onChangeDisplayOptions({ ...displayOptions, theme: value })
}
variant="normal"
showButtons
vertical
/>
</DisplayOptionSection>
{canWhitelabel && (
<DisplayOptionSection title={t`Font`}>
<Select
value={displayOptions.font}
options={MetabaseSettings.get("available-fonts").map(font => ({
name: font,
value: font,
}))}
onChange={e => {
onChangeDisplayOptions({
...displayOptions,
font: e.target.value,
});
}}
/> />
</DisplayOptionSection> </DisplayOptionSection>
)} {canWhitelabel && (
</div> <>
); <DisplayOptionSection title={t`Font`}>
<Select
value={displayOptions.font}
options={MetabaseSettings.get("available-fonts").map(font => ({
name: font,
value: font,
}))}
onChange={e => {
onChangeDisplayOptions({
...displayOptions,
font: e.target.value,
});
}}
/>
</DisplayOptionSection>
<DisplayOptionSection title={t`Download data`}>
<ToggleContainer>
<ToggleLabel
htmlFor={toggleId}
>{t`Enable users to download data from this embed?`}</ToggleLabel>
<Toggle
id={toggleId}
aria-checked={!displayOptions.hide_download_button}
role="switch"
value={!displayOptions.hide_download_button}
onChange={isEnabled => {
onChangeDisplayOptions({
...displayOptions,
hide_download_button: !isEnabled ? true : null,
});
}}
/>
</ToggleContainer>
</DisplayOptionSection>
</>
)}
</div>
);
};
const DisplayOptionSection = ({ title, children }) => ( const DisplayOptionSection = ({ title, children }) => (
<DisplayOption> <DisplayOption>
......
import styled from "@emotion/styled"; import styled from "@emotion/styled";
import { space } from "metabase/styled-components/theme";
export const StyleContainer = styled.div` export const StyleContainer = styled.div`
display: flex; display: flex;
...@@ -18,3 +19,13 @@ export const DisplayOption = styled.div` ...@@ -18,3 +19,13 @@ export const DisplayOption = styled.div`
export const DisplayOptionTitle = styled.h3` export const DisplayOptionTitle = styled.h3`
margin-bottom: 1rem; margin-bottom: 1rem;
`; `;
export const ToggleContainer = styled.div`
display: flex;
align-items: center;
`;
export const ToggleLabel = styled.label`
margin-right: ${space(3)};
line-height: 1.5;
`;
...@@ -27,7 +27,17 @@ describe("scenarios > embedding > code snippets", () => { ...@@ -27,7 +27,17 @@ describe("scenarios > embedding > code snippets", () => {
cy.get(".ace_content") cy.get(".ace_content")
.first() .first()
.invoke("text") .invoke("text")
.should("match", JS_CODE(isEE)); .should("match", JS_CODE({ isEE }));
// hide download button for pro/enterprise users metabase#23477
cy.findByLabelText(
"Enable users to download data from this embed?",
).click();
cy.get(".ace_content")
.first()
.invoke("text")
.should("match", JS_CODE({ isEE, hideDownloadButton: true }));
cy.get(".ace_content") cy.get(".ace_content")
.last() .last()
......
export const JS_CODE = isEE => export const JS_CODE = ({ isEE, hideDownloadButton }) =>
new RegExp( new RegExp(
`// you will need to install via 'npm install jsonwebtoken' or in your package.json `// you will need to install via 'npm install jsonwebtoken' or in your package.json
...@@ -13,9 +13,9 @@ var payload = { ...@@ -13,9 +13,9 @@ var payload = {
}; };
var token = jwt.sign(payload, METABASE_SECRET_KEY); var token = jwt.sign(payload, METABASE_SECRET_KEY);
var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true${ var iframeUrl = METABASE_SITE_URL + "/embed/dashboard/" + token + "#bordered=true&titled=true${getParameter(
isEE ? "&font=Lato" : "" { isEE, hideDownloadButton },
}";` )}";`
.split("\n") .split("\n")
.join("") .join("")
.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") .replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")
...@@ -32,3 +32,17 @@ export const IFRAME_CODE = `<iframe ...@@ -32,3 +32,17 @@ export const IFRAME_CODE = `<iframe
></iframe>` ></iframe>`
.split("\n") .split("\n")
.join(""); .join("");
function getParameter({ isEE, hideDownloadButton }) {
let parameter = "";
if (isEE) {
parameter += "&font=Lato";
}
if (hideDownloadButton) {
parameter += "&hide_download_button=true";
}
return parameter;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment