Skip to content

Commit

Permalink
[sitecore-jss] isFieldValueEmpty can't handle null, undefined values (#…
Browse files Browse the repository at this point in the history
…1854)

* [sitecore-jss] isFieldValueEmpty can't handle null, undefined values

* Updated CHANGELOG
  • Loading branch information
illiakovalenko authored Jul 25, 2024
1 parent a4e8d9e commit b604ddd
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Our versioning strategy is as follows:

### 🛠 Breaking Change

* Editing Integration Support: ([#1776](https://github.com/Sitecore/jss/pull/1776))([#1792](https://github.com/Sitecore/jss/pull/1792))([#1773](https://github.com/Sitecore/jss/pull/1773))([#1797](https://github.com/Sitecore/jss/pull/1797))([#1800](https://github.com/Sitecore/jss/pull/1800))([#1803](https://github.com/Sitecore/jss/pull/1803))([#1806](https://github.com/Sitecore/jss/pull/1806))([#1809](https://github.com/Sitecore/jss/pull/1809))([#1814](https://github.com/Sitecore/jss/pull/1814))([#1816](https://github.com/Sitecore/jss/pull/1816))([#1819](https://github.com/Sitecore/jss/pull/1819))([#1828](https://github.com/Sitecore/jss/pull/1828))([#1835](https://github.com/Sitecore/jss/pull/1835)) ([#1849](https://github.com/Sitecore/jss/pull/1849))
* Editing Integration Support: ([#1776](https://github.com/Sitecore/jss/pull/1776))([#1792](https://github.com/Sitecore/jss/pull/1792))([#1773](https://github.com/Sitecore/jss/pull/1773))([#1797](https://github.com/Sitecore/jss/pull/1797))([#1800](https://github.com/Sitecore/jss/pull/1800))([#1803](https://github.com/Sitecore/jss/pull/1803))([#1806](https://github.com/Sitecore/jss/pull/1806))([#1809](https://github.com/Sitecore/jss/pull/1809))([#1814](https://github.com/Sitecore/jss/pull/1814))([#1816](https://github.com/Sitecore/jss/pull/1816))([#1819](https://github.com/Sitecore/jss/pull/1819))([#1828](https://github.com/Sitecore/jss/pull/1828))([#1835](https://github.com/Sitecore/jss/pull/1835))([#1849](https://github.com/Sitecore/jss/pull/1849))([#1831](https://github.com/Sitecore/jss/pull/1831))([#1854](https://github.com/Sitecore/jss/pull/1854))
* `[sitecore-jss-react]` Introduces `PlaceholderMetadata` component which supports the hydration of chromes on Pages by rendering the components and placeholders with required metadata.
* `[sitecore-jss]` Chromes are hydrated based on the basis of new `editMode` property derived from LayoutData, which is defined as an enum consisting of `metadata` and `chromes`.
* `ComponentConsumerProps` is removed. You might need to reuse `WithSitecoreContextProps` type.
Expand Down
32 changes: 32 additions & 0 deletions packages/sitecore-jss/src/layout/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,37 @@ describe('sitecore-jss layout utils', () => {
expect(result).to.be.false;
});
});

describe('null', () => {
it('should return true if field value is null', () => {
const field = {
value: null,
};
const result = isFieldValueEmpty(field);
expect(result).to.be.true;
});

it('should return true if value is null', () => {
const field = null;
const result = isFieldValueEmpty(field as any);
expect(result).to.be.true;
});
});

describe('undefined', () => {
it('should return true if field value is undefined', () => {
const field = {
value: undefined,
};
const result = isFieldValueEmpty(field);
expect(result).to.be.true;
});

it('should return true if value is undefined', () => {
const field = undefined;
const result = isFieldValueEmpty(field as any);
expect(result).to.be.true;
});
});
});
});
4 changes: 4 additions & 0 deletions packages/sitecore-jss/src/layout/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export function isFieldValueEmpty(field: GenericFieldValue | Partial<Field>): bo
const isDateFieldEmpty = (fieldValue: GenericFieldValue) => fieldValue === EMPTY_DATE_FIELD_VALUE;

const isEmpty = (fieldValue: GenericFieldValue) => {
if (fieldValue === null || fieldValue === undefined) {
return true;
}

if (typeof fieldValue === 'object') {
return (
isImageFieldEmpty(fieldValue) &&
Expand Down

0 comments on commit b604ddd

Please sign in to comment.