/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React, { useHistory } from "react-router-dom"; import Link from "../components/Link"; import { usePublicHomepageSearch } from "../hooks"; import { useTranslation } from "react-i18next"; import UtilsService from "../services/UtilsService"; import Search from "../components/Search"; import { LocationState, PublicTopicArea, PublicDashboard, Dashboard } from "../models"; import Spinner from "../components/Spinner"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faArrowLeft, faArrowRight } from "@fortawesome/free-solid-svg-icons"; import MarkdownRender from "../components/MarkdownRender"; import dayjs from "dayjs"; import LocalizedFormat from "dayjs/plugin/localizedFormat"; import "./Home.scss"; import "../styles/base.scss"; dayjs.extend(LocalizedFormat); function HomeWithSearch() { const params = new URLSearchParams(window.location.search); const query = params.get("q"); const { homepage, loading } = usePublicHomepageSearch(query as string); const { t } = useTranslation(); const history = useHistory(); const topicareas = UtilsService.groupByTopicArea(homepage.dashboards); // Sort topic areas and their dashboards in ascending alphabetical order. topicareas.sort((a: PublicTopicArea, b: PublicTopicArea) => a.name.localeCompare(b.name)); for (let topicArea of topicareas) { topicArea.dashboards?.sort((a: PublicDashboard, b: PublicDashboard) => a.name.localeCompare(b.name), ); } const onSearch = (query: string) => { history.push("/public/search?q=" + query); }; const onClear = () => { history.push("/"); }; const getDashboardLink = (dashboard: PublicDashboard | Dashboard): string => { const link = dashboard.friendlyURL ? dashboard.friendlyURL : dashboard.id; return "/" + link; }; return loading ? ( ) : (
{t("AllDashboardsLink")}

{homepage.title}

{query === "" ? t("Search.EnterSearchTerm") + "." : ""}

{t("Search.SearchResults")}

{homepage.dashboards.length} dashboard(s) contain "{query}"  
{topicareas.map((topicarea) => (
    {topicarea.dashboards?.map((dashboard) => { return (
  • {topicarea.name}
    {dashboard.name}
    {t("Updated") + " " + dayjs(dashboard.updatedAt).fromNow()}
    {dashboard.queryMatches?.map((queryMatch) => { return (

    {" "} ... {queryMatch} ...

    ); })}
  • ); })}
))}
); } export default HomeWithSearch;