Skip to content

Commit 51d8072

Browse files
authored
Create a new "Media Storage Details" view (#24888)
* Create a new "Media Storage Details" view * Remove an empty line * Localize "View Usage"
1 parent adee5bb commit 51d8072

6 files changed

Lines changed: 522 additions & 3 deletions

File tree

Modules/Sources/BuildSettingsKit/BuildSettings+Preview.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Foundation
44
extension BuildSettings {
55
nonisolated(unsafe) static var preview = BuildSettings(
66
configuration: .debug,
7+
secrets: .dummy,
78
brand: .jetpack,
89
pushNotificationAppID: "xcpreview_push_notification_id",
910
appGroupName: "xcpreview_app_group_name",

Sources/WordPressData/Swift/Blog+Quota.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public extension Blog {
4545
return String(format: formatString, quotaPercentageUsedDescription, quotaSpaceAllowedDescription)
4646
}
4747

48+
@objc var quotaUsageShortDescription: String? {
49+
guard isQuotaAvailable, let quotaPercentageUsedDescription = self.quotaPercentageUsedDescription, let quotaSpaceAllowedDescription = self.quotaSpaceAllowedDescription else {
50+
return nil
51+
}
52+
let formatString = NSLocalizedString("%1$@ of %2$@ used", comment: "Amount of disk quota being used. First argument is the total percentage being used second argument is total quota allowed in GB.Ex: 33% of 14 GB used on your site.")
53+
return String(format: formatString, quotaPercentageUsedDescription, quotaSpaceAllowedDescription)
54+
}
55+
4856
/// Returns the disk space quota still available to use in the site.
4957
@objc var quotaSpaceAvailable: NSNumber? {
5058
guard let quotaSpaceAllowed = quotaSpaceAllowed?.int64Value, let quotaSpaceUsed = quotaSpaceUsed?.int64Value else {

WordPress/Classes/Services/MediaServiceRemoteCoreREST.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class MediaServiceRemoteCoreREST: NSObject, MediaServiceRemote {
1414
self.client = client
1515
}
1616

17+
func unattachedMediaItemCount() async throws -> Int? {
18+
try await client.api.media
19+
.listWithViewContext(params: .init(parent: [0]))
20+
.headerMap
21+
.wpTotal()
22+
.flatMap(Int.init)
23+
}
24+
1725
func getMediaWithID(_ mediaID: NSNumber, success: ((RemoteMedia?) -> Void)?, failure: (((any Error)?) -> Void)?) {
1826
Task { @MainActor in
1927
do {

WordPress/Classes/Utility/BuildInformation/FeatureFlag.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public enum FeatureFlag: Int, CaseIterable {
2727
case newsletterSubscribers
2828
case newStats
2929
case newPublishingSheet
30+
case mediaQuotaView
3031

3132
/// Returns a boolean indicating if the feature is enabled.
3233
///
@@ -85,6 +86,8 @@ public enum FeatureFlag: Int, CaseIterable {
8586
return false
8687
case .newPublishingSheet:
8788
return false
89+
case .mediaQuotaView:
90+
return false
8891
}
8992
}
9093

@@ -129,6 +132,7 @@ extension FeatureFlag {
129132
case .newsletterSubscribers: "Newsletter Subscribers"
130133
case .newStats: "New Stats"
131134
case .newPublishingSheet: "New Publishing Sheet"
135+
case .mediaQuotaView: "Media Quota"
132136
}
133137
}
134138
}

WordPress/Classes/ViewRelated/Media/SiteMedia/Controllers/SiteMediaAddMediaMenuController.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import SwiftUI
12
import UIKit
23
import Photos
34
import PhotosUI
@@ -35,9 +36,17 @@ final class SiteMediaAddMediaMenuController: NSObject, PHPickerViewControllerDel
3536
]
3637
}
3738
if let quotaUsageDescription = blog.quotaUsageDescription {
38-
children += [
39-
UIAction(subtitle: quotaUsageDescription, handler: { _ in })
40-
]
39+
if FeatureFlag.mediaQuotaView.enabled {
40+
children += [
41+
UIAction(title: Strings.viewUsage, subtitle: blog.quotaUsageShortDescription, image: UIImage(systemName: "opticaldiscdrive"), handler: { _ in
42+
self.showQuotaView(from: viewController)
43+
})
44+
]
45+
} else {
46+
children += [
47+
UIAction(subtitle: quotaUsageDescription, handler: { _ in })
48+
]
49+
}
4150
}
4251
return UIMenu(options: [.displayInline], children: children)
4352
}
@@ -47,6 +56,12 @@ final class SiteMediaAddMediaMenuController: NSObject, PHPickerViewControllerDel
4756
.showPhotosPicker(delegate: self)
4857
}
4958

59+
private func showQuotaView(from viewController: UIViewController) {
60+
guard let viewModel = try? MediaStorageDetailsViewModel(blog: blog) else { return }
61+
let rootView = MediaStorageDetailsView(viewModel: viewModel)
62+
viewController.present(UIHostingController(rootView: rootView), animated: true)
63+
}
64+
5065
// MARK: - PHPickerViewControllerDelegate
5166

5267
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
@@ -150,4 +165,5 @@ final class SiteMediaAddMediaMenuController: NSObject, PHPickerViewControllerDel
150165

151166
private enum Strings {
152167
static let pickFromOtherApps = NSLocalizedString("mediaPicker.pickFromOtherApps", value: "Other Files", comment: "The name of the action in the context menu for selecting photos from other apps (Files app)")
168+
static let viewUsage = NSLocalizedString("mediaPicker.viewUsage", value: "View Usage", comment: "The menu item of viewing media library usage")
153169
}

0 commit comments

Comments
 (0)