From d8f2fb52e13b69553812b8105bbc823c2e1af3a0 Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Sat, 27 Jul 2024 19:19:36 +0200 Subject: [PATCH] feat: organise router path --- dashboard/app.py | 29 ++++++++++++++++++++++++++--- dashboard/datalake.py | 8 ++++---- dashboard/libs/stage/fs_stage.py | 4 +++- dashboard/pages/home.py | 29 +++++++++++++++++++++-------- dashboard/pages/schema.py | 11 +++++++++++ dashboard/pages/stage.py | 10 ++++++++++ dashboard/pages/table.py | 13 +++++++++++++ 7 files changed, 88 insertions(+), 16 deletions(-) create mode 100644 dashboard/pages/schema.py create mode 100644 dashboard/pages/stage.py create mode 100644 dashboard/pages/table.py diff --git a/dashboard/app.py b/dashboard/app.py index 880325e..971fd8a 100644 --- a/dashboard/app.py +++ b/dashboard/app.py @@ -1,6 +1,6 @@ import dash from dash import Dash, html, dcc -from .pages import home, config +from .pages import home, config, stage, schema, table external_scripts = [ {'src': 'https://cdn.tailwindcss.com'} @@ -9,8 +9,31 @@ external_scripts = [ app = Dash(__name__, use_pages=True, external_scripts=external_scripts) app.scripts.config.serve_locally = True -dash.register_page(home.__name__, path='/', layout=home.layout) -dash.register_page(config.__name__, path='/config', layout=config.layout) +dash.register_page( + home.__name__, + path='/', + layout=home.layout, +) +dash.register_page( + config.__name__, + path='/config', + layout=config.layout +) +dash.register_page( + stage.__name__, + path_template='/stage/', + layout=stage.layout +) +dash.register_page( + schema.__name__, + path_template='/stg//schema/', + layout=schema.layout +) +dash.register_page( + table.__name__, + path_template='/stg//schm//table/', + layout=table.layout +) app.layout = html.Div([ html.Div([ diff --git a/dashboard/datalake.py b/dashboard/datalake.py index 9fff53f..346657e 100644 --- a/dashboard/datalake.py +++ b/dashboard/datalake.py @@ -6,8 +6,8 @@ env = { } stages = { - "raw": FSStage(f"{env['DATA_PATH']}/{env['RAW_SUBPATH']}"), - "staging": FSStage(f"{env['DATA_PATH']}/{env['STAGING_SUBPATH']}"), - "gold": FSStage(f"{env['DATA_PATH']}/{env['GOLD_SUBPATH']}"), - "mart": FSStage(f"{env['DATA_PATH']}/{env['MART_SUBPATH']}"), + "raw": FSStage("raw", f"{env['DATA_PATH']}/{env['RAW_SUBPATH']}"), + "staging": FSStage("staging", f"{env['DATA_PATH']}/{env['STAGING_SUBPATH']}"), + "gold": FSStage("gold", f"{env['DATA_PATH']}/{env['GOLD_SUBPATH']}"), + "mart": FSStage("mart", f"{env['DATA_PATH']}/{env['MART_SUBPATH']}"), } diff --git a/dashboard/libs/stage/fs_stage.py b/dashboard/libs/stage/fs_stage.py index a957d02..631487e 100644 --- a/dashboard/libs/stage/fs_stage.py +++ b/dashboard/libs/stage/fs_stage.py @@ -2,7 +2,9 @@ from .stage import AbstractStage from pathlib import Path class FSStage(AbstractStage): - def __init__(self, basepath, metadata_engine=None): + def __init__(self, name, basepath, metadata_engine=None): + self.name = name + self.basepath = Path(basepath) self._metadata_engine = metadata_engine diff --git a/dashboard/pages/home.py b/dashboard/pages/home.py index b5b9cbe..589a873 100644 --- a/dashboard/pages/home.py +++ b/dashboard/pages/home.py @@ -1,4 +1,4 @@ -from dash import html +from dash import html, dcc from ..datalake import stages from ..libs.stage.stage import AbstractStage @@ -6,13 +6,15 @@ 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 = [ - html.Span( + dcc.Link( schema, + href=schema_baseurl + schema, className="text-lg text-bold" ), html_list_table(stage, schema) @@ -25,9 +27,12 @@ def html_list_schema(stage:AbstractStage, with_tables=True): return html.Ul( [ html.Li( - schema, - className="text-lg text-bold" - ) for schema in stage.schemas() + dcc.Link( + schema, + href=schema_baseurl + schema, + className="text-lg text-bold" + ), + ) for schema in stage.schemas() ], className=ul_classes ) @@ -36,9 +41,16 @@ def html_list_schema(stage:AbstractStage, with_tables=True): 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(table) for table in stage.tables(schema=schema) + html.Li( + dcc.Link( + table, + href=table_baseurl + table, + className="text-lg text-bold" + ), + ) for table in stage.tables(schema=schema) ], className="ml-4" ) @@ -51,10 +63,11 @@ layout = html.Div([ children=[ html.Li( children=[ - html.Span( + dcc.Link( stagename, + href=f"/stage/{stagename}", className="text-2xl text-center p-2 bg-amber-100 rounded shadow" - ), + ), html_list_schema(stage) ], className="flex-1 bg-gray-100 rounded flex flex-col shadow" diff --git a/dashboard/pages/schema.py b/dashboard/pages/schema.py new file mode 100644 index 0000000..2464716 --- /dev/null +++ b/dashboard/pages/schema.py @@ -0,0 +1,11 @@ +from dash import html +from ..datalake import stages +from ..libs.stage.stage import AbstractStage + + +def layout(stage_name=None, schema_name=None): + return html.Div([ + html.H2(f"Stage - {stage_name}"), + html.H3(f"Schema - {schema_name}"), + ]) + diff --git a/dashboard/pages/stage.py b/dashboard/pages/stage.py new file mode 100644 index 0000000..a89b179 --- /dev/null +++ b/dashboard/pages/stage.py @@ -0,0 +1,10 @@ +from dash import html +from ..datalake import stages +from ..libs.stage.stage import AbstractStage + + +def layout(stage_name=None): + stage = stages[stage_name] + return html.Div([ + html.H2(f"Stage - {stage_name}") + ]) diff --git a/dashboard/pages/table.py b/dashboard/pages/table.py new file mode 100644 index 0000000..9d6a002 --- /dev/null +++ b/dashboard/pages/table.py @@ -0,0 +1,13 @@ +from dash import html +from ..datalake import stages +from ..libs.stage.stage import AbstractStage + + +def layout(stage_name=None, schema_name=None, table_name=None): + return html.Div([ + html.H2(f"Stage - {stage_name}"), + html.H3(f"Schema - {schema_name}"), + html.H4(f"Table - {table_name}"), + ]) + +