-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2618 from finos/datagrid-row-col-region-select
Add region, column and row selection modes to Perspective Datagrid
- Loading branch information
Showing
49 changed files
with
1,003 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
packages/perspective-viewer-datagrid/src/js/event_handlers/click.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ | ||
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ | ||
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ | ||
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ | ||
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ | ||
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ | ||
// ┃ Copyright (c) 2017, the Perspective Authors. ┃ | ||
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ | ||
// ┃ This file is part of the Perspective library, distributed under the terms ┃ | ||
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ | ||
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ | ||
|
||
import * as edit_click from "./click/edit_click.js"; | ||
import * as edit_keydown from "./keydown/edit_keydown.js"; | ||
|
||
export function is_editable(viewer, allowed = false) { | ||
const has_pivots = | ||
this._config.group_by.length === 0 && | ||
this._config.split_by.length === 0; | ||
const selectable = viewer.hasAttribute("selectable"); | ||
const editable = allowed || !!viewer.children[0]._is_edit_mode; | ||
return has_pivots && !selectable && editable; | ||
} | ||
|
||
export function keydownListener(table, viewer, selected_position_map, event) { | ||
if (this._edit_mode === "EDIT") { | ||
if (!is_editable.call(this, viewer)) { | ||
return; | ||
} | ||
|
||
edit_keydown.keydownListener.call( | ||
this, | ||
table, | ||
viewer, | ||
selected_position_map, | ||
event | ||
); | ||
} else { | ||
console.log( | ||
`Mode ${this._edit_mode} for "keydown" event not yet implemented` | ||
); | ||
} | ||
} | ||
|
||
export function clickListener(table, viewer, event) { | ||
if (this._edit_mode === "EDIT") { | ||
if (!is_editable.call(this, viewer)) { | ||
return; | ||
} | ||
|
||
edit_click.clickListener.call(this, table, viewer, event); | ||
} else if (this._edit_mode === "READ_ONLY") { | ||
} else if (this._edit_mode === "SELECT_COLUMN") { | ||
} else if (this._edit_mode === "SELECT_ROW") { | ||
} else if (this._edit_mode === "SELECT_REGION") { | ||
} else { | ||
console.log( | ||
`Mode ${this._edit_mode} for "click" event not yet implemented` | ||
); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/perspective-viewer-datagrid/src/js/event_handlers/click/edit_click.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ | ||
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃ | ||
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃ | ||
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃ | ||
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃ | ||
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫ | ||
// ┃ Copyright (c) 2017, the Perspective Authors. ┃ | ||
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃ | ||
// ┃ This file is part of the Perspective library, distributed under the terms ┃ | ||
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃ | ||
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ | ||
|
||
export function write_cell(table, model, active_cell) { | ||
const meta = table.getMeta(active_cell); | ||
const type = model._schema[model._column_paths[meta.x]]; | ||
if (meta) { | ||
let text = active_cell.textContent; | ||
const id = model._ids[meta.y - meta.y0][0]; | ||
if (type === "float" || type === "integer") { | ||
text = parseFloat(text.replace(/,/g, "")); | ||
if (isNaN(text)) { | ||
return false; | ||
} | ||
} else if (type === "date" || type === "datetime") { | ||
text = Date.parse(text); | ||
if (isNaN(text)) { | ||
return false; | ||
} | ||
} else if (type === "boolean") { | ||
text = text === "true" ? false : text === "false" ? true : null; | ||
} | ||
|
||
const msg = { | ||
__INDEX__: id, | ||
[model._column_paths[meta.x]]: text, | ||
}; | ||
|
||
model._table.update([msg], { port_id: model._edit_port }); | ||
return true; | ||
} | ||
} | ||
|
||
export function clickListener(table, _viewer, event) { | ||
const meta = table.getMeta(event.target); | ||
if (typeof meta?.x !== "undefined") { | ||
const is_editable2 = this._is_editable[meta.x]; | ||
const is_bool = this.get_psp_type(meta) === "boolean"; | ||
const is_null = event.target.textContent === "-"; | ||
if (is_editable2 && is_bool && !is_null) { | ||
write_cell(table, this, event.target); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.