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

iOS-3264 Version history | Impl readonly mode #1879

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ final class BaseDocument: BaseDocumentProtocol {
let newPermissios = ObjectPermissions(
details: details ?? ObjectDetails(id: ""),
isLocked: isLocked,
participantCanEdit: participantIsEditor,
participantCanEdit: participantIsEditor,
isVersionMode: mode.isVersion,
objectRestrictions: objectRestrictions.objectRestriction
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ enum DocumentMode: Hashable, Codable {
var isHandling: Bool {
self == .handling
}

var isVersion: Bool {
if case .version = self {
return true
} else {
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ extension ObjectPermissions {
details: ObjectDetails,
isLocked: Bool,
participantCanEdit: Bool,
isVersionMode: Bool,
objectRestrictions: [ObjectRestriction]
) {
let isArchive = details.isArchived
let isTemplateType = details.isTemplateType

let canEdit = !isLocked && !isArchive && participantCanEdit
let canEdit = !isLocked && !isArchive && participantCanEdit && !isVersionMode
let canApplyUneditableActions = participantCanEdit && !isArchive

let specificTypes = details.layoutValue != .set
Expand Down Expand Up @@ -70,7 +71,7 @@ extension ObjectPermissions {
self.canShare = !isTemplateType
self.canApplyTemplates = canEdit && !isTemplateType

if isLocked {
if isLocked || isVersionMode {
self.editBlocks = .readonly(.locked)
} else if isArchive {
self.editBlocks = .readonly(.archived)
Expand Down Expand Up @@ -99,7 +100,8 @@ extension ObjectDetails {
ObjectPermissions(
details: self,
isLocked: false,
participantCanEdit: participantCanEdit,
participantCanEdit: participantCanEdit,
isVersionMode: false,
objectRestrictions: restrictionsValue
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct FlowRelationsView: View {
TitleWithIconView(
icon: viewModel.icon,
showIcon: viewModel.showIcon,
canEditIcon: viewModel.canEditIcon,
title: viewModel.title,
style: .list
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ import SwiftUI
class FlowRelationsViewModel: ObservableObject {
let icon: Icon?
let showIcon: Bool
let canEditIcon: Bool
let title: String?
let description: String?
let relations: [Relation]

init(
icon: Icon? = nil,
showIcon: Bool = true,
canEditIcon: Bool,
title: String?,
description: String?,
relations: [Relation]
) {
self.icon = icon
self.showIcon = showIcon
self.canEditIcon = canEditIcon
self.title = title
self.description = description
self.relations = relations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AnytypeCore
struct TitleWithIconView: View {
let icon: Icon?
let showIcon: Bool
let canEditIcon: Bool
let title: String?
let style: TitleWithIconStyle

Expand All @@ -22,6 +23,7 @@ struct TitleWithIconView: View {
height: style.iconSize.height
)
.padding(.top, 1)
.disabled(!canEditIcon)
}
} else {
title(with: title)
Expand All @@ -47,7 +49,8 @@ struct TitleWithIconView_Previews: PreviewProvider {
static var previews: some View {
TitleWithIconView(
icon: .object(.emoji(Emoji("📘")!)),
showIcon: true,
showIcon: true,
canEditIcon: true,
title: "Let's see how this TitleWithIconView looks like with image - header style",
style: .header
)
Expand All @@ -56,6 +59,7 @@ struct TitleWithIconView_Previews: PreviewProvider {
TitleWithIconView(
icon: .object(.emoji(Emoji("📘")!)),
showIcon: true,
canEditIcon: true,
title: "Let's see how this TitleWithIconView looks like with image - list style",
style: .list
)
Expand All @@ -64,6 +68,7 @@ struct TitleWithIconView_Previews: PreviewProvider {
TitleWithIconView(
icon: .object(.emoji(Emoji("📘")!)),
showIcon: true,
canEditIcon: true,
title: "Let's see how this TitleWithIconView looks like with image - gallery style",
style: .gallery
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ final class SetObjectWidgetInternalViewModel: ObservableObject {
details,
dataView: setDocument.dataView,
activeView: setDocument.activeView,
viewRelationValueIsLocked: false,
viewRelationValueIsLocked: false,
canEditIcon: setDocument.setPermissions.canEditSetObjectIcon,
storage: subscriptionStorage.detailsStorage,
spaceId: setDocument.spaceId,
onItemTap: { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ final class EditorSetViewModel: ObservableObject {
records,
dataView: setDocument.dataView,
activeView: activeView,
viewRelationValueIsLocked: !setDocument.setPermissions.canEditRelationValuesInView,
viewRelationValueIsLocked: !setDocument.setPermissions.canEditRelationValuesInView,
canEditIcon: setDocument.setPermissions.canEditSetObjectIcon,
storage: subscription.detailsStorage,
spaceId: setDocument.spaceId,
onItemTap: { [weak self] details in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ final class SetPermissionsBuilder: SetPermissionsBuilderProtocol {

func build(setDocument: SetDocument, participantCanEdit: Bool) -> SetPermissions {

let isVersionMode = setDocument.mode.isVersion
let isArchive = setDocument.details?.isArchived ?? true
let isLocked = setDocument.document.isLocked
let canEdit = !isLocked && !isArchive && participantCanEdit
let canEdit = !isLocked && !isArchive && participantCanEdit && !isVersionMode

return SetPermissions(
canCreateObject: canEdit && canCreateObject(setDocument: setDocument, participantCanEdit: participantCanEdit),
canEditView: canEdit,
canTurnSetIntoCollection: canEdit && !setDocument.isCollection(),
canChangeQuery: canEdit && !setDocument.isCollection(),
canEditRelationValuesInView: canEdit && canEditRelationValuesInView(setDocument: setDocument)
canEditRelationValuesInView: canEdit && canEditRelationValuesInView(setDocument: setDocument),
canEditTitle: canEdit,
canEditDescription: canEdit,
canEditSetObjectIcon: canEdit
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ struct SetPermissions {
var canTurnSetIntoCollection: Bool = false
var canChangeQuery: Bool = false
var canEditRelationValuesInView: Bool = false
var canEditTitle: Bool = false
var canEditDescription: Bool = false
var canEditSetObjectIcon: Bool = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ struct SetGalleryViewCell: View {
VStack(alignment: .leading, spacing: 0) {
TitleWithIconView(
icon: configuration.icon,
showIcon: configuration.showIcon,
showIcon: configuration.showIcon,
canEditIcon: configuration.canEditIcon,
title: configuration.title,
style: .gallery
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct SetListViewCell: View {
FlowRelationsView(
viewModel: FlowRelationsViewModel(
icon: configuration.icon,
showIcon: configuration.showIcon,
showIcon: configuration.showIcon,
canEditIcon: configuration.canEditIcon,
title: configuration.title,
description: configuration.description,
relations: configuration.relations.filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ extension SetFullHeader {
text: $model.descriptionString
)
.padding([.trailing], 20)
.foregroundStyle(Color.Text.primary)
.foregroundStyle(Color.Text.primary)
.disabled(!model.setDocument.setPermissions.canEditDescription)
} else {
EmptyView()
}
Expand Down Expand Up @@ -117,6 +118,7 @@ extension SetFullHeader {
.padding([.trailing], 20)
.foregroundStyle(Color.Text.primary)
.disableAutocorrection(true)
.disabled(!model.setDocument.setPermissions.canEditTitle)
}

private var featuredRelationsView: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol SetContentViewDataBuilderProtocol: AnyObject {
dataView: BlockDataview,
activeView: DataviewView,
viewRelationValueIsLocked: Bool,
canEditIcon: Bool,
storage: ObjectDetailsStorage,
spaceId: String,
onItemTap: @escaping @MainActor (ObjectDetails) -> Void
Expand Down Expand Up @@ -80,6 +81,7 @@ final class SetContentViewDataBuilder: SetContentViewDataBuilderProtocol {
dataView: BlockDataview,
activeView: DataviewView,
viewRelationValueIsLocked: Bool,
canEditIcon: Bool,
storage: ObjectDetailsStorage,
spaceId: String,
onItemTap: @escaping @MainActor (ObjectDetails) -> Void
Expand Down Expand Up @@ -108,7 +110,8 @@ final class SetContentViewDataBuilder: SetContentViewDataBuilderProtocol {
id: item.details.id,
title: item.details.title,
description: item.details.description,
icon: item.details.objectIconImage,
icon: item.details.objectIconImage,
canEditIcon: canEditIcon,
relations: item.relations,
showIcon: !activeView.hideIcon,
isSmallCardSize: activeView.isSmallCardSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ struct SetContentViewItemConfiguration: Identifiable, Hashable {
let title: String
let description: String?
let icon: Icon?
let canEditIcon: Bool
let relations: [Relation]
let showIcon: Bool
let isSmallCardSize: Bool
Expand All @@ -21,6 +22,7 @@ struct SetContentViewItemConfiguration: Identifiable, Hashable {
title: String,
description: String?,
icon: Icon?,
canEditIcon: Bool,
relations: [Relation],
showIcon: Bool,
isSmallCardSize: Bool,
Expand All @@ -34,6 +36,7 @@ struct SetContentViewItemConfiguration: Identifiable, Hashable {
self.title = title
self.description = description
self.icon = icon
self.canEditIcon = canEditIcon
self.relations = relations
self.showIcon = showIcon
self.isSmallCardSize = isSmallCardSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct SetTableViewRow: View {
if let icon = configuration.icon, configuration.showIcon {
IconView(icon: icon).frame(width: 18, height: 18)
.padding(.trailing, 8)
.disabled(!model.setDocument.setPermissions.canEditSetObjectIcon)
}
}
}
Expand Down
Loading