Skip to content
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
30 changes: 29 additions & 1 deletion packages/perspective-viewer-datagrid/src/js/editing.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ function write(table, model, active_cell) {
if (isNaN(text)) {
return false;
}
} else if (type === "boolean") {
text = text === "check" ? false : text === "close" ? true : null;
}

const msg = {
Expand Down Expand Up @@ -122,7 +124,20 @@ function editableStyleListener(table, viewer) {
}
const edit = isEditable.call(this, viewer);
for (const td of table.querySelectorAll("td")) {
td.toggleAttribute("contenteditable", edit);
const meta = table.getMeta(td);
const type = this.get_psp_type(meta);
if (this._is_editable[meta.x]) {
if (type === "boolean") {
td.toggleAttribute("contenteditable", false);
td.classList.toggle("boolean-editable", meta.user !== null);
} else {
td.toggleAttribute("contenteditable", edit);
td.classList.toggle("boolean-editable", false);
}
} else {
td.toggleAttribute("contenteditable", false);
td.classList.toggle("boolean-editable", false);
}
}
}

Expand Down Expand Up @@ -219,12 +234,25 @@ function focusinListener(table, viewer, event) {
}
}

function clickListener(table, _viewer, event) {
const meta = table.getMeta(event.target);
if (typeof meta?.x !== "undefined") {
const is_editable = this._is_editable[meta.x];
const is_bool = this.get_psp_type(meta) === "boolean";
const is_null = event.target.textContent === "-";
if (is_editable && is_bool && !is_null) {
write(table, this, event.target);
}
}
}

// Plugin

export async function configureEditable(table, viewer) {
this._edit_port = await viewer.getEditPort();
table.addStyleListener(editableStyleListener.bind(this, table, viewer));
table.addStyleListener(focusStyleListener.bind(this, table, viewer));
table.addEventListener("click", clickListener.bind(this, table, viewer));
table.addEventListener(
"focusin",
focusinListener.bind(this, table, viewer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,26 @@ function styleListener(regularTable) {
td.style.backgroundColor = "";
td.style.color = hex;
}
} else if (type === "boolean") {
const [hex] =
metadata.user === true
? this._pos_color
: metadata.user === false
? this._neg_color
: ["", 0, 0, 0, ""];

td.style.backgroundColor = "";
td.style.color = hex;
} else {
td.style.backgroundColor = "";
td.style.color = "";
}

td.classList.toggle(
"psp-bool-type",
type === "boolean" && metadata.user !== null
);

const is_th = td.tagName === "TH";
if (is_th) {
const is_not_empty =
Expand Down Expand Up @@ -233,17 +248,6 @@ function styleListener(regularTable) {
}
}

function get_psp_type(metadata) {
if (metadata.x >= 0) {
const column_path = this._column_paths[metadata.x];
const column_path_parts = column_path.split("|");
return this._schema[column_path_parts[column_path_parts.length - 1]];
} else {
const column_path = this._config.row_pivots[metadata.row_header_x - 1];
return this._table_schema[column_path];
}
}

async function sortHandler(regularTable, event, target) {
const meta = regularTable.getMeta(target);
const column_name = meta.column_header[meta.column_header.length - 1];
Expand Down Expand Up @@ -397,7 +401,7 @@ const FORMATTER_CONS = {
float: Intl.NumberFormat,
boolean: class {
format(val) {
return val.toString();
return val ? "check" : "close";
}
},
};
Expand Down Expand Up @@ -498,8 +502,9 @@ async function dataListener(regularTable, x0, y0, x1, y1) {
}

const data = [],
metadata = [];
const column_headers = [];
metadata = [],
column_headers = [];

for (const path of this._column_paths.slice(x0, x1)) {
const path_parts = path.split("|");
const column = columns[path] || new Array(y1 - y0).fill(null);
Expand Down Expand Up @@ -598,24 +603,44 @@ export async function createModel(regular, table, view, extend = {}) {
const _neg_color = create_color_record(
get_rule(regular, "--rt-neg-cell--color", "#FF5942")
);
const _schema = {...schema, ...expression_schema};
const _table_schema = {
...table_schema,
...validated_expressions.expression_schema,
};

const _column_paths = column_paths.filter((path) => {
return path !== "__ROW_PATH__" && path !== "__ID__";
});

const _is_editable = [];
const _column_types = [];
for (const column_path of _column_paths) {
const column_path_parts = column_path.split("|");
const column = column_path_parts[column_path_parts.length - 1];
_column_types.push(_schema[column]);
_is_editable.push(!!table_schema[column]);
}

const model = Object.assign(extend, {
_view: view,
_table: table,
_table_schema: {
...table_schema,
...validated_expressions.expression_schema,
},
_table_schema,
_config: config,
_num_rows: num_rows,
_schema: {...schema, ...expression_schema},
_schema,
_ids: [],
_open_column_styles_menu: [],
_plugin_background,
_pos_color,
_neg_color,
_column_paths: column_paths.filter((path) => {
return path !== "__ROW_PATH__" && path !== "__ID__";
_column_paths,
_column_types,
_is_editable,
_row_header_types: config.row_pivots.map((column_path) => {
return _table_schema[column_path];
}),
get_psp_type,
});

// Re-use div factory
Expand All @@ -625,6 +650,14 @@ export async function createModel(regular, table, view, extend = {}) {
return model;
}

function get_psp_type(metadata) {
if (metadata.x >= 0) {
return this._column_types[metadata.x];
} else {
return this._row_header_types[metadata.row_header_x - 1];
}
}

export async function configureRegularTable(regular, model) {
regular.addStyleListener(styleListener.bind(model, regular));
regular.addEventListener(
Expand Down
12 changes: 12 additions & 0 deletions packages/perspective-viewer-datagrid/src/less/regular_table.less
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ regular-table thead tr:last-child th {
border-left-width: 0px;
}

.psp-bool-type {
font-family: "Material Icons";
}

.boolean-editable {
cursor: pointer;
}

regular-table table {
user-select: none;
color: #161616;
Expand All @@ -162,6 +170,10 @@ regular-table table {
height: 23px;
}

.psp-header-group {
text-overflow: ellipsis;
}

.psp-header-leaf {
border-bottom-width: 0px;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"superstore_displays_visible_columns_": "d7cfabd1879d62859ce4fa057ed0a9d1",
"superstore_resets_viewable_area_when_the_logical_size_expands_": "e9dd1d275f46f6a0857e0168835d0b38",
"superstore_resets_viewable_area_when_the_physical_size_expands_": "e469597235cc032619bc095a76f9ad6f",
"__GIT_COMMIT__": "b279269baf54c6088d84d5ec1fc3b4664b22519d",
"__GIT_COMMIT__": "d6340a9ef5b4eae273567dd5f433fbea4171f8e9",
"superstore_shows_a_grid_without_any_settings_applied": "9ba7d100dc0f3e91a61668ac2f2ddabb",
"superstore_pivot_by_a_row": "9fdd64446ba41da3c7bd85191e20f946",
"superstore_pivot_by_two_rows": "2191bbeac5fd5fd5b53593e877561b14",
Expand Down
29 changes: 19 additions & 10 deletions rust/perspective-viewer/src/less/column-selector.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
@import "./aggregate-selector.less";

:host {

.column-selector-column-title {
display: flex;
width: 100%;
flex-direction: row !important;
}

#expression-columns .column-selector-column-title {
width: calc(100% - 24px);
}

#side_panel {
& > :not(:last-child) {
margin-bottom: 6px;
Expand Down Expand Up @@ -70,8 +81,7 @@
span.expression-edit-button,
span.expression-delete-button {
padding-left: 6px;
padding-right: 4px;
position: absolute;
padding-right: 0px;
font-family: "Material Icons";
cursor: pointer;
opacity: 1;
Expand All @@ -83,14 +93,6 @@
}
}

span.expression-edit-button {
right: 0px;
}

span.expression-delete-button {
right: 18px;
}

.column_selector_draggable {
display: flex;
align-items: start;
Expand Down Expand Up @@ -120,6 +122,7 @@
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
flex: 1 1 250px;
}

.column_name:before {
Expand Down Expand Up @@ -226,6 +229,11 @@
position: relative;
.column_selector_draggable {
width: calc(100% - 24px);

span.expression-edit-button {
margin-left: 18px;
}

}

&:before {
Expand Down Expand Up @@ -293,6 +301,7 @@

.column_selector_draggable {
border-bottom-color: transparent;
align-items: center;
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions rust/perspective-viewer/src/less/config-selector.less
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
white-space: nowrap;
}

span:first-child {
text-overflow: ellipsis;
max-width: 250px;
overflow: hidden;
}

// Column is being dragged-over, e.g. this is the drop indicator.
&.config-drop {
display: inline;
Expand Down
10 changes: 9 additions & 1 deletion rust/perspective-viewer/src/less/viewer.less
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
position: absolute;
top: 0;
left: 0;
padding: var(--button--padding, 12px 14px 24px 8px);
padding: var(--settings-button--padding, 15px 8px);
overflow: hidden;
display: flex;
align-items: center;
Expand All @@ -169,4 +169,12 @@
content: var(--settings-button--content, "\1f527");
}
}

.split-panel {
.split-panel-child {
&:first-child:not(.is-width-override) {
max-width: 250px;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ impl Component for ActiveColumn {
ondragstart={ dragstart }
ondragend={ self.props.ondragend.clone() }>

<span>
<span class="column-selector-column-title">
<span
ref={ noderef.clone() }
class={ format!("column_name {}", col_type) }>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,15 @@ impl Component for SplitPanel {
SplitPanelMsg::Reset
});

let class = if style.is_some() {
"split-panel-child is-width-override"
} else {
"split-panel-child"
};

html! {
<div id={ self.props.id.clone() } class="split-panel">
<div class="split-panel-child" ref={ _ref } style={ style }>
<div class={ class } ref={ _ref } style={ style }>
{ iter.next().unwrap() }
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Component for InactiveColumn {
onmousedown={ add_column }>
</span>
<div
class="column_selector_draggable"
class="column_selector_draggable column-selector-column-title"
draggable="true"
ref={ self.add_expression_ref.clone() }
ondragstart={ dragstart }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
--side_panel--padding: 12px 4px 12px 8px;
--top_panel--padding: 0px 0px 12px 0px;
--column-drop-label--margin: -10px 0px 0px 0px;
--button--padding: 12px 8px;
--settings-button--padding: 15px 8px;
--column-drop-label--font-size: 8px;
--column_selector--width: 24px;
}
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/themes/material-dense.less
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
--side_panel--padding: 12px 4px 12px 8px;
--top_panel--padding: 0px 0px 12px 0px;
--column-drop-label--margin: -10px 0px 0px 0px;
--button--padding: 12px 9px;
--settings-button--padding: 15px 8px;
--column-drop-label--font-size: 8px;
--column_selector--width: 24px;
}
Expand Down
2 changes: 1 addition & 1 deletion rust/perspective-viewer/src/themes/material.less
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ perspective-expression-editor {
--column_selector--font-size: 16px;

--side_panel--padding: 24px 16px 24px 17px;
--button--padding: 24px 17px 0px 17px;
--settings-button--padding: 24px 17px 0px 17px;
--button--font-size: 16px;

--top_panel--padding: 12px 0px 24px 0px;
Expand Down
Loading