Merge branch 'v15/bugfix/fix-omitted-callback' into v15/bugfix/17312
This commit is contained in:
@@ -53,21 +53,26 @@ export const UmbClassMixin = <T extends ClassConstructor<EventTarget>>(superClas
|
||||
>(
|
||||
// This type dance checks if the Observable given could be undefined, if it potentially could be undefined it means that this potentially could return undefined and then call the callback with undefined. [NL]
|
||||
source: ObservableType,
|
||||
callback: ObserverCallback<SpecificT>,
|
||||
callback?: ObserverCallback<SpecificT>,
|
||||
controllerAlias?: UmbControllerAlias | null,
|
||||
): SpecificR {
|
||||
// Fallback to use a hash of the provided method, but only if the alias is undefined.
|
||||
controllerAlias ??= controllerAlias === undefined ? simpleHashCode(callback.toString()) : undefined;
|
||||
// Fallback to use a hash of the provided method, but only if the alias is undefined and there is a callback.
|
||||
if (controllerAlias === undefined && callback) {
|
||||
controllerAlias = simpleHashCode(callback.toString());
|
||||
} else if (controllerAlias === null) {
|
||||
// if value is null, then reset it to undefined. Null is used to explicitly tell that we do not want a controller alias. [NL]
|
||||
controllerAlias = undefined;
|
||||
}
|
||||
|
||||
if (source) {
|
||||
return new UmbObserverController<T>(
|
||||
this,
|
||||
source,
|
||||
callback as unknown as ObserverCallback<T>,
|
||||
callback as unknown as ObserverCallback<T> | undefined,
|
||||
controllerAlias,
|
||||
) as unknown as SpecificR;
|
||||
} else {
|
||||
callback(undefined as SpecificT);
|
||||
callback?.(undefined as SpecificT);
|
||||
this.removeUmbControllerByAlias(controllerAlias);
|
||||
return undefined as SpecificR;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ export const UmbControllerHostElementMixin = <T extends HTMLElementConstructor>(
|
||||
super.disconnectedCallback?.();
|
||||
this.hostDisconnected();
|
||||
}
|
||||
|
||||
override destroy(): void {}
|
||||
}
|
||||
|
||||
return UmbControllerHostElementClass as unknown as HTMLElementConstructor<UmbControllerHostElement> & T;
|
||||
|
||||
@@ -29,21 +29,26 @@ export const UmbElementMixin = <T extends HTMLElementConstructor>(superClass: T)
|
||||
>(
|
||||
// This type dance checks if the Observable given could be undefined, if it potentially could be undefined it means that this potentially could return undefined and then call the callback with undefined. [NL]
|
||||
source: ObservableType,
|
||||
callback: ObserverCallback<SpecificT>,
|
||||
callback?: ObserverCallback<SpecificT>,
|
||||
controllerAlias?: UmbControllerAlias | null,
|
||||
): SpecificR {
|
||||
// Fallback to use a hash of the provided method, but only if the alias is undefined.
|
||||
controllerAlias ??= controllerAlias === undefined ? simpleHashCode(callback.toString()) : undefined;
|
||||
// Fallback to use a hash of the provided method, but only if the alias is undefined and there is a callback.
|
||||
if (controllerAlias === undefined && callback) {
|
||||
controllerAlias = simpleHashCode(callback.toString());
|
||||
} else if (controllerAlias === null) {
|
||||
// if value is null, then reset it to undefined. Null is used to explicitly tell that we do not want a controller alias. [NL]
|
||||
controllerAlias = undefined;
|
||||
}
|
||||
|
||||
if (source) {
|
||||
return new UmbObserverController<T>(
|
||||
this,
|
||||
source,
|
||||
callback as unknown as ObserverCallback<T>,
|
||||
callback as unknown as ObserverCallback<T> | undefined,
|
||||
controllerAlias,
|
||||
) as unknown as SpecificR;
|
||||
} else {
|
||||
callback(undefined as SpecificT);
|
||||
callback?.(undefined as SpecificT);
|
||||
this.removeUmbControllerByAlias(controllerAlias);
|
||||
return undefined as SpecificR;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { UMB_DOCUMENT_ENTITY_TYPE, UMB_DOCUMENT_ROOT_ENTITY_TYPE } from '../../entity.js';
|
||||
import { UMB_DUPLICATE_DOCUMENT_MODAL } from './modal/index.js';
|
||||
import { UmbDuplicateDocumentRepository } from './repository/index.js';
|
||||
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
import { UmbEntityActionBase, UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/entity-action';
|
||||
import { UmbEntityActionBase, UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action';
|
||||
|
||||
export class UmbDuplicateDocumentEntityAction extends UmbEntityActionBase<never> {
|
||||
override async execute() {
|
||||
@@ -32,22 +33,28 @@ export class UmbDuplicateDocumentEntityAction extends UmbEntityActionBase<never>
|
||||
});
|
||||
|
||||
if (!error) {
|
||||
this.#reloadMenu();
|
||||
this.#reloadMenu(destinationUnique);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async #reloadMenu() {
|
||||
async #reloadMenu(destinationUnique: string | null) {
|
||||
const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
|
||||
const event = new UmbRequestReloadStructureForEntityEvent({
|
||||
unique: this.args.unique,
|
||||
entityType: this.args.entityType,
|
||||
|
||||
// When duplicating, the destination entity type may or may not be the same as that of
|
||||
// the item selected for duplication (that is available in this.args).
|
||||
// For documents though, we know the entity type will be "document", unless we are duplicating
|
||||
// to the root (when the destinationUnique will be null).
|
||||
const destinationEntityType = destinationUnique === null ? UMB_DOCUMENT_ROOT_ENTITY_TYPE : UMB_DOCUMENT_ENTITY_TYPE;
|
||||
|
||||
const event = new UmbRequestReloadChildrenOfEntityEvent({
|
||||
unique: destinationUnique,
|
||||
entityType: destinationEntityType,
|
||||
});
|
||||
|
||||
actionEventContext.dispatchEvent(event);
|
||||
// TODO: Reload destination
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
import { observeMultiple } from '@umbraco-cms/backoffice/observable-api';
|
||||
import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api';
|
||||
import { debounce } from '@umbraco-cms/backoffice/utils';
|
||||
import { UMB_APP_LANGUAGE_CONTEXT } from '@umbraco-cms/backoffice/language';
|
||||
|
||||
interface UmbDocumentInfoViewLink {
|
||||
culture: string;
|
||||
@@ -36,6 +37,9 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
|
||||
@state()
|
||||
private _links: Array<UmbDocumentInfoViewLink> = [];
|
||||
|
||||
@state()
|
||||
private _defaultCulture?: string;
|
||||
|
||||
#urls: Array<UmbDocumentUrlModel> = [];
|
||||
|
||||
#documentWorkspaceContext?: typeof UMB_DOCUMENT_WORKSPACE_CONTEXT.TYPE;
|
||||
@@ -75,17 +79,19 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
|
||||
this.#setLinks();
|
||||
});
|
||||
});
|
||||
|
||||
this.consumeContext(UMB_APP_LANGUAGE_CONTEXT, (instance) => {
|
||||
this.observe(instance.appDefaultLanguage, (value) => {
|
||||
this._defaultCulture = value?.unique;
|
||||
this.#setLinks();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#setLinks() {
|
||||
const possibleVariantCultures = this._variantOptions?.map((variantOption) => variantOption.culture) ?? [];
|
||||
const possibleUrlCultures = this.#urls.map((link) => link.culture);
|
||||
const possibleCultures = [...new Set([...possibleVariantCultures, ...possibleUrlCultures])].filter(
|
||||
Boolean,
|
||||
) as string[];
|
||||
|
||||
const links: Array<UmbDocumentInfoViewLink> = possibleCultures.map((culture) => {
|
||||
const url = this.#urls.find((link) => link.culture === culture)?.url;
|
||||
const links: Array<UmbDocumentInfoViewLink> = this.#urls.map((u) => {
|
||||
const culture = u.culture ?? this._defaultCulture ?? "";
|
||||
const url = u.url;
|
||||
const state = this._variantOptions?.find((variantOption) => variantOption.culture === culture)?.variant?.state;
|
||||
return { culture, url, state };
|
||||
});
|
||||
@@ -93,6 +99,18 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
|
||||
this._links = links;
|
||||
}
|
||||
|
||||
#getTargetUrl (url: string | undefined) {
|
||||
if (!url || url.length === 0) {
|
||||
return url;
|
||||
}
|
||||
|
||||
if (url.includes(".") && !url.includes("//")) {
|
||||
return "//" + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
async #requestUrls() {
|
||||
if (this._isNew) return;
|
||||
if (!this._unique) return;
|
||||
@@ -181,7 +199,7 @@ export class UmbDocumentWorkspaceViewInfoLinksElement extends UmbLitElement {
|
||||
}
|
||||
|
||||
return html`
|
||||
<a class="link-item" href=${link.url} target="_blank">
|
||||
<a class="link-item" href=${this.#getTargetUrl(link.url)} target="_blank">
|
||||
<span>
|
||||
${this.#renderLinkCulture(link.culture)}
|
||||
<span>${link.url}</span>
|
||||
|
||||
Reference in New Issue
Block a user