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

New: version history in details tab #220

Merged
merged 8 commits into from
Mar 20, 2018

Conversation

DanDeMicco
Copy link
Contributor

@DanDeMicco DanDeMicco commented Mar 14, 2018

This adds the versions API, and version history to the details tab. Relies on box-react-ui 22.6.0

@boxcla
Copy link

boxcla commented Mar 14, 2018

Verified that @DanDeMicco has signed the CLA. Thanks for the pull request!

src/flowTypes.js Outdated
@@ -338,3 +339,19 @@ export type MultiputPart = {
export type MultiputData = {
part?: MultiputPart
};

export type Version = {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a BoxItemVersion
Can you check if its duped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is similar, but it appears the BoxItemVersion has an incomplete type definition and also includes less fields, according to the sample api docs

Copy link
Contributor

Choose a reason for hiding this comment

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

I would refactor and make them the same, you would just need to add ? to properties that are optional and not needed for the object to be partial and just null check them. Should ideally not have two definitions of 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.

Combined the types. As far as I could tell from the api docs only 3 properties were mandatory

src/constants.js Outdated
@@ -25,6 +25,7 @@ export const VIEW_UPLOAD_SUCCESS: 'upload-success' = 'upload-success';
export const TYPE_FOLDER: 'folder' = 'folder';
export const TYPE_FILE: 'file' = 'file';
export const TYPE_WEBLINK: 'web_link' = 'web_link';
export const TYPE_VERSIONS: 'versions' = 'versions';
Copy link
Contributor

Choose a reason for hiding this comment

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

There shouldn't be a type versions, since thats item type, and thats only the above 3.
If you are looking for a cache prefix, then see CACHE_PREFIX_* below

src/flowTypes.js Outdated
@@ -58,7 +59,7 @@ export type ClassComponent<P, S> = Class<React$Component<P, S>>;
export type StringMap = { [string]: string };
export type StringAnyMap = { [string]: any };
export type StringBooleanMap = { [string]: boolean };
export type ItemAPI = FolderAPI | FileAPI | WebLinkAPI;
export type ItemAPI = FolderAPI | FileAPI | WebLinkAPI | VersionsAPI;
Copy link
Contributor

Choose a reason for hiding this comment

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

VersionsAPI should be separate from ItemAPI

@@ -145,6 +162,9 @@ class APIFactory {
case TYPE_WEBLINK:
api = this.getWebLinkAPI();
break;
case TYPE_VERSIONS:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not be here, as thats for item type only

src/api/Item.js Outdated
* making file based XHRs where auth token
* can be per file as used by Preview.
*
* @return {string} typed id for file
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in File.js as before

// We only need the total_count for now
return this.xhr
.get({
id: this.getTypedFileId(id),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be referenced from FileAPI.
Can maybe make it a static function and update other places calling it.

@@ -43,11 +43,13 @@ type Props = {
sharedLinkPassword?: string,
requestInterceptor?: Function,
responseInterceptor?: Function,
onInteraction: Function
onInteraction: Function,
onVersionHistoryClick?: Function
Copy link
Contributor

Choose a reason for hiding this comment

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

hasVersions: boolean needs to be added like other has* above

@@ -324,9 +352,10 @@ class ContentSidebar extends PureComponent<Props, State> {
<Internationalize language={language} messages={messages}>
<div id={this.id} className={`be bcs ${className}`}>
<div className='be-app-element'>
{file ? (
{file && versions ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

Check should ideally not needed here, sidebar should render before versions is got

<Sidebar
file={file}
versions={versions}
Copy link
Contributor

Choose a reason for hiding this comment

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

pass in hasVersions too

@@ -56,6 +61,12 @@ const DetailsSidebar = ({

return (
<SidebarContent hasTitle={hasTitle} title={<FormattedMessage {...messages.sidebarDetailsTitle} />}>
{versions &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be inside its own file, say SidebarVersions and here it will be
{hasVersions && <SidebarVersions versions={versions} onVersionHistoryClick={onVersionHistoryClick}>}

/**
* API for versions
*/
getVersionsAPI(): VersionsAPI {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may have to extend/improve these get*API calls to optionally take a flag that prevents calling this.destroy(). Until now it wasn't really needed because most API calls were not really called in parallel. Called one at a time. But versions will be called in parallel to say the File api call. So calling destroy will destroy the other. Likewise I didn't want two API calls to muck with the same cached object, but in versions case its a diff cache object, so not a big deal from that perspective.

Either that, or the call to getVersionAPI() should come in the fetch success callback of the file, so that its a serial call and not parallel.

this.rootElement = ((document.getElementById(this.id): any): HTMLElement);
this.appElement = ((this.rootElement.firstElementChild: any): HTMLElement);

if (fileId) {
this.fetchFile(fileId);
if (hasVersions) {
Copy link
Contributor

Choose a reason for hiding this comment

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

componentWillReceiveProps also has fetchFile(), this will likely need to be replicated there.
OR maybe have this.fetchVersions() inside fetchFile()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactoring componentWillReceiveProps a bit

@@ -56,6 +63,7 @@ const DetailsSidebar = ({

return (
<SidebarContent hasTitle={hasTitle} title={<FormattedMessage {...messages.sidebarDetailsTitle} />}>
{hasVersions && <SidebarVersions onClick={onVersionHistoryClick} versions={versions} />}
Copy link
Contributor

Choose a reason for hiding this comment

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

onClick is fine for now, but may need a more descriptive name in the future if/when we pull in version switching and other on* actions.

}

return (
<section className='bcs-section'>
Copy link
Contributor

@priyajeet priyajeet Mar 15, 2018

Choose a reason for hiding this comment

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

The other commit from jeremy has some improvements of <SidebarSection> without need of a title, perhaps see if that works well 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.

👍

);
};

SidebarVersions.defaultProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not the pattern we use, causes side effects for uglifyjs cleanup.
Assign the defaults within the props.

{ onVersionHistoryClick, versions = { total_count: 0 } }

Also will total count not be there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

total_count would not be there if API hasn't responded by time the component has rendered

src/flowTypes.js Outdated
@@ -338,3 +339,19 @@ export type MultiputPart = {
export type MultiputData = {
part?: MultiputPart
};

export type Version = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would refactor and make them the same, you would just need to add ? to properties that are optional and not needed for the object to be partial and just null check them. Should ideally not have two definitions of versions.

@wenboyu2
Copy link
Contributor

Webpack Bundle Size Github Bot

Bundle Diff Before After
sidebar 3 KB 477 KB 474 KB
tree 1 KB 497 KB 496 KB
explorer 3 KB 674 KB 671 KB
uploader 1 KB 501 KB 500 KB
picker 1 KB 599 KB 598 KB
preview 3 KB 537 KB 534 KB
Total 12 KB 3.21 MB 3.2 MB

Compared against previously merged PR #206

@DanDeMicco DanDeMicco merged commit 935f617 into box:master Mar 20, 2018
@DanDeMicco DanDeMicco deleted the version-history branch March 20, 2018 19:13
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.

4 participants