C-Dash: Add search in tests
[csit.git] / csit.infra.dash / app / cdash / stats / layout.py
index ecd81ba..56b24e0 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2023 Cisco and/or its affiliates.
+# Copyright (c) 2024 Cisco and/or its affiliates.
 # Licensed 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:
@@ -29,7 +29,7 @@ from yaml import load, FullLoader, YAMLError
 from ..utils.constants import Constants as C
 from ..utils.control_panel import ControlPanel
 from ..utils.utils import show_tooltip, gen_new_url, get_ttypes, get_cadences, \
-    get_test_beds, get_job, generate_options, set_job_params
+    get_test_beds, get_job, generate_options, set_job_params, navbar_trending
 from ..utils.url_processing import url_decode
 from .graphs import graph_statistics, select_data
 
@@ -194,7 +194,11 @@ class Layout:
             "ri-ttypes-value": self._default["ttype"],
             "ri-cadences-value": self._default["cadence"],
             "dd-tbeds-value": self._default["tbed"],
-            "al-job-children": self._default["job"]
+            "al-job-children": html.A(
+                self._default["job"],
+                href=f"{C.URL_JENKINS}{self._default['job']}",
+                target="_blank"
+            )
         }
 
         # Callbacks:
@@ -229,9 +233,7 @@ class Layout:
                     dbc.Row(
                         id="row-navbar",
                         class_name="g-0",
-                        children=[
-                            self._add_navbar()
-                        ]
+                        children=[navbar_trending((False, False, True, False))]
                     ),
                     dbc.Spinner(
                         dbc.Offcanvas(
@@ -252,6 +254,18 @@ class Layout:
                             self._add_ctrl_col(),
                             self._add_plotting_col()
                         ]
+                    ),
+                    dbc.Offcanvas(
+                        class_name="w-75",
+                        id="offcanvas-documentation",
+                        title="Documentation",
+                        placement="end",
+                        is_open=False,
+                        children=html.Iframe(
+                            src=C.URL_DOC_TRENDING,
+                            width="100%",
+                            height="100%"
+                        )
                     )
                 ]
             )
@@ -268,31 +282,6 @@ class Layout:
                 ]
             )
 
-    def _add_navbar(self):
-        """Add nav element with navigation panel. It is placed on the top.
-
-        :returns: Navigation bar.
-        :rtype: dbc.NavbarSimple
-        """
-        return dbc.NavbarSimple(
-            id="navbarsimple-main",
-            children=[
-                dbc.NavItem(
-                    dbc.NavLink(
-                        C.STATS_TITLE,
-                        disabled=True,
-                        external_link=True,
-                        href="#"
-                    )
-                )
-            ],
-            brand=C.BRAND,
-            brand_href="/",
-            brand_external_link=True,
-            class_name="p-2",
-            fluid=True
-        )
-
     def _add_ctrl_col(self) -> dbc.Col:
         """Add column with controls. It is placed on the left side.
 
@@ -555,8 +544,8 @@ class Layout:
             Input("dd-tbeds", "value"),
             Input("url", "href")
         )
-        def _update_ctrl_panel(cp_data: dict, dut: str, ttype: str, cadence:str,
-                tbed: str, href: str) -> tuple:
+        def _update_ctrl_panel(cp_data: dict, dut: str, ttype: str,
+                cadence: str, tbed: str, href: str) -> tuple:
             """Update the application when the event is detected.
 
             :param cp_data: Current status of the control panel stored in
@@ -647,7 +636,14 @@ class Layout:
                                 "ri-ttypes-value": job_params["ttype"],
                                 "ri-cadences-value": job_params["cadence"],
                                 "dd-tbeds-value": job_params["tbed"],
-                                "al-job-children": job_params["job"]
+                                "al-job-children": html.A(
+                                    self._default["job"],
+                                    href=(
+                                        f"{C.URL_JENKINS}"
+                                        f"{self._default['job']}"
+                                    ),
+                                    target="_blank"
+                                )
                             },
                             None
                         )
@@ -662,7 +658,15 @@ class Layout:
                 ctrl_panel.get("dd-tbeds-value")
             )
 
-            ctrl_panel.set({"al-job-children": job})
+            ctrl_panel.set(
+                {
+                    "al-job-children": html.A(
+                        job,
+                        href=f"{C.URL_JENKINS}{job}",
+                        target="_blank"
+                    )
+                }
+            )
             plotting_area = self._get_plotting_area(
                 job,
                 gen_new_url(parsed_url, {"job": job})
@@ -780,11 +784,29 @@ class Layout:
                     fail_tests = None
 
                 # Create the content of the offcanvas:
+                list_group_items = list()
+                for itm in lst_graph_data:
+                    lst_itm = itm.split(": ")
+                    if lst_itm[0] == "csit-ref":
+                        list_group_item = dbc.ListGroupItem([
+                            dbc.Badge(lst_itm[0]),
+                            html.A(
+                                lst_itm[1],
+                                href=f"{C.URL_JENKINS}{lst_itm[1]}",
+                                target="_blank"
+                            )
+                        ])
+                    else:
+                        list_group_item = dbc.ListGroupItem([
+                            dbc.Badge(lst_itm[0]),
+                            lst_itm[1]
+                        ])
+                    list_group_items.append(list_group_item)
                 metadata = [
                     dbc.Card(
                         class_name="gy-2 p-0",
                         children=[
-                            dbc.CardHeader(children=[
+                            dbc.CardHeader([
                                 dcc.Clipboard(
                                     target_id="metadata",
                                     title="Copy",
@@ -793,21 +815,9 @@ class Layout:
                                 title
                             ]),
                             dbc.CardBody(
+                                dbc.ListGroup(list_group_items, flush=True),
                                 id="metadata",
-                                class_name="p-0",
-                                children=[dbc.ListGroup(
-                                    children=[
-                                        dbc.ListGroupItem(
-                                            [
-                                                dbc.Badge(
-                                                    x.split(":")[0]
-                                                ),
-                                                x.split(": ")[1]
-                                            ]
-                                        ) for x in lst_graph_data
-                                    ],
-                                    flush=True),
-                                ]
+                                class_name="p-0"
                             )
                         ]
                     )
@@ -839,3 +849,13 @@ class Layout:
                 open_canvas = True
 
             return metadata, open_canvas
+
+        @app.callback(
+            Output("offcanvas-documentation", "is_open"),
+            Input("btn-documentation", "n_clicks"),
+            State("offcanvas-documentation", "is_open")
+        )
+        def toggle_offcanvas_documentation(n_clicks, is_open):
+            if n_clicks:
+                return not is_open
+            return is_open