-
Notifications
You must be signed in to change notification settings - Fork 78
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
Linked 2 components #446
Linked 2 components #446
Conversation
All the rendering for the resultLink is now done by the renderUri function, just like the PrintableUri. ResultLink initiates the render instead of PrintableUri. Since PrintableUri already has a renderUri function, it is the one that is used for rendering. Need to add code to handle added options from ResultLink. https://coveord.atlassian.net/browse/JSUI-1536
Not sure if PrintableUri needs to implement iComponentBindings. Also not sure if it's OK to always initiate the rendering from ResultLink. |
This fixed the issue where a PrintableUri with the AlwaysOpenInNewWindow option set to true would open the link in a new tab AND open the link in the current tab. https://coveord.atlassian.net/browse/JSUI-1536
results containing XML and results that don't now both use the same class for css. https://coveord.atlassian.net/browse/JSUI-1536
sass/_PrintableUri.scss
Outdated
@@ -1,21 +1,33 @@ | |||
@import "Variables"; | |||
|
|||
.CoveoPrintableUri{ | |||
.CoveoPrintableUri { | |||
justify-content:flex-start; |
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.
Use bourbon mixin.
@include justify-content(flex-start);
sass/_PrintableUri.scss
Outdated
font-size: $font-size-smallest; | ||
@include clickable(); | ||
padding: 0 2px 0 2px; | ||
display: flex; |
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.
Same, use bourbon mixin.
Basically, use bourbon mixin for every "flex" rules you are using.
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.
Using bourbon mixin on every flex rule, but I noticed that the ones for the flex-box have a deprecation warning. Leave them as is or use bourbon for that too ?
sass/_PrintableUri.scss
Outdated
.coveo-printable-uri-part { | ||
margin: 1px; | ||
//box-sizing: border-box; |
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.
remove comments.
sass/_PrintableUri.scss
Outdated
overflow: hidden; | ||
text-overflow: ellipsis; | ||
//display:inline-block; |
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.
Comments
src/ui/PrintableUri/PrintableUri.ts
Outdated
this.uri = result.clickUri; | ||
let stringAndHoles: StringAndHoles; | ||
if (result.printableUri.indexOf('\\') == -1) { | ||
stringAndHoles = StringAndHoles.shortenUri(result.printableUri, $$(element).width() / 7); |
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.
What's the / 7
purpose here ?
I understand it was there before, and you mostly imported the old implementation, but I would like if we had an explanation for this magic number/ a comment that explains why we are dividing by 7 like that.
src/ui/PrintableUri/PrintableUri.ts
Outdated
stringAndHoles = StringAndHoles.shortenPath(result.printableUri, $$(element).width() / 7); | ||
} | ||
this.shortenedUri = HighlightUtils.highlightString(stringAndHoles.value, result.printableUriHighlights, stringAndHoles.holes, 'coveo-highlight'); | ||
let link = $$('div'); |
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.
for this whole component, you can replace most of the let
by const
. Only when you need to re-assign a variable should you need to use const
. Once again, I know it was like that before, but we should always try to update/upgrade the codebase over time to use const when we can.
src/ui/PrintableUri/PrintableUri.ts
Outdated
} | ||
this.shortenedUri = HighlightUtils.highlightString(stringAndHoles.value, result.printableUriHighlights, stringAndHoles.holes, 'coveo-highlight'); | ||
let link = $$('div'); | ||
link.setAttribute('title', result.printableUri); |
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.
this can all be replaced with
$$('div', {
className : 'coveo-printable-uri-part',
href : result.clickUri,
title : result.printableUri
}
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.
This has not been changed :D
It should be modified to use the short hand method, instead of setting every attribute one by one.
test/ui/PrintableUriTest.ts
Outdated
|
||
it('should not modify the href template if there are no field specified', () => { | ||
let hrefTemplate = 'test'; | ||
test = Mock.optionsResultComponentSetup<PrintableUri, IResultLinkOptions>(PrintableUri, { hrefTemplate: hrefTemplate }, fakeResult); |
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.
IPrintableUriOptions
src/ui/PrintableUri/PrintableUri.ts
Outdated
let seperator = document.createElement('span'); | ||
seperator.innerText = '>'; | ||
seperator.innerText = ' > '; |
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.
innerText
is non-standard. You should use textContent
instead.
src/ui/PrintableUri/PrintableUri.ts
Outdated
let link = document.createElement('a'); | ||
this.bindLogOpenDocument(link); | ||
link.href = uri; | ||
let link = document.createElement('span'); |
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.
You can create elements in a more concise way using our $$
utilty function:
const link = $$('span', { className: 'coveo-printable-uri-part' }, modifiedName);
test/ui/PrintableUriTest.ts
Outdated
}); | ||
|
||
it('should display the XML correctly if the result has a very long parents field', () => { | ||
fakeResult.raw.parents = '<?xml version="1.0" encoding="utf-16"?><parents><parent name="Organization" uri="https://na17.salesforce.com/home/home.jsp" /><parent name="Technical_Article__ka" uri="http://www.salesforce.com/org:organization/articletype:Technical_Article" /><parent name="Generator became sentient and refuses to cut power" uri="https://na17.salesforce.com/kA0o00000003Wpk" /><parent name="un autre test" uri="http//:google.ca" /></parents>'; |
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.
Just a suggestion : you can use template strings using a backtick (`) to write multi-line strings. It makes the code look a bit better.
@@ -63,7 +63,7 @@ export function ResultLinkTest() { | |||
expect(window.open).toHaveBeenCalledWith(hrefTemplate, jasmine.anything()); | |||
}); | |||
|
|||
it('should replaces fields in the href template by the results equivalent', () => { | |||
it('should replace fields in the href template by the results equivalent', () => { |
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.
It should replaces hobbitses 😛
src/ui/PrintableUri/PrintableUri.ts
Outdated
@@ -17,7 +17,9 @@ export interface IPrintableUriOptions extends IResultLinkOptions { | |||
} | |||
|
|||
/** | |||
* The PrintableUri component displays the URI, or path, to access a result. | |||
* The PrintableUri component inherits from the ResultLink component and supports all of its options. |
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.
We should create a link in the documentation ( {@link ResultLink} )
@fbeaudoincoveo Any comments to add on this ?
I think we should
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.
src/ui/PrintableUri/PrintableUri.ts
Outdated
} | ||
this.shortenedUri = HighlightUtils.highlightString(stringAndHoles.value, result.printableUriHighlights, stringAndHoles.holes, 'coveo-highlight'); | ||
let link = $$('div'); | ||
link.setAttribute('title', result.printableUri); |
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.
This has not been changed :D
It should be modified to use the short hand method, instead of setting every attribute one by one.
src/ui/PrintableUri/PrintableUri.ts
Outdated
this.element.innerHTML = newTitle ? StreamHighlightUtils.highlightStreamText(newTitle, this.result.termsToHighlight, this.result.phrasesToHighlight) : this.result.clickUri; | ||
} | ||
} | ||
element.title = this.result.printableUri; | ||
} | ||
|
||
public buildSeparator() { | ||
let seperator = document.createElement('span'); | ||
seperator.innerText = ' > '; | ||
const seperator = document.createElement('span'); |
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.
This should use the short hand method also with $$('span', {className : 'coveo-rpintable-uri-separator'}, ' > ');
All the rendering for the resultLink is now done by the renderUri function, just like the PrintableUri. ResultLink initiates the render instead of PrintableUri. Since PrintableUri already has a renderUri function, it is the one that is used for rendering. Need to add code to handle added options from ResultLink.
https://coveord.atlassian.net/browse/JSUI-1536
This change is