-
Notifications
You must be signed in to change notification settings - Fork 39
feat(headless): creation of headless attached citations controller #6843
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
base: SFINT-6550
Are you sure you want to change the base?
Conversation
| articlePublishStatus: ensureStringOrUndefined( | ||
| citation.fields?.sfpublishstatus | ||
| ), | ||
| isCitation: true, |
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.
will update this to isAttachedFromCitation
erocheleau
left a comment
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.
Some small suggestions, but otherwise almost ready to merge!
| const isCitation = attached.isCitation === true; | ||
|
|
||
| return ( | ||
| caseIdMatches && isCitation && (permanentIdMatches || uriHashMatches) |
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.
| caseIdMatches && isCitation && (permanentIdMatches || uriHashMatches) | |
| caseIdMatches && (permanentIdMatches || uriHashMatches) |
This is what we discussed right? No matter if it's a citation or not, it's attached.
| }); | ||
| }; | ||
|
|
||
| const getAttachedResultsForRecord = (): AttachedResult[] => { |
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 is something I would centralize in an accessor btw, we have the exact same code duplicated in the headless-attached-results.ts
export const selectAttachedResultsForCase =
(caseId: string) =>
(state: State): AttachedResult[] =>
state.attachedResults.results.filter((attached) => attached.caseId === caseId);
// And then use it like this:
const getAttachedResultsForRecord = (): AttachedResult[] =>
selectAttachedResultsForCase(caseId)(engine.state);
| ); | ||
| }; | ||
|
|
||
| const validateStringOrUndefined = (value: unknown): string | undefined => { |
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.
I believe Bueno exposes something for this already no?
| permanentId: citation.permanentid, | ||
| resultUrl: citation.clickUri ?? citation.uri, | ||
| title: citation.title, | ||
| uriHash: validateStringOrUndefined(citation.fields?.urihash), |
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.
These will include a bunch of undefined is that what you want?
{
uriHash: undefined,
source: undefined,
...
}
| const resultToAttach = buildAttachedResultFromCitation(citation); | ||
| dispatch(attachResult(resultToAttach)); |
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 omit the intermediate variable if you want, only if you want.
| const resultToAttach = buildAttachedResultFromCitation(citation); | |
| dispatch(attachResult(resultToAttach)); | |
| dispatch(attachResult(buildAttachedResultFromCitation(citation))); |
| return typeof value === 'string' ? value : undefined; | ||
| }; | ||
|
|
||
| const buildAttachedResultFromCitation = ( |
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.
I believe it's an anti-pattern to include this method here,
either you could use the exposed method from the actual component if it's exposed.
Or, you create the object you already expect and don't go through mapping.
Otherwise if the mapping changes in the actual component you have to maintain this part too.
What's important to test is the expectated values, so hardcode that expected value.
SFINT-6517
IN THIS PR:
It supports the following methods:
isAttached-> checks in the state if a citation document is attachedattach-> attaches a citation document to the attached results statedetach-> detaches a citation document from the attached results stateTEST: