Skip to content
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

feat(hub-discussions): adds Discussions package to Hub.js #479

Merged
merged 87 commits into from
Jul 7, 2021

Conversation

cpgruber
Copy link
Contributor

@cpgruber cpgruber commented Mar 3, 2021

Adds discussions package to monorepo, which will serve as the interface layer in front of the Discussions API and ultimately replace hub-annotations (TBDeprecated)

@codecov
Copy link

codecov bot commented Mar 3, 2021

Codecov Report

Merging #479 (50ab423) into master (a64b488) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            master      #479    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          428       438    +10     
  Lines         6001      6242   +241     
  Branches       946       993    +47     
==========================================
+ Hits          6001      6242   +241     
Impacted Files Coverage Δ
packages/discussions/src/channels.ts 100.00% <100.00%> (ø)
packages/discussions/src/index.ts 100.00% <100.00%> (ø)
packages/discussions/src/posts.ts 100.00% <100.00%> (ø)
packages/discussions/src/reactions.ts 100.00% <100.00%> (ø)
packages/discussions/src/request.ts 100.00% <100.00%> (ø)
packages/discussions/src/types.ts 100.00% <100.00%> (ø)
packages/discussions/src/utils/channels.ts 100.00% <100.00%> (ø)
packages/discussions/src/utils/platform.ts 100.00% <100.00%> (ø)
packages/discussions/src/utils/posts.ts 100.00% <100.00%> (ø)
packages/discussions/src/utils/reactions.ts 100.00% <100.00%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a64b488...50ab423. Read the comment docs.

@ajturner
Copy link
Member

✋Let me know when it's appropriate to provide some questions or comments on this PR.

@cpgruber
Copy link
Contributor Author

✋Let me know when it's appropriate to provide some questions or comments on this PR.

@ajturner let em fly

Copy link
Member

@ajturner ajturner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for being open to feedback. I've added some notes based discussions with @mikeringrose & @dbouwman for consistency in Hub.js, and some other recommendations considering longer-term maintenance.

packages/discussions/README.md Outdated Show resolved Hide resolved
packages/discussions/src/channels.ts Outdated Show resolved Hide resolved
* @param {IRequestOptions} options
* @return {*} {Promise<string>}
*/
export function authenticateRequest(options: IRequestOptions): Promise<string> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These methods seem like they would be used across this library. Are there Discussion-specific reasons it's in this module or should they be in a core utils?

If possible, that would reduce redundancy, discrepancies, and maintenance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I didn't give much thought about the location of this method. I assumed this was the only place that needed to use platform authentication to make an off-platform request. Is that not the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have:

export function hubApiRequest(

and a few places where we append the Authorization header, although those seem to be missing the "Bearer " prefix to the token. I have some vague recollection of a discussion between John Gravois and @rgwozdz regarding that at some point.

I think that the request and auth logic should be centralized in hub-common.


/**
* update post
* NOTE: this method only updates a post's title and/or body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good limit to note.

what are your plans for adding update support to geometry or other post attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are separate methods for updating a post's status (only allowed by moderators) and its channel/sharing. This method could support geometry and discussion/target in just a few LOC; it would be beneficial to discuss the business logic about which attributes are updatable and by whom.

packages/discussions/src/posts.ts Outdated Show resolved Hide resolved
packages/discussions/src/utils/posts.ts Outdated Show resolved Hide resolved
*/
export function searchPosts(
options: IQueryPostsOptions | IQueryChannelPostsOptions
): Promise<INestPagination<IPostDTO>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are bleeding the implementation into hub.js. I'd change IPostDTO to just IPost and INestPagination shouldn't be. We really need to be consistent in how we do things so if at all possible pagination should be uniform across hub.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree w/ @mikeringrose on this... from what I can tell, we should be able to drop DTO from everything that has it... Using Rename Symbol in vscode, this should be pretty easy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, *DTO has been removed. For pagination, what's the gold standard? I've found IPagedResponse and IPagingParams, but I've also seen other interfaces like https://github.com/Esri/hub.js/blob/master/packages/search/src/types/common.ts#L38

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, would it be appropriate for me to leverage SortDirection from hub-search in my query DTO's?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so @cpgruber

Comment on lines 35 to 39
if (options.params.hasOwnProperty("channelId")) {
const {
params: { channelId }
} = options as IQueryChannelPostsOptions;
url = `/channels/${channelId}` + url;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just one method? Why not a method searchPost and searchChannel? It allows code to be more explicit and you remove the if condition and you force validation by parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this method is searching posts; IQueryChannelPostsOptions scopes the search to a single channel, while IQueryPostsOptions can search many channels. Does that change your opinion?

Otherwise, I thought having two methods, searchPosts and searchChannelPosts, to be redundant and consolidated to a single method for the convenience of dev users.

Comment on lines +22 to +29
THUMBS_UP = "thumbs_up",
THUMBS_DOWN = "thumbs_down",
THINKING = "thinking",
HEART = "heart",
ONE_HUNDRED = "one_hundred",
SAD = "sad",
LAUGH = "laugh",
SURPRISED = "surprised"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these are comments, just use the UTF8 emoji character 👍, 👎, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure it would work just fine, but since these values are ultimately persisted in the database I figure using human-readable string versions would eliminate any potential for things to go wrong if and when we choose to optimize by migrating these string values to numeric

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UTF8 emoji character would be numeric. For example, thumbs-up is U+1F44D.

packages/discussions/src/types.ts Outdated Show resolved Hide resolved
packages/discussions/src/utils/channels.ts Outdated Show resolved Hide resolved
@cpgruber cpgruber changed the title Hub Discussions feat(hub-discussions): adds Discussions package to Hub.js Jul 7, 2021
@cpgruber cpgruber merged commit 6117cb3 into master Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants