-
Notifications
You must be signed in to change notification settings - Fork 32
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
Me/dh/records published by my org #640
Conversation
2514f1b
to
b8b4dcc
Compare
Affected libs:
|
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.
Nicely done @cmoinier for this huge work.
I've let some comments, some debatable. Feel free to remove the comments either.
Maybe a nice things to have is a 'no record for this organisation/ no user for this organisation' placeholder instead of blank page.
apps/metadata-editor/src/app/my-org-users/my-org-users.component.ts
Outdated
Show resolved
Hide resolved
apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts
Outdated
Show resolved
Hide resolved
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.
Thanks Camille for those nice improvements ! If @jahow can tell us what she thinks about it.
Otherwise, it seems to be good :)
this.orgService.organisations$.subscribe((orgs) => { | ||
const orgName = this.myOrgDataSubject.value.orgName | ||
const org = orgs.find((org) => org.name === orgName) | ||
const logoUrl = org?.logoUrl?.href.toString() | ||
const recordCount = org?.recordCount | ||
this.myOrgDataSubject.next({ | ||
...this.myOrgDataSubject.value, | ||
logoUrl, | ||
recordCount, | ||
}) | ||
}) | ||
|
||
this.authService.allUsers$.subscribe((users) => { | ||
const orgName = this.myOrgDataSubject.value.orgName | ||
// const orgName = 'Barbie Inc.' | ||
const userList = users.filter((user) => user.organisation === orgName) | ||
const userCount = userList.length | ||
this.myOrgDataSubject.next({ ...this.myOrgDataSubject.value, userList }) | ||
this.myOrgDataSubject.next({ ...this.myOrgDataSubject.value, userCount }) | ||
}) |
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 am skeptical for this. I may need @jahow advice there ...
Instead of subscribing to 3 observables, it may be good to do it with rxjs with some kind of (with combineLatest or zip, or something else if it exists.) :
const orgData$ = combineLatest([users$, allUsers$, organisations]).pipe(
map(([a,b,c]) => resolve resolve),
);
and in html using an async
pipe to get datas.
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.
Indeed this is a good exercise for observables 🙂
RxJS offers you tools to avoid creating your own observable and calling next()
yourself. Something like what @f-necas was suggesting:
myOrgData$ = combineLatest([this.authService.user$, this.authService.allUsers$, this.orgService.organisations$]).pipe(
map(([user, allUsers, orgs]) => {
const orgName = user.organisation
const org = orgs.find((org) => org.name === orgName)
const logoUrl = org?.logoUrl?.href.toString()
const recordCount = org?.recordCount
const userList = users.filter((user) => user.organisation === orgName)
const userCount = userList.length
return {
logoUrl,
recordCount,
userList,
userCount,
}
})
);
(this is not tested!)
As for what you did originally, the problem is that you "break" the observable pattern by using the myOrgDataSubject
to share information between various contexts (namely the orgName
value). Although it works, it might be difficult to read for others because of the convoluted logic.
As a rule of thumb, an ideal use of observables is:
- no manual subscribing (only in the html with
| async
) - no creation of observables yourself (most observables should be derived from something else: HTTP requests, events, etc.)
Don't hesitate to ask if something is unclear! And yes, this should go in the docs eventually. 👼
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.
Got it, thanks for the extensive explaination 🙂
Following this guidance, should I change the way my-org-records.component.html
receives its data?
Go from : orgData?.logoUrl
to something like myOrgRecordsService.myOrgData$.logoUrl | async
?
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.
Thanks for the extensive work! It feels like you tackled quite a complex task with this story. I've added some comments, and I think it could be great if you could address them.
The metadata-editor components will still need some work for the future and that's fine, let's keep this an iterative process. I hope my comments are clear enough 🙂
apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.spec.ts
Show resolved
Hide resolved
apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts
Outdated
Show resolved
Hide resolved
apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts
Outdated
Show resolved
Hide resolved
this.orgService.organisations$.subscribe((orgs) => { | ||
const orgName = this.myOrgDataSubject.value.orgName | ||
const org = orgs.find((org) => org.name === orgName) | ||
const logoUrl = org?.logoUrl?.href.toString() | ||
const recordCount = org?.recordCount | ||
this.myOrgDataSubject.next({ | ||
...this.myOrgDataSubject.value, | ||
logoUrl, | ||
recordCount, | ||
}) | ||
}) | ||
|
||
this.authService.allUsers$.subscribe((users) => { | ||
const orgName = this.myOrgDataSubject.value.orgName | ||
// const orgName = 'Barbie Inc.' | ||
const userList = users.filter((user) => user.organisation === orgName) | ||
const userCount = userList.length | ||
this.myOrgDataSubject.next({ ...this.myOrgDataSubject.value, userList }) | ||
this.myOrgDataSubject.next({ ...this.myOrgDataSubject.value, userCount }) | ||
}) |
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.
Indeed this is a good exercise for observables 🙂
RxJS offers you tools to avoid creating your own observable and calling next()
yourself. Something like what @f-necas was suggesting:
myOrgData$ = combineLatest([this.authService.user$, this.authService.allUsers$, this.orgService.organisations$]).pipe(
map(([user, allUsers, orgs]) => {
const orgName = user.organisation
const org = orgs.find((org) => org.name === orgName)
const logoUrl = org?.logoUrl?.href.toString()
const recordCount = org?.recordCount
const userList = users.filter((user) => user.organisation === orgName)
const userCount = userList.length
return {
logoUrl,
recordCount,
userList,
userCount,
}
})
);
(this is not tested!)
As for what you did originally, the problem is that you "break" the observable pattern by using the myOrgDataSubject
to share information between various contexts (namely the orgName
value). Although it works, it might be difficult to read for others because of the convoluted logic.
As a rule of thumb, an ideal use of observables is:
- no manual subscribing (only in the html with
| async
) - no creation of observables yourself (most observables should be derived from something else: HTTP requests, events, etc.)
Don't hesitate to ask if something is unclear! And yes, this should go in the docs eventually. 👼
Thanks @jahow for this review and for your advice. I think the last two commits cover pretty much everything 🙂 For some reason I couldn't comment back on your comment . Here it is : I know, the union type is behaving weirdly, I thought it would work too when I first tried. |
55fb41e
to
c4b5817
Compare
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.
Thanks for getting my comments addressed, I think it can be merged now 🙂
Could you please rebase the branch on develop
before merging and remove the merge commit in the PR history? We generally try to avoid merge commits in Pull Requests as much as possible, thanks!
changes made & checked by other team member
1a71268
to
1d7afe4
Compare
TO-DO
In the "My Organization" menu item:
How to test
For testing purposes, I left commented lines at :
You might need to restore the commented line depending on the user you're using/your docker compo.
For instance, the user
Barbie
has the organization nameBarbie Inc.
which doesn't match any record or user organization and prevents testing here.The comments will be removed before merging.