Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'perspective-select' event to @finos/perspective-viewer-hypergrid #894

Merged
merged 2 commits into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/workspace/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
},
plugins: [
new HtmlWebPackPlugin({
title: "Phosphor Example"
title: "Workspace Example"
}),
new PerspectivePlugin({})
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default require("datasaur-local").extend("PerspectiveDataModel", {

pspFetch: async function(rect) {
const selection_enabled = this._grid.properties.rowSelection || this._viewer.hasAttribute("editable");
const range = pad_data_window(rect, this._config.row_pivots, this._viewer.hasAttribute("settings"), selection_enabled);
const range = pad_data_window(rect, this._config.row_pivots, selection_enabled);
const next_page = await this._view.to_columns(range);
this.data = [];
const rows = page2hypergrid(next_page, this._config.row_pivots, this._columns);
Expand Down
21 changes: 18 additions & 3 deletions packages/perspective-viewer-hypergrid/src/js/perspective-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,23 @@ export const install = function(grid) {
}

const filters = config.filter.concat(row_filters).concat(column_filters);
const action = this.grid.properties.rowSelection && this.grid.getSelectedRows().indexOf(y) === -1 ? "deselected" : "selected";

// this only works for single row select (which is all we support right now)
if (this.grid.properties.rowSelection) {
const selected = this.grid.getSelectedRows()[0] === y;
this.grid.canvas.dispatchEvent(
new CustomEvent("perspective-select", {
bubbles: true,
composed: true,
detail: {
selected,
config: {filters: selected ? filters : []},
column_names,
row: r[0]
}
})
);
}

this.grid.canvas.dispatchEvent(
new CustomEvent("perspective-click", {
Expand All @@ -333,8 +349,7 @@ export const install = function(grid) {
detail: {
config: {filters},
column_names,
row: r[0],
action
row: r[0]
}
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ utils.with_server({}, () => {
});
});
},
{reload_page: false, root: path.join(__dirname, "..", "..")}
{reload_page: true, root: path.join(__dirname, "..", "..")}
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"superstore_memoized_column_meta_should_reinterpret_metadata_when_only_row_pivots_are_changed": "dcb44e291c98a15c57a19523ff6a3cd8",
"superstore_resets_viewable_area_when_the_logical_size_expands_": "1bc04ce4ebdbbb8c59d8a04cea43c901",
"superstore_resets_viewable_area_when_the_physical_size_expands_": "13d3164f406bf6a7d053c21dd506a0d5",
"__GIT_COMMIT__": "12d6d9d08ccd26b8495eb52638bf55553d33d99b",
"__GIT_COMMIT__": "510a3095fcbcd7af3e7038b9290c6067a203ebe2",
"empty_perspective-click_is_fired_when_an_empty_dataset_is_loaded_first": "7e5b653226145e1ab9f82e2417d89d7b",
"hypergrid_clicking_on_a_cell_in_the_grid_when_no_filters_are_present_perspective_dispatches_perspective-click_event_with_correct_properties_": "13d3164f406bf6a7d053c21dd506a0d5",
"hypergrid_clicking_on_a_cell_in_the_grid_when_a_filter_is_present_perspective_dispatches_perspective-click_event_with_one_filter_": "b66684328af5084134b0d3ed8d095eaf",
Expand All @@ -39,9 +39,9 @@
"editable_editing_UI_saves_should_fail_to_save_edits_of_invalid_integers": "41a364e1cfed53b3bfcbde33978c236f",
"editable_editing_UI_saves_should_follow_the_indexed_row_when_the_data_updates": "1f9e8514f88efc7ad77f484c9ec6e344",
"selectable_no_pivots_selecting_a_row_highlights_the_row_with_no_pivots": "4c468ef10481f506c30155ee1b61829d",
"selectable_no_pivots_selecting_a_row_keeps_selection_when_row_moves_with_no_pivots": "08a10d12b2d7cf7a4a1108c92fcb221f",
"selectable_row_pivots_selecting_a_row_highlights_the_row_with_row_pivots": "338a7b0ee35e716dfedbac70b0a39b1d",
"selectable_row_pivots_selecting_a_row_keeps_selection_when_row_moves_with_row_pivots": "9ade48c0badce151c429678d42842ce5",
"selectable_no_pivots_selecting_a_row_keeps_selection_when_row_moves_with_no_pivots": "4891f7883567ea402bb2c711f1f16833",
"selectable_row_pivots_selecting_a_row_highlights_the_row_with_row_pivots": "fb3bd1dab64aafd859ae5a9703ab8b03",
"selectable_row_pivots_selecting_a_row_keeps_selection_when_row_moves_with_row_pivots": "db89db9abf083a9201b65a27731a2741",
"empty_empty_grids_do_not_explode": "e4be3f558cd6dcb391a4f21a28407b7f",
"regressions_Updates_should_not_render_an_extra_row_for_column_only_views": "93c5c1a79c0263069cb02c2dccd62add",
"regressions_Updates_regular_updates": "c519987a2a2179eb5b50fbcd99c87a95",
Expand Down
15 changes: 11 additions & 4 deletions packages/perspective-workspace/src/js/workspace/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export class PerspectiveWorkspace extends DiscreteSplitPanel {
table: this.getTable(widgetConfig.table),
config: {master: true, ...widgetConfig}
});
widget.viewer.addEventListener("perspective-click", this.onPerspectiveClick);
widget.viewer.addEventListener("perspective-select", this.onPerspectiveSelect);
widget.viewer.addEventListener("perspective-click", this.onPerspectiveSelect);
this.masterPanel.addWidget(widget);
});
layout.master.sizes && this.masterPanel.setRelativeSizes(layout.master.sizes);
Expand Down Expand Up @@ -217,8 +218,12 @@ export class PerspectiveWorkspace extends DiscreteSplitPanel {
}, this.dockpanel.saveLayout());
}

onPerspectiveClick = event => {
onPerspectiveSelect = event => {
const config = event.target.save();
// perspective-select is already handled for hypergrid
if (event.type === "perspective-click" && config.plugin === "hypergrid") {
return;
}
const candidates = new Set([...(config["row-pivots"] || []), ...(config["column-pivots"] || []), ...(config.filters || []).map(x => x[0])]);
const filters = [...event.detail.config.filters];
this.filterWidget(candidates, filters);
Expand All @@ -241,7 +246,8 @@ export class PerspectiveWorkspace extends DiscreteSplitPanel {

widget.selectable = true;
widget.viewer.restyleElement();
widget.viewer.addEventListener("perspective-click", this.onPerspectiveClick);
widget.viewer.addEventListener("perspective-click", this.onPerspectiveSelect);
widget.viewer.addEventListener("perspective-select", this.onPerspectiveSelect);
}

makeDetail(widget) {
Expand All @@ -256,7 +262,8 @@ export class PerspectiveWorkspace extends DiscreteSplitPanel {
}
widget.selectable = false;
widget.viewer.restyleElement();
widget.viewer.removeEventListener("perspective-click", this.onPerspectiveClick);
widget.viewer.removeEventListener("perspective-click", this.onPerspectiveSelect);
widget.viewer.removeEventListener("perspective-select", this.onPerspectiveSelect);
}

/*********************************************************************
Expand Down