OneDrive details UX improvements (#1034)

## Description

- Rename `LastModified` to `Modified` in OneDrive backup details
- Humanize file size units

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* #627 

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Vaibhav Kamra 2022-10-04 08:44:47 -07:00 committed by GitHub
parent 8ab5d5c112
commit 3df3d68a3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 29 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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),
}
}

View File

@ -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},
},
}

View File

@ -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)

View File

@ -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,
},
}