-
Notifications
You must be signed in to change notification settings - Fork 276
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
[sitecore-jss-react] [sitecore-jss-nextjs] Add support for chrome's hydration for fields #1773
Merged
Merged
Changes from 12 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
4aea79e
render field metadata for Text field component; introduce field metad…
yavorsk 5c4d4f9
rename FieldMetadata module, add unit test for Text component, add co…
yavorsk b23334a
add field metadata component to Date, Image and File field components…
yavorsk 889b81e
add field metadata component to link and richtext field components, i…
yavorsk a8591e9
update FieldMetadata interfaces to prevent build errors in sitecore-j…
yavorsk f5641e4
export fieldmetadata component and interfaces from sitecore-jss-react
yavorsk 5d16054
add metadata component for nextjs link field component; include unit …
yavorsk f8cfc3d
add field metadata component to nextimage component; small fix in lin…
yavorsk dcab12f
unit tests for FieldMetadata
yavorsk 64431fb
update unit test
yavorsk 6a05025
introduce getFieldMetadataMarkup function and used in the field compo…
yavorsk 2e3362c
update changelog
yavorsk 1141690
react - use higher order component to wrap metadata around field comp…
yavorsk 08df912
update nextjs components to use metadata wrapper hoc; aadjust unit tests
yavorsk 752506f
adjust unit tests and fix File component
yavorsk 03b9de9
adjust image field tests; include check for media property in metadat…
yavorsk ecc5d82
some types updates
yavorsk 4d23b39
some unit tests adjustments and metadata wrapper component update
yavorsk 0b05351
some FieldMetadata related renamings
yavorsk 46481cd
add unit test for RichText nextjs component
yavorsk cd24bb9
update changelog
yavorsk 0a5c3d5
update changelog pull request
yavorsk 77ccdcd
some type updates
yavorsk 6c74f77
reenable file tests
yavorsk d5dcd8d
update function description
yavorsk 69fe14b
minor variable renaming
yavorsk fcb38b9
remove unnecessary commented line
yavorsk 8c47f76
remove unnecessary undefined check
yavorsk 19333b2
move FieldMetada interfaces to base package; extract metadata proptypes
yavorsk 04afea6
move FieldMetadata under enchancments
yavorsk 6c63e83
Merge branch 'feature/JSS-1827' of https://github.com/Sitecore/jss in…
yavorsk 581527e
added some descriptions
yavorsk 32deed2
move and rename FieldMetadata to layout submodule of base package
yavorsk a0115fd
rename FieldMetadata component
yavorsk 8095600
add tsdoc description for fieldmetadata component
yavorsk d749ad9
conditionally forwardRef in fieldMetadata
yavorsk dde6878
two separate withFieldMetadata functions based on if used with forwar…
yavorsk 5cd3c75
single withFieldMetadata function with forwardref parameter
yavorsk 633e322
update with metadata unit test to test the whole structure of markup
yavorsk c12dbb8
withMetadata refactoring wip
yavorsk 13473fd
Adjusted withFieldMetadata generic type
illiakovalenko 9120a7b
update unit test
yavorsk e6252f6
wip - refactor field metadata hoc
yavorsk d5f49e9
Updates
illiakovalenko 6842fc8
Merge branch 'dev' of https://github.com/Sitecore/jss into feature/JS…
illiakovalenko 8277ee6
Updated unit tests, simplified types
illiakovalenko f8e8232
Update
illiakovalenko 15c9f40
Expose withFieldMetadata as a part of nextjs sdk
illiakovalenko bdbddd8
Updated PropTypes
illiakovalenko c86c0d2
Removed extra asserts
illiakovalenko 59cf116
remove media property from propTypes
yavorsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ import { | |||||
LinkField, | ||||||
LinkProps as ReactLinkProps, | ||||||
LinkPropTypes, | ||||||
getFieldMetadataMarkup, | ||||||
} from '@sitecore-jss/sitecore-jss-react'; | ||||||
|
||||||
export type LinkProps = ReactLinkProps & { | ||||||
|
@@ -22,6 +23,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>( | |||||
const { | ||||||
field, | ||||||
editable, | ||||||
metadata, | ||||||
children, | ||||||
internalLinkMatcher = /^\//g, | ||||||
showLinkTextWithChildrenPresent, | ||||||
|
@@ -35,6 +37,11 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>( | |||||
return null; | ||||||
} | ||||||
|
||||||
// when metadata is present, render it to be used for chrome hydration | ||||||
if (metadata) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to continue to respect the (user-defined)
Suggested change
|
||||||
return getFieldMetadataMarkup(metadata, children); | ||||||
} | ||||||
|
||||||
const value = ((field as LinkFieldValue).href | ||||||
? field | ||||||
: (field as LinkField).value) as LinkFieldValue; | ||||||
|
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
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
114 changes: 114 additions & 0 deletions
114
packages/sitecore-jss-react/src/components/FieldMetadata.test.tsx
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,114 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import React from 'react'; | ||
import { expect } from 'chai'; | ||
import { mount, render } from 'enzyme'; | ||
|
||
import { | ||
FieldMetadataComponent, | ||
FieldMetadataComponentProps, | ||
getFieldMetadataMarkup, | ||
} from './FieldMetadata'; | ||
import { describe } from 'node:test'; | ||
import { json } from 'stream/consumers'; | ||
|
||
describe('<FieldMetadataComponent />', () => { | ||
const testMetadata = { | ||
contextItem: { | ||
id: '{09A07660-6834-476C-B93B-584248D3003B}', | ||
language: 'en', | ||
revision: 'a0b36ce0a7db49418edf90eb9621e145', | ||
version: 1, | ||
}, | ||
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}', | ||
fieldType: 'single-line', | ||
rawValue: 'Test1', | ||
}; | ||
const stringifiedData = JSON.stringify(testMetadata); | ||
|
||
it('Should render provided metadata', () => { | ||
const props: FieldMetadataComponentProps = { | ||
data: stringifiedData, | ||
}; | ||
|
||
const rendered = mount(<FieldMetadataComponent {...props} />); | ||
|
||
expect(rendered.find('code')).to.have.length(2); | ||
expect(rendered.html()).to.contain('kind="open"'); | ||
expect(rendered.html()).to.contain('kind="close"'); | ||
expect(rendered.html()).to.include(stringifiedData); | ||
}); | ||
|
||
it('Should render with provided children', () => { | ||
const props: FieldMetadataComponentProps = { | ||
data: stringifiedData, | ||
}; | ||
|
||
const rendered = mount( | ||
<FieldMetadataComponent {...props}> | ||
<div>nested</div> | ||
</FieldMetadataComponent> | ||
); | ||
|
||
expect(rendered.find('code')).to.have.length(2); | ||
expect(rendered.find('div')).to.have.length(1); | ||
expect(rendered.html()).to.include('nested'); | ||
}); | ||
|
||
it('Should render with default attributes', () => { | ||
const props: FieldMetadataComponentProps = { | ||
data: stringifiedData, | ||
}; | ||
|
||
const rendered = mount(<FieldMetadataComponent {...props} />); | ||
|
||
expect(rendered.html()).to.contain('kind="open"'); | ||
expect(rendered.html()).to.contain('kind="close"'); | ||
expect(rendered.html()).to.contain('type="text/sitecore"'); | ||
expect(rendered.html()).to.contain('chrometype="field"'); | ||
expect(rendered.html()).to.contain('class="scpm"'); | ||
}); | ||
|
||
it('Should render with provided attributes', () => { | ||
const props: FieldMetadataComponentProps = { | ||
data: stringifiedData, | ||
htmlAttributes: { | ||
chrometype: 'foo', | ||
type: 'bar', | ||
className: 'far', | ||
}, | ||
}; | ||
|
||
const rendered = mount(<FieldMetadataComponent {...props} />); | ||
|
||
expect(rendered.html()).to.contain('kind="open"'); | ||
expect(rendered.html()).to.contain('kind="close"'); | ||
expect(rendered.html()).to.contain('type="bar"'); | ||
expect(rendered.html()).to.contain('chrometype="foo"'); | ||
expect(rendered.html()).to.contain('class="far"'); | ||
}); | ||
}); | ||
|
||
describe('getFieldMetadataMarkup', () => { | ||
it('Should render component with provided metadata and children ', () => { | ||
const testMetadata = { | ||
contextItem: { | ||
id: '{09A07660-6834-476C-B93B-584248D3003B}', | ||
language: 'en', | ||
revision: 'a0b36ce0a7db49418edf90eb9621e145', | ||
version: 1, | ||
}, | ||
fieldId: '{414061F4-FBB1-4591-BC37-BFFA67F745EB}', | ||
fieldType: 'single-line', | ||
rawValue: 'Test1', | ||
}; | ||
|
||
const div = <div>nested</div>; | ||
|
||
const rendered = mount(getFieldMetadataMarkup(testMetadata, div)); | ||
expect(rendered.find('code')).to.have.length(2); | ||
expect(rendered.html()).to.contain('kind="open"'); | ||
expect(rendered.html()).to.contain('kind="close"'); | ||
expect(rendered.html()).to.include(JSON.stringify(testMetadata)); | ||
expect(rendered.html()).to.include('<div>nested</div>'); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.