From 74882ae57234d297ff95502a8b3cbace101c605b Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sun, 28 Jul 2024 12:29:14 +0200 Subject: [PATCH] Feat: add navigation --- dashboard/components/__init__.py | 0 dashboard/components/lists.py | 55 +++++++++++++++++++++++++++++++ dashboard/pages/home.py | 56 +------------------------------- dashboard/pages/schema.py | 19 +++++++++-- dashboard/pages/stage.py | 14 ++++++-- dashboard/pages/table.py | 25 +++++++++++--- 6 files changed, 104 insertions(+), 65 deletions(-) create mode 100644 dashboard/components/__init__.py create mode 100644 dashboard/components/lists.py diff --git a/dashboard/components/__init__.py b/dashboard/components/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dashboard/components/lists.py b/dashboard/components/lists.py new file mode 100644 index 0000000..88235c4 --- /dev/null +++ b/dashboard/components/lists.py @@ -0,0 +1,55 @@ +from ..libs.stage.stage import AbstractStage +from dash import html, dcc + +def html_list_schema(stage:AbstractStage, with_tables=True): + """ Build html list of schema in stage """ + ul_classes = "ml-2" + schema_baseurl = f"/stg/{stage.name}/schema/" + if with_tables: + return html.Ul( + [ + html.Li( + children = [ + dcc.Link( + schema, + href=schema_baseurl + schema, + className="text-lg hover:underline" + ), + html_list_table(stage, schema) + ], + className="" + ) for schema in stage.schemas() + ], + className=ul_classes + ) + return html.Ul( + [ + html.Li( + dcc.Link( + schema, + href=schema_baseurl + schema, + className="text-lg hover:underline" + ), + ) for schema in stage.schemas() + ], + className=ul_classes + ) + + +def html_list_table(stage:AbstractStage, schema:str): + """ Build html list of table in stage """ + table_baseurl = f"/stg/{stage.name}/schm/{schema}/table/" + return html.Ul( + [ + html.Li( + dcc.Link( + table, + href=table_baseurl + table, + className="hover:underline" + ), + ) for table in stage.tables(schema=schema) + ], + className="ml-4" + ) + + diff --git a/dashboard/pages/home.py b/dashboard/pages/home.py index 589a873..506fd51 100644 --- a/dashboard/pages/home.py +++ b/dashboard/pages/home.py @@ -1,60 +1,6 @@ from dash import html, dcc from ..datalake import stages -from ..libs.stage.stage import AbstractStage - - -def html_list_schema(stage:AbstractStage, with_tables=True): - """ Build html list of schema in stage """ - ul_classes = "ml-2" - schema_baseurl = f"/stg/{stage.name}/schema/" - if with_tables: - return html.Ul( - [ - html.Li( - children = [ - dcc.Link( - schema, - href=schema_baseurl + schema, - className="text-lg text-bold" - ), - html_list_table(stage, schema) - ], - className="" - ) for schema in stage.schemas() - ], - className=ul_classes - ) - return html.Ul( - [ - html.Li( - dcc.Link( - schema, - href=schema_baseurl + schema, - className="text-lg text-bold" - ), - ) for schema in stage.schemas() - ], - className=ul_classes - ) - - - -def html_list_table(stage:AbstractStage, schema:str): - """ Build html list of table in stage """ - table_baseurl = f"/stg/{stage.name}/schm/{schema}/table/" - return html.Ul( - [ - html.Li( - dcc.Link( - table, - href=table_baseurl + table, - className="text-lg text-bold" - ), - ) for table in stage.tables(schema=schema) - ], - className="ml-4" - ) - +from ..components.lists import html_list_schema layout = html.Div([ diff --git a/dashboard/pages/schema.py b/dashboard/pages/schema.py index 2464716..29230e7 100644 --- a/dashboard/pages/schema.py +++ b/dashboard/pages/schema.py @@ -1,11 +1,24 @@ -from dash import html +from dash import html, dcc from ..datalake import stages from ..libs.stage.stage import AbstractStage def layout(stage_name=None, schema_name=None): + stage = stages[stage_name] return html.Div([ - html.H2(f"Stage - {stage_name}"), - html.H3(f"Schema - {schema_name}"), + html.H2([ + dcc.Link( + f"{stage.name}", + href=f"/stage/{stage.name}", + className="hover:underline" + ), + html.Span(" > "), + html.Span( + f"{schema_name}", + ), + ], + className="text-2xl p-4 py-2" + + ), ]) diff --git a/dashboard/pages/stage.py b/dashboard/pages/stage.py index a89b179..9bb42c7 100644 --- a/dashboard/pages/stage.py +++ b/dashboard/pages/stage.py @@ -1,10 +1,18 @@ -from dash import html +from dash import html, dcc from ..datalake import stages from ..libs.stage.stage import AbstractStage +from ..components.lists import html_list_schema def layout(stage_name=None): stage = stages[stage_name] return html.Div([ - html.H2(f"Stage - {stage_name}") - ]) + + html.H2( + f"{stage.name}", + className="text-2xl p-4 py-2" + ), + html_list_schema(stage) + ], + className = "flex flex-col" + ) diff --git a/dashboard/pages/table.py b/dashboard/pages/table.py index 9d6a002..be11baf 100644 --- a/dashboard/pages/table.py +++ b/dashboard/pages/table.py @@ -1,13 +1,30 @@ -from dash import html +from dash import html, dcc from ..datalake import stages from ..libs.stage.stage import AbstractStage def layout(stage_name=None, schema_name=None, table_name=None): + stage = stages[stage_name] return html.Div([ - html.H2(f"Stage - {stage_name}"), - html.H3(f"Schema - {schema_name}"), - html.H4(f"Table - {table_name}"), + html.H2([ + dcc.Link( + f"{stage.name}", + href=f"/stage/{stage.name}", + className="hover:underline" + ), + html.Span(" > "), + dcc.Link( + f"{schema_name}", + href=f"/stg/{stage.name}/schema/{schema_name}", + className="hover:underline" + ), + html.Span(" > "), + html.Span(table_name), + ], + className="text-2xl p-4 py-2" + + ), ]) +