Skip to content

Commit

Permalink
#254: Fixes for disabling actions
Browse files Browse the repository at this point in the history
  • Loading branch information
aschonfeld authored and aschonfeld committed Jun 15, 2022
1 parent 484d109 commit 26be909
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 10 deletions.
8 changes: 4 additions & 4 deletions dtale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@

dtale = Blueprint("dtale", __name__, url_prefix="/dtale")

ALLOW_CELL_EDITS = True
HIDE_SHUTDOWN = False
GITHUB_FORK = False

# flake8: NOQA
from dtale.app import show, get_instance, instances, offline_chart # isort:skip
from dtale.cli.loaders import LOADERS # isort:skip
from dtale.cli.clickutils import retrieve_meta_info_and_version
from dtale.global_state import update_id # isort:skip

ALLOW_CELL_EDITS = True
HIDE_SHUTDOWN = False
GITHUB_FORK = False

for loader_name, loader in LOADERS.items():
if hasattr(loader, "show_loader"):
globals()["show_{}".format(loader_name)] = loader.show_loader
Expand Down
1 change: 1 addition & 0 deletions dtale/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ def show(data=None, data_loader=None, name=None, context_vars=None, **options):
vertical_headers=final_options["vertical_headers"],
is_proxy=JUPYTER_SERVER_PROXY,
app_root=final_app_root,
hide_shutdown=final_options.get("hide_shutdown"),
)
instance.started_with_open_browser = final_options["open_browser"]
is_active = not running_with_flask_debug() and is_up(app_url)
Expand Down
6 changes: 4 additions & 2 deletions dtale/global_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
except ImportError:
from collections import MutableMapping


APP_SETTINGS = {
"theme": "light",
"pin_menu": False,
Expand Down Expand Up @@ -397,11 +396,14 @@ def update_id(old_data_id, new_data_id):
def load_flag(data_id, flag_name, default):
import dtale

app_settings = get_app_settings()
curr_settings = get_settings(data_id) or {} # noqa: F821
global_flag = getattr(dtale, flag_name.upper())
if global_flag != default:
return global_flag
return curr_settings.get(flag_name, default)
if flag_name in app_settings and app_settings[flag_name] != default:
return app_settings[flag_name]
return curr_settings.get(flag_name, app_settings.get(flag_name, default))


def _as_dict(store):
Expand Down
18 changes: 16 additions & 2 deletions dtale/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ def startup(
app_root=None,
is_proxy=None,
vertical_headers=False,
hide_shutdown=False,
):
"""
Loads and stores data globally
Expand Down Expand Up @@ -1027,6 +1028,7 @@ def startup(
app_root=app_root,
is_proxy=is_proxy,
vertical_headers=vertical_headers,
hide_shutdown=hide_shutdown,
)

global_state.set_dataset(instance._data_id, data)
Expand Down Expand Up @@ -1080,6 +1082,8 @@ def startup(
data = sort_df_for_grid(data, dict(sort=sort))
if nan_display is not None:
base_settings["nanDisplay"] = nan_display
if hide_shutdown is not None:
base_settings["hide_shutdown"] = hide_shutdown
global_state.set_settings(data_id, base_settings)
if optimize_dataframe:
data = optimize_df(data)
Expand Down Expand Up @@ -1112,6 +1116,9 @@ def base_render_template(template, data_id, **kwargs):
curr_settings = global_state.get_settings(data_id) or {}
curr_app_settings = global_state.get_app_settings()
_, version = retrieve_meta_info_and_version("dtale")
hide_shutdown = global_state.load_flag(data_id, "hide_shutdown", False)
allow_cell_edits = global_state.load_flag(data_id, "allow_cell_edits", True)
github_fork = global_state.load_flag(data_id, "github_fork", False)
return render_template(
template,
data_id=data_id,
Expand All @@ -1120,13 +1127,20 @@ def base_render_template(template, data_id, **kwargs):
settings=json.dumps(curr_settings),
version=str(version),
processes=global_state.size(),
allow_cell_edits=global_state.load_flag(data_id, "allow_cell_edits", True),
python_version=platform.python_version(),
predefined_filters=json.dumps(
[f.asdict() for f in predefined_filters.get_filters()]
),
is_vscode=os.environ.get("VSCODE_PID") is not None,
**dict_merge(kwargs, curr_app_settings)
**dict_merge(
kwargs,
curr_app_settings,
dict(
allow_cell_edits=allow_cell_edits,
hide_shutdown=hide_shutdown,
github_fork=github_fork,
),
),
)


Expand Down
2 changes: 2 additions & 0 deletions frontend/static/dtale/export/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ require('../../publicPath');
const store = createAppStore<AppState>(appReducers);
store.dispatch(actions.init());
actions.loadBackgroundMode(store);
actions.loadHideShutdown(store);
actions.loadAllowCellEdits(store);
ReactDOM.render(
<Provider store={store}>
<ServerlessDataViewer response={(global as any).RESPONSE! as DataResponseContent} />
Expand Down
2 changes: 2 additions & 0 deletions frontend/static/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ let storeBuilder: () => Store = () => {
const store = createAppStore<AppState>(appReducers);
store.dispatch(actions.init());
actions.loadBackgroundMode(store);
actions.loadHideShutdown(store);
actions.loadAllowCellEdits(store);
return store;
};
if (pathname.indexOf('/dtale/popup') === 0) {
Expand Down
16 changes: 15 additions & 1 deletion frontend/static/redux/actions/AppActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export enum ActionType {
SET_QUERY_ENGINE = 'set-query-engine',
UPDATE_SHOW_ALL_HEATMAP_COLUMNS = 'update-show-all-heatmap-columns',
SET_RANGE_STATE = 'set-range-state',
UPDATE_HIDE_SHUTDOWN = 'update-hide-shutdown',
UPDATE_ALLOW_CELL_EDITS = 'update-allow-cell-edits',
}

/** Action fired when a range is selected */
Expand Down Expand Up @@ -215,6 +217,16 @@ export interface OpenChartAction extends Action<typeof ActionType.OPEN_CHART> {
chartData: Popups;
}

/** Action fired when updating the hide_shutdown flag */
export interface UpdateHideShutdown extends Action<typeof ActionType.UPDATE_HIDE_SHUTDOWN> {
value: boolean;
}

/** Action fired when updating the allow_cell_edits flag */
export interface UpdateAllowCellEdits extends Action<typeof ActionType.UPDATE_ALLOW_CELL_EDITS> {
value: boolean;
}

/** Type definition encompassing all application actions */
export type AppActionTypes =
| InitAction
Expand Down Expand Up @@ -253,7 +265,9 @@ export type AppActionTypes =
| SetQueryEngineAction
| UpdateShowAllHeatmapColumnsAction
| OpenChartAction
| SetRangeStateAction;
| SetRangeStateAction
| UpdateHideShutdown
| UpdateAllowCellEdits;

/** Type definition for redux application actions */
export type AppActions<R> = ThunkAction<R, AppState, Record<string, unknown>, AnyAction>;
10 changes: 10 additions & 0 deletions frontend/static/redux/actions/dtale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ export const loadBackgroundMode = (store: Store<AppState, AnyAction>): void => {
});
};

export const loadHideShutdown = (store: Store<AppState, AnyAction>): void => {
const { settings, hideShutdown } = store.getState();
store.dispatch({ type: ActionType.UPDATE_HIDE_SHUTDOWN, value: settings.hideShutdown ?? hideShutdown });
};

export const loadAllowCellEdits = (store: Store<AppState, AnyAction>): void => {
const { settings, allowCellEdits } = store.getState();
store.dispatch({ type: ActionType.UPDATE_ALLOW_CELL_EDITS, value: settings.allowCellEdits ?? allowCellEdits });
};

export const openCustomFilter = (): SidePanelAction => ({
type: ActionType.SHOW_SIDE_PANEL,
view: SidePanelType.FILTER,
Expand Down
4 changes: 4 additions & 0 deletions frontend/static/redux/reducers/app/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const hideShutdown = (state = false, action: AppActionTypes): boolean =>
switch (action.type) {
case ActionType.INIT_PARAMS:
return toBool(getHiddenValue('hide_shutdown'));
case ActionType.UPDATE_HIDE_SHUTDOWN:
return action.value;
case ActionType.LOAD_PREVIEW:
return true;
default:
Expand Down Expand Up @@ -51,6 +53,8 @@ export const allowCellEdits = (state = true, action: AppActionTypes): boolean =>
switch (action.type) {
case ActionType.INIT_PARAMS:
return toBool(getHiddenValue('allow_cell_edits'));
case ActionType.UPDATE_ALLOW_CELL_EDITS:
return action.value;
case ActionType.LOAD_PREVIEW:
return false;
default:
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ pandas
plotly==4.14.3; python_version < '3.6'
plotly>=5.0.0; python_version >= '3.6'
pyparsing==2.4.7; python_version == '2.7'
requests
requests; python_version >= '3.6'
requests==2.27.1; python_version == '2.7'
scikit-learn==0.20.4; python_version < '3.0'
scikit-learn==0.24.2; python_version == '3.6'
scikit-learn==1.0.2; python_version == '3.7'
Expand Down
5 changes: 5 additions & 0 deletions tests/dtale/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_startup(unittest):
dict(
allow_cell_edits=True,
columnFormats={},
hide_shutdown=False,
locked=["date", "security_id"],
precision=2,
sortInfo=[("security_id", "ASC")],
Expand Down Expand Up @@ -117,6 +118,7 @@ def test_startup(unittest):
dict(
allow_cell_edits=False,
columnFormats={},
hide_shutdown=False,
locked=[],
precision=6,
rangeHighlight=range_highlights,
Expand All @@ -135,6 +137,7 @@ def test_startup(unittest):
dict(
allow_cell_edits=True,
columnFormats={},
hide_shutdown=False,
locked=["security_id"],
precision=2,
rangeHighlight=None,
Expand All @@ -154,6 +157,7 @@ def test_startup(unittest):
locked=[],
precision=2,
columnFormats={},
hide_shutdown=False,
rangeHighlight=None,
backgroundMode=None,
verticalHeaders=False,
Expand All @@ -171,6 +175,7 @@ def test_startup(unittest):
locked=[],
precision=2,
columnFormats={},
hide_shutdown=False,
rangeHighlight=None,
backgroundMode=None,
verticalHeaders=False,
Expand Down

0 comments on commit 26be909

Please # to comment.