Skip to content

Commit

Permalink
updating tooltip to not show if errors are present, adding a updateVa…
Browse files Browse the repository at this point in the history
…lidationHelper to the datatable for external validation needs
  • Loading branch information
tnrich committed Dec 14, 2023
1 parent 839633a commit 6fe19f8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/ui",
"version": "0.3.60",
"version": "0.3.62",
"main": "./src/index.js",
"exports": {
".": {
Expand Down
42 changes: 24 additions & 18 deletions packages/ui/src/DataTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class DataTable extends React.Component {
constructor(props) {
super(props);
if (this.props.helperProp) {
this.props.helperProp.updateValidationHelper =
this.updateValidationHelper;
this.props.helperProp.addEditableTableEntities =
this.addEditableTableEntities;
this.props.helperProp.getEditableTableInfoAndThrowFormError =
Expand Down Expand Up @@ -797,18 +799,21 @@ class DataTable extends React.Component {
});
}
};
updateValidationHelper = () => {
const { entities, reduxFormCellValidation } = computePresets(this.props);
this.updateValidation(entities, reduxFormCellValidation);
};

updateValidation = (entities, newCellValidate) => {
const { change, schema } = computePresets(this.props);
change(
"reduxFormCellValidation",
validateTableWideErrors({
entities,
schema,
newCellValidate,
props: this.props
})
);
const tableWideErr = validateTableWideErrors({
entities,
schema,
newCellValidate,
props: this.props
});
change("reduxFormCellValidation", tableWideErr);
this.forceUpdate();
};
handleDeleteCell = () => {
const {
Expand Down Expand Up @@ -1246,8 +1251,8 @@ class DataTable extends React.Component {
compactClassName += extraCompact
? " tg-extra-compact-table"
: compact
? " tg-compact-table"
: "";
? " tg-compact-table"
: "";

const hasFilters =
filters.length ||
Expand Down Expand Up @@ -1536,10 +1541,10 @@ class DataTable extends React.Component {
const nextCellId = up
? cellIdAbove
: down
? cellIdBelow
: left
? cellIdToLeft
: cellIdToRight;
? cellIdBelow
: left
? cellIdToLeft
: cellIdToRight;

e.stopPropagation();
e.preventDefault();
Expand Down Expand Up @@ -1747,8 +1752,8 @@ class DataTable extends React.Component {
extraCompact
? itemSizeEstimators.compact
: compact
? itemSizeEstimators.normal
: itemSizeEstimators.comfortable
? itemSizeEstimators.normal
: itemSizeEstimators.comfortable
}
TfootComponent={() => {
return <button>hasdfasdf</button>;
Expand Down Expand Up @@ -2029,7 +2034,8 @@ class DataTable extends React.Component {
this.startCellEdit(cellId);
},
...(err && {
"data-tip": err?.message || err
"data-tip": err?.message || err,
"data-no-child-data-tip": true
}),
onContextMenu: e => {
if (!isPrimarySelected) {
Expand Down
13 changes: 11 additions & 2 deletions packages/ui/src/autoTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ let clearMe;
dataTitle && !recentlyHidden
? [1300, 1300]
: dataTitle
? [150, 150]
: [0, 0],
? [150, 150]
: [0, 0],
allowHTML: true,
...(dataTitle && {
followCursor: dataTitle ? "initial" : false
Expand Down Expand Up @@ -171,6 +171,7 @@ let clearMe;
isEllipsized &&
el.offsetWidth < el.scrollWidth - 4 && //the -4 is adding a teeny bit of tolerance to fix issues with the column headers getting tooltips even when fully visible
!el.classList.contains("no-data-tip") &&
!parentIncludesNoChildDataTip(el, 0) &&
!document.body.classList.contains("drag-active") &&
el.textContent &&
el.textContent?.trim?.().length !== 0
Expand All @@ -189,3 +190,11 @@ let clearMe;
}
});
})();

function parentIncludesNoChildDataTip(el, count) {
if (count > 4) return false;
if (!el) return false;
// if attr data-no-child-data-tip is preset on the element, then we don't want to show a tooltip on any of its children
if (el.getAttribute("data-no-child-data-tip")) return true;
return parentIncludesNoChildDataTip(el.parentElement, count + 1);
}

0 comments on commit 6fe19f8

Please sign in to comment.