/* * SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. * * Any modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ /* * Licensed to Elasticsearch B.V. under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch B.V. licenses this file to you under * the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ import React, { FunctionComponent, createElement } from 'react'; import { RenderingMetadata } from '../types'; import { Fonts } from './fonts'; import { Styles } from './styles'; interface Props { metadata: RenderingMetadata; } export const Template: FunctionComponent = ({ metadata: { uiPublicUrl, locale, darkMode, themeVersion, injectedMetadata, i18n, bootstrapScriptUrl, strictCsp, }, }) => { const openSearchLogo = ( ); const openSearchLogoSpinner = ( ); const loadingLogoDefault = injectedMetadata.branding.loadingLogo?.defaultUrl; const loadingLogoDarkMode = injectedMetadata.branding.loadingLogo?.darkModeUrl; const markDefault = injectedMetadata.branding.mark?.defaultUrl; const markDarkMode = injectedMetadata.branding.mark?.darkModeUrl; const favicon = injectedMetadata.branding.faviconUrl; const applicationTitle = injectedMetadata.branding.applicationTitle; /** * Use branding configurations to check which URL to use for rendering * loading logo in default mode. In default mode, loading logo will * proritize default loading logo URL, and then default mark URL. * If both are invalid, default opensearch logo and spinner will be rendered. * * @returns a valid custom URL or undefined if no valid URL is provided */ const customLoadingLogoDefaultMode = () => { return loadingLogoDefault ?? markDefault ?? undefined; }; /** * Use branding configurations to check which URL to use for rendering * loading logo in default mode. In dark mode, loading logo will proritize * loading logo URLs, then mark logo URLs. * Within each type, the dark mode URL will be proritized if provided. * * @returns a valid custom URL or undefined if no valid URL is provided */ const customLoadingLogoDarkMode = () => { return loadingLogoDarkMode ?? loadingLogoDefault ?? markDarkMode ?? markDefault ?? undefined; }; /** * Render custom loading logo for both default mode and dark mode * * @returns a valid custom loading logo URL, or undefined */ const customLoadingLogo = () => { return darkMode ? customLoadingLogoDarkMode() : customLoadingLogoDefaultMode(); }; /** * Check if a horizontal loading is needed to be rendered. * Loading bar will be rendered only when a default mode mark URL or * dark mode mark URL is rendered as the loading logo. We add the * horizontal loading bar on the bottom of the static mark logo to have * some loading effect for the loading page. * * @returns a loading bar component or no loading bar component */ const renderBrandingEnabledOrDisabledLoadingBar = () => { if (customLoadingLogo() && !loadingLogoDefault) { return
; } }; /** * Check if we render a custom loading logo or the default opensearch spinner. * If customLoadingLogo() returns undefined(no valid custom URL is found), we * render the default opensearch logo spinenr * * @returns a image component with custom logo URL, or the default opensearch logo spinner */ const renderBrandingEnabledOrDisabledLoadingLogo = () => { if (customLoadingLogo()) { return (
{applicationTitle
); } return openSearchLogoSpinner; }; return ( {applicationTitle} {/** * Favicons (generated from https://realfavicongenerator.net/) * * For user customized favicon using yml file: * If user inputs a valid URL, we gurantee basic favicon customization, such as * browser favicon(Chrome, Firefox, Safari, and Edge), apple touch icon, safari * pinned icon. (For Safari browser favicon, we recommend input a png image URL, * svg image URL might not work) * * we do not guarantee other advanced favicon customization such as * windows tile icon, Andriod device favicon etc. However, the opensearch favicon * will not be shown at those places and the default browser/device icon will be shown instead. * * If user inputs a invalid URL, original opensearch favicon will be used. */} {/* Inject stylesheets into the before scripts so that KP plugins with bundled styles will override them */} {/* Place fonts after styles that would be injected later to make sure nothing overrides them */} {createElement('osd-csp', { data: JSON.stringify({ strictCsp }), })} {createElement('osd-injected-metadata', { data: JSON.stringify(injectedMetadata) })}
{renderBrandingEnabledOrDisabledLoadingLogo()}
{i18n('core.ui.welcomeMessage', { defaultMessage: `Loading ${injectedMetadata.branding.applicationTitle}`, })}
{renderBrandingEnabledOrDisabledLoadingBar()}
{openSearchLogo}

{i18n('core.ui.legacyBrowserTitle', { defaultMessage: 'Please upgrade your browser', })}

{i18n('core.ui.legacyBrowserMessage', { defaultMessage: 'This OpenSearch installation has strict security requirements enabled that your current browser does not meet.', })}