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 { Dialog, DialogContent, DialogActions, Button, StyleRulesCallback, withStyles, WithStyles } from "@material-ui/core";
7 import { connect } from "react-redux";
8 import { RootState } from "store/store";
9 import bannerActions from "store/banner/banner-action";
10 import { ArvadosTheme } from 'common/custom-theme';
11 import servicesProvider from 'common/service-provider';
12 import { Dispatch } from 'redux';
14 type CssRules = 'dialogContent' | 'dialogContentIframe';
16 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22 dialogContentIframe: {
28 interface BannerProps {
31 keepWebInlineServiceUrl: string;
34 type BannerComponentProps = BannerProps & WithStyles<CssRules> & {
36 closeBanner: Function,
39 const mapStateToProps = (state: RootState): BannerProps => ({
40 isOpen: state.banner.isOpen,
41 bannerUUID: state.auth.config.clusterConfig.Workbench.BannerUUID,
42 keepWebInlineServiceUrl: state.auth.config.keepWebInlineServiceUrl,
45 const mapDispatchToProps = (dispatch: Dispatch) => ({
46 openBanner: () => dispatch<any>(bannerActions.openBanner()),
47 closeBanner: () => dispatch<any>(bannerActions.closeBanner()),
50 export const BANNER_LOCAL_STORAGE_KEY = 'bannerFileData';
52 export const BannerComponent = (props: BannerComponentProps) => {
58 keepWebInlineServiceUrl
60 const [bannerContents, setBannerContents] = useState(`<h1>Loading ...</h1>`)
62 const onConfirm = useCallback(() => {
67 if (!!bannerUUID && bannerUUID !== "") {
68 servicesProvider.getServices().collectionService.files(bannerUUID)
70 const bannerFileData = results.find(({name}) => name === 'banner.html');
71 const result = localStorage.getItem(BANNER_LOCAL_STORAGE_KEY);
73 if (result && result === JSON.stringify(bannerFileData) && !isOpen) {
78 servicesProvider.getServices()
79 .collectionService.getFileContents(bannerFileData)
81 setBannerContents(data);
83 localStorage.setItem(BANNER_LOCAL_STORAGE_KEY, JSON.stringify(bannerFileData));
88 }, [bannerUUID, keepWebInlineServiceUrl, openBanner, isOpen]);
91 <Dialog open={isOpen}>
92 <div data-cy='confirmation-dialog'>
93 <DialogContent className={props.classes.dialogContent}>
94 <div dangerouslySetInnerHTML={{ __html: bannerContents }}></div>
96 <DialogActions style={{ margin: '0px 24px 24px' }}>
98 data-cy='confirmation-dialog-ok-btn'
111 export const Banner = withStyles(styles)(connect(mapStateToProps, mapDispatchToProps)(BannerComponent));