Feat: put table's callback and layout in factory
This commit is contained in:
parent
612df0a8eb
commit
7fb7bc6f5c
@ -1,6 +1,7 @@
|
||||
import dash
|
||||
from dash import Dash, html, dcc
|
||||
from .pages import home, config, stage, schema, table
|
||||
from .datalake import stages
|
||||
|
||||
external_scripts = [
|
||||
{'src': 'https://cdn.tailwindcss.com'}
|
||||
@ -36,8 +37,9 @@ dash.register_page(
|
||||
dash.register_page(
|
||||
table.__name__,
|
||||
path_template='/stg/<stage_name>/schm/<schema_name>/table/<table_name>',
|
||||
layout=table.layout
|
||||
layout=table.layout_factory(stages)
|
||||
)
|
||||
table.callback_factory(app)
|
||||
|
||||
app.layout = html.Div([
|
||||
html.Div([
|
||||
|
@ -1,9 +1,8 @@
|
||||
from dash import html, dcc, dash_table, callback, Input, Output, State
|
||||
from dash import html, dcc, dash_table, Input, Output, State
|
||||
from dash.exceptions import PreventUpdate
|
||||
from ..datalake import stages
|
||||
from ..libs.stage.stage import AbstractStage
|
||||
|
||||
|
||||
def layout_factory(stages: list[AbstractStage]):
|
||||
def layout(stage_name=None, schema_name=None, table_name=None):
|
||||
stage = stages[stage_name]
|
||||
df = stage.read(table=table_name, schema=schema_name)
|
||||
@ -71,9 +70,11 @@ def layout(stage_name=None, schema_name=None, table_name=None):
|
||||
],
|
||||
className="p-2"
|
||||
)
|
||||
return layout
|
||||
|
||||
|
||||
@callback(
|
||||
def callback_factory(app):
|
||||
@app.callback(
|
||||
Output("datatable", 'editable', allow_duplicate=True),
|
||||
Output("table_backup", 'data'),
|
||||
Input("btn_edit", "n_clicks"),
|
||||
@ -88,9 +89,9 @@ def activate_editable(n_clicks, df_src):
|
||||
return True, df_backup
|
||||
raise PreventUpdate
|
||||
|
||||
@callback(
|
||||
Output("datatable", 'editable'),
|
||||
Output("datatable", 'data'),
|
||||
@app.callback(
|
||||
Output("datatable", 'editable', allow_duplicate=True),
|
||||
Output("datatable", 'data', allow_duplicate=True),
|
||||
Input("btn_cancel", "n_clicks"),
|
||||
State("table_backup", 'data'),
|
||||
prevent_initial_call=True
|
||||
@ -102,19 +103,20 @@ def cancel_modifications(n_clicks, data):
|
||||
return False, data.copy()
|
||||
raise PreventUpdate
|
||||
|
||||
# @callback(
|
||||
# Output("datatable", 'editable'),
|
||||
# Input("btn_save", "n_clicks"),
|
||||
# State("datatable", 'editable'),
|
||||
# )
|
||||
# def save_modifications(n_clicks, editable):
|
||||
# if n_clicks is None:
|
||||
# raise PreventUpdate
|
||||
# if n_clicks > 0:
|
||||
# return not editable
|
||||
# return editable
|
||||
@app.callback(
|
||||
Output("datatable", 'editable'),
|
||||
Output("datatable", 'data'),
|
||||
Input("btn_save", "n_clicks"),
|
||||
State("datatable", 'editable'),
|
||||
)
|
||||
def save_modifications(n_clicks, editable):
|
||||
if n_clicks is None:
|
||||
raise PreventUpdate
|
||||
if n_clicks > 0:
|
||||
return not editable
|
||||
return editable
|
||||
|
||||
@callback(
|
||||
@app.callback(
|
||||
Output("btn_edit", "style"),
|
||||
Output("btn_save", "style"),
|
||||
Output("btn_cancel", "style"),
|
||||
|
Loading…
Reference in New Issue
Block a user