1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React, { useState, useCallback, useEffect } from "react";
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { Dialog, DialogContent, DialogActions, Button } from "@mui/material";
8 import { WithStyles } from '@mui/styles';
9 import withStyles from '@mui/styles/withStyles';
10 import { connect } from "react-redux";
11 import { RootState } from "store/store";
12 import bannerActions from "store/banner/banner-action";
13 import { ArvadosTheme } from "common/custom-theme";
14 import servicesProvider from "common/service-provider";
15 import { Dispatch } from "redux";
16 import { sanitizeHTML } from "common/html-sanitize";
18 type CssRules = "dialogContent" | "dialogContentIframe";
20 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 dialogContentIframe: {
32 interface BannerProps {
35 keepWebInlineServiceUrl: string;
38 type BannerComponentProps = BannerProps &
39 WithStyles<CssRules> & {
41 closeBanner: Function;
44 const mapStateToProps = (state: RootState): BannerProps => ({
45 isOpen: state.banner.isOpen,
46 bannerUUID: state.auth.config.clusterConfig.Workbench.BannerUUID,
47 keepWebInlineServiceUrl: state.auth.config.keepWebInlineServiceUrl,
50 const mapDispatchToProps = (dispatch: Dispatch) => ({
51 openBanner: () => dispatch<any>(bannerActions.openBanner()),
52 closeBanner: () => dispatch<any>(bannerActions.closeBanner()),
55 export const BANNER_LOCAL_STORAGE_KEY = "bannerFileData";
57 export const BannerComponent = (props: BannerComponentProps) => {
58 const { isOpen, openBanner, closeBanner, bannerUUID, keepWebInlineServiceUrl } = props;
59 const [bannerContents, setBannerContents] = useState(`<h1>Loading ...</h1>`);
61 const onConfirm = useCallback(() => {
66 if (!!bannerUUID && bannerUUID !== "") {
70 .collectionService.files(bannerUUID)
72 const bannerFileData = results.find(({ name }) => name === "banner.html");
73 const result = localStorage.getItem(BANNER_LOCAL_STORAGE_KEY);
75 if (result && result === JSON.stringify(bannerFileData) && !isOpen) {
82 .collectionService.getFileContents(bannerFileData)
84 setBannerContents(data);
86 localStorage.setItem(BANNER_LOCAL_STORAGE_KEY, JSON.stringify(bannerFileData));
91 console.error("Failed to load banner", e);
94 }, [bannerUUID, keepWebInlineServiceUrl, openBanner, isOpen]);
101 <div data-cy="confirmation-dialog">
102 <DialogContent className={props.classes.dialogContent}>
103 <div dangerouslySetInnerHTML={{ __html: sanitizeHTML(bannerContents) }}></div>
105 <DialogActions style={{ margin: "0px 24px 24px" }}>
107 data-cy="confirmation-dialog-ok-btn"
121 export const Banner = withStyles(styles)(connect(mapStateToProps, mapDispatchToProps)(BannerComponent));