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

fix(editors): Editors should work with undefined item properties #25

Merged
merged 2 commits into from
Jul 23, 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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,3 @@ yarn run test:watch
- [ ] Check why `DOM Purify` doesn't work in SF
- [ ] Search for any left "todo" in the entire solution
- [ ] The Pagination/Footer width is a little off sometime compare to the width of the grid container
- [ ] Check why we need to click twice on a Date Editor to get date picker to open when the date is initially empty
2 changes: 1 addition & 1 deletion packages/common/src/editors/autoCompleteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class AutoCompleteEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const data = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];
this._currentValue = data;
this._defaultTextValue = typeof data === 'string' ? data : data[this.labelName];
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/checkboxEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class CheckboxEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];
this.originalValue = value;
if (this.originalValue) {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/dateEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export class DateEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];
this.originalDate = value;
this.flatInstance.setDate(value);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/dualInputEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class DualInputEditor implements Editor {
const inputVarPosition = (position === 'leftInput') ? '_leftInput' : '_rightInput';
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

if (item && fieldName !== undefined && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const itemValue = (isComplexObject) ? getDescendantProperty(item, fieldName) : (item.hasOwnProperty(fieldName) ? item[fieldName] : '');
this[originalValuePosition] = itemValue;
if (this.editorParams[position].type === 'float') {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/floatEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class FloatEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];
this.originalValue = value;
const decPlaces = this.getDecimalPlaces();
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/integerEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class IntegerEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];
this.originalValue = (isNaN(value) || value === null || value === undefined) ? value : `${value}`;
this._input.value = `${this.originalValue}`;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/longTextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class LongTextEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName.indexOf('.') > 0;

if (item && fieldName !== undefined && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : item[fieldName];
this.defaultValue = value;
this._$textarea.val(this.defaultValue);
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/selectEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class SelectEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName !== undefined && fieldName.indexOf('.') > 0;

if (item && this.columnDef && fieldName !== undefined && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
// when it's a complex object, user could override the object path (where the editable object is located)
// else we use the path provided in the Field Column Definition
const objectPath = this.columnEditor && this.columnEditor.complexObjectPath || fieldName;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/sliderEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class SliderEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

if (item && fieldName && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
let value = (isComplexObject) ? getDescendantProperty(item, fieldName) : (item.hasOwnProperty(fieldName) && item[fieldName]);
if (value === '' || value === null || value === undefined) {
value = this.defaultValue; // load default value when item doesn't have any value
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/editors/textEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class TextEditor implements Editor {
// is the field a complex object, "address.streetNumber"
const isComplexObject = fieldName && fieldName.indexOf('.') > 0;

if (item && fieldName !== undefined && this.columnDef && (item.hasOwnProperty(fieldName) || isComplexObject)) {
if (item && fieldName !== undefined) {
const value = (isComplexObject) ? getDescendantProperty(item, fieldName) : (item.hasOwnProperty(fieldName) && item[fieldName] || '');
this.originalValue = value;
this._input.value = this.originalValue;
Expand Down
10 changes: 5 additions & 5 deletions packages/vanilla-bundle/src/components/slick-footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class SlickFooterComponent {

const itemCountElm = document.createElement('span');
itemCountElm.className = 'item-count';
itemCountElm.textContent = `${this.metrics?.itemCount ?? ''}`;
itemCountElm.textContent = `${this.metrics?.itemCount ?? '0'}`;

// last update elements
rightFooterElm.appendChild(lastUpdateElm);
Expand All @@ -133,18 +133,18 @@ export class SlickFooterComponent {
// total count element (unless hidden)
if (!this.customFooterOptions.hideTotalItemCount) {
const textOfElm = document.createElement('span');
textOfElm.textContent = ` ${this.customFooterOptions.metricTexts?.of ?? ''} `;
textOfElm.textContent = ` ${this.customFooterOptions.metricTexts?.of ?? 'of'} `;
rightFooterElm.appendChild(textOfElm);

const totalCountElm = document.createElement('span');
totalCountElm.className = 'total-count';
totalCountElm.textContent = `${this.metrics?.totalItemCount ?? ''} items`;
totalCountElm.textContent = `${this.metrics?.totalItemCount ?? '0'}`;

rightFooterElm.appendChild(totalCountElm);
}

const textItemsElm = document.createElement('span');
textItemsElm.textContent = ` ${this.customFooterOptions.metricTexts?.items ?? ''} `;
textItemsElm.textContent = ` ${this.customFooterOptions.metricTexts?.items ?? 'items'} `;
rightFooterElm.appendChild(textItemsElm);

return rightFooterElm;
Expand All @@ -153,7 +153,7 @@ export class SlickFooterComponent {
/** Create the Right Section Last Update Timestamp */
private createFooterLastUpdate(): HTMLSpanElement {
// get translated text & last timestamp
const lastUpdateText = this.customFooterOptions?.metricTexts?.lastUpdate ?? '';
const lastUpdateText = this.customFooterOptions?.metricTexts?.lastUpdate ?? 'Last Update';
const lastUpdateTimestamp = moment(this.metrics?.endTime).format(this.customFooterOptions.dateFormat);

const lastUpdateElm = document.createElement('span');
Expand Down