From 3df3d68a3e1bdff51a7e8db16021a8e0d2d7fed3 Mon Sep 17 00:00:00 2001 From: Vaibhav Kamra Date: Tue, 4 Oct 2022 08:44:47 -0700 Subject: [PATCH] OneDrive details UX improvements (#1034) ## Description - Rename `LastModified` to `Modified` in OneDrive backup details - Humanize file size units ## Type of change - [ ] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Test - [ ] :computer: CI/Deployment - [x] :hamster: Trivial/Minor ## Issue(s) * #627 ## Test Plan - [ ] :muscle: Manual - [x] :zap: Unit test - [ ] :green_heart: E2E --- src/go.mod | 2 +- src/internal/connector/onedrive/item.go | 10 +++++----- src/pkg/backup/details/details.go | 20 +++++++++++--------- src/pkg/backup/details/details_test.go | 14 +++++++------- src/pkg/selectors/onedrive.go | 2 +- src/pkg/selectors/onedrive_test.go | 12 ++++++------ 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/src/go.mod b/src/go.mod index e7020f908..77cbd1673 100644 --- a/src/go.mod +++ b/src/go.mod @@ -51,7 +51,7 @@ require ( github.com/chmduquesne/rollinghash v4.0.0+incompatible // indirect github.com/cjlapao/common-go v0.0.27 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dustin/go-humanize v1.0.0 // indirect + github.com/dustin/go-humanize v1.0.0 github.com/edsrzf/mmap-go v1.1.0 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect diff --git a/src/internal/connector/onedrive/item.go b/src/internal/connector/onedrive/item.go index 6db6ec35a..b70ceccd7 100644 --- a/src/internal/connector/onedrive/item.go +++ b/src/internal/connector/onedrive/item.go @@ -57,11 +57,11 @@ func driveItemReader( } return &details.OneDriveInfo{ - ItemType: details.OneDriveItem, - ItemName: *item.GetName(), - Created: *item.GetCreatedDateTime(), - LastModified: *item.GetLastModifiedDateTime(), - Size: *item.GetSize(), + ItemType: details.OneDriveItem, + ItemName: *item.GetName(), + Created: *item.GetCreatedDateTime(), + Modified: *item.GetLastModifiedDateTime(), + Size: *item.GetSize(), }, resp.Body, nil } diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index 4942e2be7..a11b4becf 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -6,6 +6,8 @@ import ( "sync" "time" + "github.com/dustin/go-humanize" + "github.com/alcionai/corso/src/cli/print" "github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/model" @@ -361,25 +363,25 @@ func (i SharepointInfo) Values() []string { // OneDriveInfo describes a oneDrive item type OneDriveInfo struct { - ItemType ItemType `json:"itemType,omitempty"` - ParentPath string `json:"parentPath"` - ItemName string `json:"itemName"` - Size int64 `json:"size,omitempty"` - Created time.Time `json:"created,omitempty"` - LastModified time.Time `json:"lastModified,omitempty"` + ItemType ItemType `json:"itemType,omitempty"` + ParentPath string `json:"parentPath"` + ItemName string `json:"itemName"` + Size int64 `json:"size,omitempty"` + Created time.Time `json:"created,omitempty"` + Modified time.Time `json:"modified,omitempty"` } // Headers returns the human-readable names of properties in a OneDriveInfo // for printing out to a terminal in a columnar display. func (i OneDriveInfo) Headers() []string { - return []string{"ItemName", "ParentPath", "Size", "Created", "LastModified"} + return []string{"ItemName", "ParentPath", "Size", "Created", "Modified"} } // Values returns the values matching the Headers list for printing // out to a terminal in a columnar display. func (i OneDriveInfo) Values() []string { return []string{ - i.ItemName, i.ParentPath, strconv.FormatInt(i.Size, 10), - common.FormatTabularDisplayTime(i.Created), common.FormatTabularDisplayTime(i.LastModified), + i.ItemName, i.ParentPath, humanize.Bytes(uint64(i.Size)), + common.FormatTabularDisplayTime(i.Created), common.FormatTabularDisplayTime(i.Modified), } } diff --git a/src/pkg/backup/details/details_test.go b/src/pkg/backup/details/details_test.go index fbfe7a94a..c93e024e5 100644 --- a/src/pkg/backup/details/details_test.go +++ b/src/pkg/backup/details/details_test.go @@ -112,16 +112,16 @@ func (suite *DetailsUnitSuite) TestDetailsEntry_HeadersValues() { ShortRef: "deadbeef", ItemInfo: details.ItemInfo{ OneDrive: &details.OneDriveInfo{ - ItemName: "itemName", - ParentPath: "parentPath", - Size: 1000, - Created: now, - LastModified: now, + ItemName: "itemName", + ParentPath: "parentPath", + Size: 1000, + Created: now, + Modified: now, }, }, }, - expectHs: []string{"Reference", "ItemName", "ParentPath", "Size", "Created", "LastModified"}, - expectVs: []string{"deadbeef", "itemName", "parentPath", "1000", nowStr, nowStr}, + expectHs: []string{"Reference", "ItemName", "ParentPath", "Size", "Created", "Modified"}, + expectVs: []string{"deadbeef", "itemName", "parentPath", "1.0 kB", nowStr, nowStr}, }, } diff --git a/src/pkg/selectors/onedrive.go b/src/pkg/selectors/onedrive.go index af4900594..d5d77ccc5 100644 --- a/src/pkg/selectors/onedrive.go +++ b/src/pkg/selectors/onedrive.go @@ -440,7 +440,7 @@ func (s OneDriveScope) matchesInfo(dii details.ItemInfo) bool { case FileFilterCreatedAfter, FileFilterCreatedBefore: i = common.FormatTime(info.Created) case FileFilterModifiedAfter, FileFilterModifiedBefore: - i = common.FormatTime(info.LastModified) + i = common.FormatTime(info.Modified) } return s.Matches(filterCat, i) diff --git a/src/pkg/selectors/onedrive_test.go b/src/pkg/selectors/onedrive_test.go index 986824ef9..439bf1d79 100644 --- a/src/pkg/selectors/onedrive_test.go +++ b/src/pkg/selectors/onedrive_test.go @@ -297,12 +297,12 @@ func (suite *OneDriveSelectorSuite) TestOneDriveScope_MatchesInfo() { itemInfo := details.ItemInfo{ OneDrive: &details.OneDriveInfo{ - ItemType: details.OneDriveItem, - ParentPath: "folder1/folder2", - ItemName: "file1", - Size: 10, - Created: now, - LastModified: now, + ItemType: details.OneDriveItem, + ParentPath: "folder1/folder2", + ItemName: "file1", + Size: 10, + Created: now, + Modified: now, }, }