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(uaa-integration): Parse Versions Response from UAA #3385

Merged
merged 9 commits into from Aug 23, 2023

Conversation

JChan106
Copy link
Contributor

@JChan106 JChan106 commented Aug 11, 2023

The UAA response gives a Versions activity event that is different than the v2 Versions API that we are currently using. We must parse the response and add the needed fields that our UI components need to render Version events.

One big difference with this change is that the latest version events do not have promotion context, unlike the v2 API. So if the user has promoted a version and that version is the most recent version, they can only see that version was promoted by clicking the info button and looking at the version history. The team has had discussions around this and is okay with this tradeoff, we will look into adding the promotion context into the UAA response in the future.

UAA:
Multiple version events
image
Multiple upload collaborators
image
Version events with comments between
image
new file upload, no events
image

V2 Versions:
Multiple version events
image
Multiple upload collaborators
image
Version events with comments between
image
new file upload, no events
image

@JChan106 JChan106 requested review from a team as code owners August 11, 2023 22:14
@@ -83,9 +84,7 @@ const CollapsedVersion = (props: Props): React.Node => {
aria-label={intl.formatMessage(messages.getVersionInfo)}
className="bcs-Version-info"
data-resin-target={ACTIVITY_TARGETS.VERSION_CARD}
onClick={() => {
onInfo({ versions });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's passed into this cb is only used when hasVersions prop is false and onVersionHistoryClick prop is passed into BUIE. There doesn't seem to be a standardized format, since the CollapsedVersion and Version components pass back different data. Because UAA doesn't have the versions array like the v2 api, I decided to use the end version of the event and match what was passed in the Version.js component (id and version_number). This cb is not used in EUA.

Copy link
Contributor

Choose a reason for hiding this comment

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

question: does the version_end always the represent current version even if a previous version was promoted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup

@@ -26,6 +26,7 @@ type Props = {
id: string,
modified_by: User,
onInfo?: Function,
shouldUseUAA?: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing where this is being used here. Can it be removed?

onClick={() => {
onInfo({ id, version_number });
}}
onClick={() => onInfo({ id, version_number })}
Copy link
Contributor

Choose a reason for hiding this comment

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

This change may un-intentionally be returning a value in the onClick when it wasn't before. I think it might be better to leave it in brackets or type the onInfo prop to show it returns void or undefined (same in CollapsedVersion).

onClick={() => {
onInfo({ versions });
}}
onClick={() => onInfo(shouldUseUAA ? { id, version_number: version_end } : { versions })}
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be returning a value now implicitly from the arrow function

}
}

return versionsItem;
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering if there would be a way to extract and organize some of this into separate functions to help reduce the length of the getParsedFileActivitiesResponse function? I'm also fine with leaving as-is if you don't think that would make sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, thought about it, there isn't really benefits to splitting though since the logic isn't reusable, and the switch statements make it more readable as well.

@@ -148,6 +148,15 @@ describe('elements/content-sidebar/ActivityFeed/activity-feed/ActivityFeed', ()
expect(wrapper.find('EmptyState').exists()).toBe(true);
});

test('should not render empty state when UAA is enabled and there is 1 version (current version from file) and the start and end version are the same', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this meant to be "should render empty.." instead of "should not render"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

patlm
patlm previously approved these changes Aug 15, 2023
Copy link
Contributor

@patlm patlm left a comment

Choose a reason for hiding this comment

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

Looks good to me!

src/api/Feed.js Outdated Show resolved Hide resolved
src/api/Feed.js Outdated Show resolved Hide resolved
mickr
mickr previously approved these changes Aug 17, 2023
@@ -83,9 +84,7 @@ const CollapsedVersion = (props: Props): React.Node => {
aria-label={intl.formatMessage(messages.getVersionInfo)}
className="bcs-Version-info"
data-resin-target={ACTIVITY_TARGETS.VERSION_CARD}
onClick={() => {
onInfo({ versions });
Copy link
Contributor

Choose a reason for hiding this comment

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

question: does the version_end always the represent current version even if a previous version was promoted?

src/api/__tests__/Feed.test.js Outdated Show resolved Hide resolved
src/api/Feed.js Outdated Show resolved Hide resolved
versionsItem.uploader_display_name = versionsItem.action_by[0].name;
}

versionsItem.action_by.map(collaborator => {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's a little odd to use map without intending to use the returned array. I think this might be a good use case for reduce:

versionsItem.collaborators = versionsItem.action_by.reduce( ... , {});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaning for keeping it for now since we've used map in a few other place. Going through another round of manual testing for the logic change also is a big time sink.

Copy link
Contributor

Choose a reason for hiding this comment

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

semantically it feels a little wrong to use a map in this case over something like a forEach since the goal is to populate a separate object instead of using the returned array

with the reduce it could be:

versionsItem.collaborators = versionsItem.action_by.reduce((collaborators, collaborator) =>
    ({ ...collaborators, [collaborator.id]: { ...collaborator } }), {});

although you could leave it as-is if the current implementation is easier to read

src/api/Feed.js Outdated Show resolved Hide resolved
src/api/Feed.js Show resolved Hide resolved
src/api/Feed.js Outdated Show resolved Hide resolved
Copy link
Contributor

@tjuanitas tjuanitas left a comment

Choose a reason for hiding this comment

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

lgtm!

versionsItem.uploader_display_name = versionsItem.action_by[0].name;
}

versionsItem.action_by.map(collaborator => {
Copy link
Contributor

Choose a reason for hiding this comment

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

semantically it feels a little wrong to use a map in this case over something like a forEach since the goal is to populate a separate object instead of using the returned array

with the reduce it could be:

versionsItem.collaborators = versionsItem.action_by.reduce((collaborators, collaborator) =>
    ({ ...collaborators, [collaborator.id]: { ...collaborator } }), {});

although you could leave it as-is if the current implementation is easier to read

@@ -471,6 +471,11 @@ export const ACTIVITY_FILTER_OPTION_RESOLVED: 'resolved' = 'resolved';
export const ACTIVITY_FILTER_OPTION_TASKS: 'tasks' = 'tasks';
export const ACTIVITY_FILTER_OPTION_UNRESOLVED: 'open' = 'open';

/* ------------------ File Activity Action Types ----------- */
export const ACTION_TYPE_CREATED: 'created' = 'created';
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if there's a concept of "action type" for other features but if there was we could change to FILE_ACTIVITY_ACTION_TYPE_[...] to be more specific

@mergify mergify bot merged commit 0fa730f into box:master Aug 23, 2023
6 checks passed
@JChan106 JChan106 deleted the COXP-11588 branch August 23, 2023 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants