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

Media Picker: only allow navigating to folders/media with children + other fixes #17617

Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0e3a9dc
only allow navigating into folders or item with children
madsrasmussen Nov 22, 2024
6133a27
export media search provider
madsrasmussen Nov 22, 2024
95a5840
mark search on media item repo as deprecated
madsrasmussen Nov 22, 2024
6fb0848
use media search provider for searching
madsrasmussen Nov 22, 2024
545ba76
rename method
madsrasmussen Nov 22, 2024
987623c
change the look of the upload button
madsrasmussen Nov 22, 2024
0b0ad39
only render checkbox if we are not in the root
madsrasmussen Nov 22, 2024
d04da2d
clear search when navigating
madsrasmussen Nov 22, 2024
496b220
add type
madsrasmussen Nov 22, 2024
608eb95
set value so it gets updated when cleared
madsrasmussen Nov 22, 2024
b1dfe0c
default to search within an item
madsrasmussen Nov 22, 2024
f983dfe
hide breadcrumb if searching in root
madsrasmussen Nov 22, 2024
4e66029
scope search on server
madsrasmussen Nov 22, 2024
08b45fe
Update media-picker-modal.element.ts
madsrasmussen Nov 22, 2024
d6725dc
hide breadcrumb when doing a global search within another item
madsrasmussen Nov 22, 2024
eadf494
add selection mode
madsrasmussen Nov 22, 2024
2e2f180
Merge branch 'v15/dev' into v15/bugfix/prevent-navigating-to-non-fold…
madsrasmussen Nov 22, 2024
6a2e556
remove unused state
madsrasmussen Nov 22, 2024
a899ef4
handle start node when searching
madsrasmussen Nov 22, 2024
2a05b1a
fix if wrong order
madsrasmussen Nov 22, 2024
ff66714
fix type error
madsrasmussen Nov 22, 2024
5258c61
pass start node to breadcrumb
madsrasmussen Nov 22, 2024
5bbfd3b
handle start node in breadcrumb
madsrasmussen Nov 22, 2024
6b4e82c
make start node optional
madsrasmussen Nov 25, 2024
a99f2fa
map data
madsrasmussen Nov 25, 2024
5527f58
clean up
madsrasmussen Nov 25, 2024
6ec9023
Update media-picker-folder-path.element.ts
madsrasmussen Nov 25, 2024
d37e0f0
add searching load indicator
madsrasmussen Nov 25, 2024
0153a1f
don't show unique in detail
madsrasmussen Nov 25, 2024
79f9091
Add information to item response model
nikolajlauridsen Nov 25, 2024
3c940f6
Update OpenApi.json
nikolajlauridsen Nov 25, 2024
fbc5be1
Merge branch 'v15/feature/add-information-to-entity' into v15/bugfix/…
madsrasmussen Nov 25, 2024
c635e45
generate new server models
madsrasmussen Nov 25, 2024
9287272
update mocks
madsrasmussen Nov 25, 2024
6d62b45
move interface to types
madsrasmussen Nov 25, 2024
f9b1801
add hasChildren and parent to media item model interface
madsrasmussen Nov 25, 2024
d4963d0
fix import
madsrasmussen Nov 25, 2024
46c1eb6
map data
madsrasmussen Nov 25, 2024
2ccc15b
map media item
madsrasmussen Nov 25, 2024
f6641c4
treat tree item and search result the same
madsrasmussen Nov 25, 2024
2b1a771
Fix: bump uui version (#17626)
madsrasmussen Nov 25, 2024
ca521f4
Merge branch 'v15/dev' into v15/bugfix/prevent-navigating-to-non-fold…
madsrasmussen Nov 25, 2024
c577d9a
lint fix
madsrasmussen Nov 25, 2024
69782ed
temp fix for media selection
nielslyngsoe Nov 25, 2024
8259741
UX corrections for media selection
nielslyngsoe Nov 25, 2024
797b9b5
temp uui fix for media picker modal
nielslyngsoe Nov 25, 2024
e1a2062
fix table selection mode
nielslyngsoe Nov 25, 2024
e47e6bf
fix search from when having a start node
madsrasmussen Nov 25, 2024
75f42f7
Merge branch 'v15/bugfix/prevent-navigating-to-non-folders-in-media-p…
madsrasmussen Nov 25, 2024
cbbf018
Merge branch 'v15/dev' into v15/bugfix/prevent-navigating-to-non-fold…
madsrasmussen Nov 25, 2024
025ea8a
remove private
nielslyngsoe Nov 25, 2024
2a2d8f5
wait for all missing parts before create table items
madsrasmussen Nov 25, 2024
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 @@ -22,19 +22,22 @@
private readonly ITemplateService _templateService;
private readonly IPublicAccessService _publicAccessService;
private readonly TimeProvider _timeProvider;
private readonly IIdKeyMap _idKeyMap;

public DocumentPresentationFactory(
IUmbracoMapper umbracoMapper,
IDocumentUrlFactory documentUrlFactory,
ITemplateService templateService,
IPublicAccessService publicAccessService,
TimeProvider timeProvider)
TimeProvider timeProvider,
IIdKeyMap idKeyMap)
{
_umbracoMapper = umbracoMapper;
_documentUrlFactory = documentUrlFactory;
_templateService = templateService;
_publicAccessService = publicAccessService;
_timeProvider = timeProvider;
_idKeyMap = idKeyMap;

Check warning on line 40 in src/Umbraco.Cms.Api.Management/Factories/DocumentPresentationFactory.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

❌ New issue: Constructor Over-Injection

DocumentPresentationFactory has 6 arguments, threshold = 5. This constructor has too many arguments, indicating an object with low cohesion or missing function argument abstraction. Avoid adding more arguments.
}

public async Task<DocumentResponseModel> CreateResponseModelAsync(IContent content)
Expand Down Expand Up @@ -73,10 +76,14 @@

public DocumentItemResponseModel CreateItemResponseModel(IDocumentEntitySlim entity)
{
Attempt<Guid> parentKeyAttempt = _idKeyMap.GetKeyForId(entity.ParentId, UmbracoObjectTypes.Document);

var responseModel = new DocumentItemResponseModel
{
Id = entity.Key,
IsTrashed = entity.Trashed
IsTrashed = entity.Trashed,
Parent = parentKeyAttempt.Success ? new ReferenceByIdModel { Id = parentKeyAttempt.Result } : null,
HasChildren = entity.HasChildren,
};

responseModel.IsProtected = _publicAccessService.IsProtected(entity.Path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
using Umbraco.Cms.Api.Management.ViewModels.Content;
using Umbraco.Cms.Api.Management.ViewModels;
using Umbraco.Cms.Api.Management.ViewModels.Content;
using Umbraco.Cms.Api.Management.ViewModels.Media;
using Umbraco.Cms.Api.Management.ViewModels.Media.Item;
using Umbraco.Cms.Api.Management.ViewModels.MediaType;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Mapping;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Entities;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Factories;

internal sealed class MediaPresentationFactory : IMediaPresentationFactory
{
private readonly IUmbracoMapper _umbracoMapper;
private readonly IMediaUrlFactory _mediaUrlFactory;
private readonly IIdKeyMap _idKeyMap;

public MediaPresentationFactory(
IUmbracoMapper umbracoMapper,
IMediaUrlFactory mediaUrlFactory)
IMediaUrlFactory mediaUrlFactory,
IIdKeyMap idKeyMap)
{
_umbracoMapper = umbracoMapper;
_mediaUrlFactory = mediaUrlFactory;
_idKeyMap = idKeyMap;
}

public MediaResponseModel CreateResponseModel(IMedia media)
Expand All @@ -32,10 +38,14 @@ public MediaResponseModel CreateResponseModel(IMedia media)

public MediaItemResponseModel CreateItemResponseModel(IMediaEntitySlim entity)
{
Attempt<Guid> parentKeyAttempt = _idKeyMap.GetKeyForId(entity.ParentId, UmbracoObjectTypes.Media);

var responseModel = new MediaItemResponseModel
{
Id = entity.Key,
IsTrashed = entity.Trashed
IsTrashed = entity.Trashed,
Parent = parentKeyAttempt.Success ? new ReferenceByIdModel { Id = parentKeyAttempt.Result } : null,
HasChildren = entity.HasChildren,
};

responseModel.MediaType = _umbracoMapper.Map<MediaTypeReferenceResponseModel>(entity)!;
Expand Down
24 changes: 24 additions & 0 deletions src/Umbraco.Cms.Api.Management/OpenApi.json
Original file line number Diff line number Diff line change
Expand Up @@ -36738,6 +36738,7 @@
"DocumentItemResponseModel": {
"required": [
"documentType",
"hasChildren",
"id",
"isProtected",
"isTrashed",
Expand All @@ -36755,6 +36756,17 @@
"isProtected": {
"type": "boolean"
},
"parent": {
"oneOf": [
{
"$ref": "#/components/schemas/ReferenceByIdModel"
}
],
"nullable": true
},
"hasChildren": {
"type": "boolean"
},
"documentType": {
"oneOf": [
{
Expand Down Expand Up @@ -38895,6 +38907,7 @@
},
"MediaItemResponseModel": {
"required": [
"hasChildren",
"id",
"isTrashed",
"mediaType",
Expand All @@ -38909,6 +38922,17 @@
"isTrashed": {
"type": "boolean"
},
"parent": {
"oneOf": [
{
"$ref": "#/components/schemas/ReferenceByIdModel"
}
],
"nullable": true
},
"hasChildren": {
"type": "boolean"
},
"mediaType": {
"oneOf": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public class DocumentItemResponseModel : ItemResponseModelBase

public bool IsProtected { get; set; }

public ReferenceByIdModel? Parent { get; set; }

public bool HasChildren { get; set; }

public DocumentTypeReferenceResponseModel DocumentType { get; set; } = new();

public IEnumerable<DocumentVariantItemResponseModel> Variants { get; set; } = Enumerable.Empty<DocumentVariantItemResponseModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ public class MediaItemResponseModel : ItemResponseModelBase
{
public bool IsTrashed { get; set; }

public ReferenceByIdModel? Parent { get; set; }

public bool HasChildren { get; set; }

public MediaTypeReferenceResponseModel MediaType { get; set; } = new();

public IEnumerable<VariantItemResponseModel> Variants { get; set; } = Enumerable.Empty<VariantItemResponseModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ export type DocumentItemResponseModel = {
id: string;
isTrashed: boolean;
isProtected: boolean;
parent?: ((ReferenceByIdModel) | null);
hasChildren: boolean;
documentType: (DocumentTypeReferenceResponseModel);
variants: Array<(DocumentVariantItemResponseModel)>;
};
Expand Down Expand Up @@ -1185,6 +1187,8 @@ export type MediaConfigurationResponseModel = {
export type MediaItemResponseModel = {
id: string;
isTrashed: boolean;
parent?: ((ReferenceByIdModel) | null);
hasChildren: boolean;
mediaType: (MediaTypeReferenceResponseModel);
variants: Array<(VariantItemResponseModel)>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ const itemMapper = (model: UmbMockDocumentBlueprintModel): DocumentItemResponseM
icon: model.documentType.icon,
id: model.documentType.id,
},
hasChildren: model.hasChildren,
id: model.id,
isProtected: model.isProtected,
isTrashed: model.isTrashed,
parent: model.parent,
variants: model.variants,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ const itemMapper = (model: UmbMockDocumentModel): DocumentItemResponseModel => {
icon: model.documentType.icon,
id: model.documentType.id,
},
hasChildren: model.hasChildren,
id: model.id,
isProtected: model.isProtected,
isTrashed: model.isTrashed,
parent: model.parent,
variants: model.variants,
};
};
Expand Down
2 changes: 2 additions & 0 deletions src/Umbraco.Web.UI.Client/src/mocks/data/media/media.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ const itemMapper = (model: UmbMockMediaModel): MediaItemResponseModel => {
icon: model.mediaType.icon,
id: model.mediaType.id,
},
hasChildren: model.hasChildren,
id: model.id,
isTrashed: model.isTrashed,
parent: model.parent,
variants: model.variants,
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface UmbNumberRangeValueType {
max?: number;
}

// TODO: this needs to use the UmbEntityUnique so we ensure that unique can be null
export interface UmbReferenceByUnique {
unique: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,24 @@ const getItems = (uniques: Array<string>) => DocumentService.getItemDocument({ i

const mapper = (item: DocumentItemResponseModel): UmbDocumentItemModel => {
return {
entityType: UMB_DOCUMENT_ENTITY_TYPE,
unique: item.id,
isTrashed: item.isTrashed,
isProtected: item.isProtected,
documentType: {
unique: item.documentType.id,
icon: item.documentType.icon,
collection: item.documentType.collection ? { unique: item.documentType.collection.id } : null,
icon: item.documentType.icon,
unique: item.documentType.id,
},
entityType: UMB_DOCUMENT_ENTITY_TYPE,
hasChildren: item.hasChildren,
isProtected: item.isProtected,
isTrashed: item.isTrashed,
name: item.variants[0]?.name, // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
parent: item.parent ? { unique: item.parent.id } : null,
unique: item.id,
variants: item.variants.map((variant) => {
return {
culture: variant.culture || null,
name: variant.name,
state: variant.state,
};
}),
name: item.variants[0]?.name, // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
};
};
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity';
import type { UmbDocumentEntityType } from '../../entity.js';
import type { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api';
import type { UmbReferenceByUnique } from '@umbraco-cms/backoffice/models';

export interface UmbDocumentItemModel {
entityType: UmbDocumentEntityType;
name: string; // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
unique: string;
isTrashed: boolean;
isProtected: boolean;
documentType: {
unique: string;
icon: string;
collection: UmbReferenceByUnique | null;
};
entityType: UmbDocumentEntityType;
hasChildren: boolean;
isProtected: boolean;
isTrashed: boolean;
name: string; // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
parent: { unique: UmbEntityUnique } | null; // TODO: Use UmbReferenceByUnique when it support unique as null
unique: string;
variants: Array<UmbDocumentItemVariantModel>;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UmbDocumentSearchServerDataSource } from './document-search.server.data-source.js';
import type { UmbDocumentSearchItemModel } from './document.search-provider.js';
import type { UmbSearchRepository, UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
import type { UmbDocumentSearchItemModel } from './types.js';

export class UmbDocumentSearchRepository
extends UmbControllerBase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UMB_DOCUMENT_ENTITY_TYPE } from '../entity.js';
import type { UmbDocumentSearchItemModel } from './document.search-provider.js';
import type { UmbSearchDataSource, UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { DocumentService } from '@umbraco-cms/backoffice/external/backend-api';
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
import type { UmbDocumentSearchItemModel } from './types.js';

/**
* A data source for the Rollback that fetches data from the server
Expand Down Expand Up @@ -40,24 +40,26 @@ export class UmbDocumentSearchServerDataSource implements UmbSearchDataSource<Um
if (data) {
const mappedItems: Array<UmbDocumentSearchItemModel> = data.items.map((item) => {
return {
href: '/section/content/workspace/document/edit/' + item.id,
entityType: UMB_DOCUMENT_ENTITY_TYPE,
unique: item.id,
isTrashed: item.isTrashed,
isProtected: item.isProtected,
documentType: {
unique: item.documentType.id,
icon: item.documentType.icon,
collection: item.documentType.collection ? { unique: item.documentType.collection.id } : null,
icon: item.documentType.icon,
unique: item.documentType.id,
},
entityType: UMB_DOCUMENT_ENTITY_TYPE,
hasChildren: item.hasChildren,
href: '/section/content/workspace/document/edit/' + item.id,
isProtected: item.isProtected,
isTrashed: item.isTrashed,
name: item.variants[0]?.name, // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
parent: item.parent ? { unique: item.parent.id } : null,
unique: item.id,
variants: item.variants.map((variant) => {
return {
culture: variant.culture || null,
name: variant.name,
state: variant.state,
};
}),
name: item.variants[0]?.name, // TODO: this is not correct. We need to get it from the variants. This is a temp solution.
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import type { UmbDocumentItemModel } from '../index.js';
import { UmbDocumentSearchRepository } from './document-search.repository.js';
import type { UmbSearchProvider, UmbSearchRequestArgs } from '@umbraco-cms/backoffice/search';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
export interface UmbDocumentSearchItemModel extends UmbDocumentItemModel {
href: string;
}
import type { UmbDocumentSearchItemModel } from './types.js';

export class UmbDocumentSearchProvider
extends UmbControllerBase
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { UmbDocumentItemModel } from '../repository/index.js';

export interface UmbDocumentSearchItemModel extends UmbDocumentItemModel {
href: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ export class UmbInputMediaElement extends UmbFormControlMixin<string | undefined
return html`
<uui-card-media
name=${ifDefined(item.name === null ? undefined : item.name)}
detail=${ifDefined(item.unique)}
href="${ifDefined(href)}"
?readonly=${this.readonly}>
<umb-imaging-thumbnail
Expand Down
7 changes: 4 additions & 3 deletions src/Umbraco.Web.UI.Client/src/packages/media/media/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export * from './repository/index.js';
export * from './workspace/index.js';
export * from './reference/index.js';
export * from './components/index.js';
export * from './dropzone/index.js';
export * from './entity.js';
export * from './paths.js';
export * from './reference/index.js';
export * from './repository/index.js';
export * from './search/index.js';
export * from './utils/index.js';
export * from './workspace/index.js';

export { UMB_MEDIA_TREE_ALIAS, UMB_MEDIA_TREE_PICKER_MODAL } from './tree/index.js';
export { UMB_MEDIA_COLLECTION_ALIAS } from './collection/index.js';
Expand Down
Loading
Loading