Merge branch 'main' into v17/dev
This commit is contained in:
@@ -12,6 +12,7 @@ internal static class DocumentVariantStateHelper
|
||||
culture,
|
||||
content.Edited,
|
||||
content.Published,
|
||||
content.Trashed,
|
||||
content.AvailableCultures,
|
||||
content.EditedCultures ?? Enumerable.Empty<string>(),
|
||||
content.PublishedCultures);
|
||||
@@ -22,17 +23,23 @@ internal static class DocumentVariantStateHelper
|
||||
culture,
|
||||
content.Edited,
|
||||
content.Published,
|
||||
content.Trashed,
|
||||
content.CultureNames.Keys,
|
||||
content.EditedCultures,
|
||||
content.PublishedCultures);
|
||||
|
||||
private static DocumentVariantState GetState(IEntity entity, string? culture, bool edited, bool published, IEnumerable<string> availableCultures, IEnumerable<string> editedCultures, IEnumerable<string> publishedCultures)
|
||||
private static DocumentVariantState GetState(IEntity entity, string? culture, bool edited, bool published, bool trashed, IEnumerable<string> availableCultures, IEnumerable<string> editedCultures, IEnumerable<string> publishedCultures)
|
||||
{
|
||||
if (entity.Id <= 0 || (culture is not null && availableCultures.Contains(culture) is false))
|
||||
{
|
||||
return DocumentVariantState.NotCreated;
|
||||
}
|
||||
|
||||
if (trashed)
|
||||
{
|
||||
return DocumentVariantState.Trashed;
|
||||
}
|
||||
|
||||
var isDraft = published is false ||
|
||||
(culture != null && publishedCultures.Contains(culture) is false);
|
||||
if (isDraft)
|
||||
|
||||
@@ -24,4 +24,9 @@ public enum DocumentVariantState
|
||||
/// The item is published and there are pending changes
|
||||
/// </summary>
|
||||
PublishedPendingChanges = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The item is in the recycle bin
|
||||
/// </summary>
|
||||
Trashed = 5,
|
||||
}
|
||||
|
||||
966
src/Umbraco.Web.UI.Client/package-lock.json
generated
966
src/Umbraco.Web.UI.Client/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
"build": "vite build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@umbraco-ui/uui": "^1.16.0-rc.0",
|
||||
"@umbraco-ui/uui-css": "^1.16.0-rc.0"
|
||||
"@umbraco-ui/uui": "^1.16.0",
|
||||
"@umbraco-ui/uui-css": "^1.16.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ export class UmbTemplateWorkspaceEditorElement extends UmbLitElement {
|
||||
}
|
||||
|
||||
#resetMasterTemplate() {
|
||||
this.#templateWorkspaceContext?.setMasterTemplate(null);
|
||||
this.#templateWorkspaceContext?.setMasterTemplate(null, true);
|
||||
}
|
||||
|
||||
#openMasterTemplatePicker() {
|
||||
@@ -121,7 +121,7 @@ export class UmbTemplateWorkspaceEditorElement extends UmbLitElement {
|
||||
?.onSubmit()
|
||||
.then((value) => {
|
||||
if (!value?.selection) return;
|
||||
this.#templateWorkspaceContext?.setMasterTemplate(value.selection[0] ?? null);
|
||||
this.#templateWorkspaceContext?.setMasterTemplate(value.selection[0] ?? null, true);
|
||||
})
|
||||
.catch(() => undefined);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,15 @@ export class UmbTemplateWorkspaceContext
|
||||
|
||||
override async load(unique: string) {
|
||||
const response = await super.load(unique);
|
||||
await this.setMasterTemplate(response.data?.masterTemplate?.unique ?? null);
|
||||
|
||||
// On load we want to set the master template details but not update the layout block in the Razor file.
|
||||
// This is because you can still set a layout in code by setting `Layout = "_Layout.cshtml";` in the template file.
|
||||
// This gets set automatically if you create a template under a parent, but you don't have to do that, you can
|
||||
// just set the `Layout` property in the Razor template file itself.
|
||||
// So even if there's no master template set by there being a parent, there may still be one set in the Razor
|
||||
// code, and we shouldn't overwrite it.
|
||||
await this.setMasterTemplate(response.data?.masterTemplate?.unique ?? null, false);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -79,9 +87,9 @@ export class UmbTemplateWorkspaceContext
|
||||
},
|
||||
});
|
||||
|
||||
// Set or reset the master template
|
||||
// This is important to reset when a new template is created so the UI reflects the correct state
|
||||
await this.setMasterTemplate(parent.unique);
|
||||
// On create set or reset the master template depending on whether the template is being created under a parent.
|
||||
// This is important to reset when a new template is created so the UI reflects the correct state.
|
||||
await this.setMasterTemplate(parent.unique, true);
|
||||
|
||||
return data;
|
||||
}
|
||||
@@ -102,7 +110,7 @@ export class UmbTemplateWorkspaceContext
|
||||
return this.getData()?.content ? this.getLayoutBlockRegexPattern().test(this.getData()?.content as string) : false;
|
||||
}
|
||||
|
||||
async setMasterTemplate(unique: string | null) {
|
||||
async setMasterTemplate(unique: string | null, updateLayoutBlock: boolean) {
|
||||
if (unique === null) {
|
||||
this.#masterTemplate.setValue(null);
|
||||
} else {
|
||||
@@ -113,7 +121,10 @@ export class UmbTemplateWorkspaceContext
|
||||
}
|
||||
}
|
||||
|
||||
this.#updateMasterTemplateLayoutBlock();
|
||||
if (updateLayoutBlock) {
|
||||
this.#updateMasterTemplateLayoutBlock();
|
||||
}
|
||||
|
||||
this._data.updateCurrent({ masterTemplate: unique ? { unique } : null });
|
||||
|
||||
return unique;
|
||||
|
||||
@@ -11,13 +11,14 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Cms.Api.Management.Mapping.Content
|
||||
[TestFixture]
|
||||
public class DocumentVariantStateHelperTests
|
||||
{
|
||||
[TestCase(false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, DocumentVariantState.PublishedPendingChanges)]
|
||||
public void Culture_Invariant_Content_State(bool edited, bool published, DocumentVariantState expectedResult)
|
||||
[TestCase(false, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, false, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, false, DocumentVariantState.PublishedPendingChanges)]
|
||||
[TestCase(true, false, true, DocumentVariantState.Trashed)]
|
||||
public void Culture_Invariant_Content_State(bool edited, bool published, bool trashed, DocumentVariantState expectedResult)
|
||||
{
|
||||
var content = Mock.Of<IContent>(c => c.Id == 1 && c.Published == published && c.Edited == edited);
|
||||
var content = Mock.Of<IContent>(c => c.Id == 1 && c.Published == published && c.Edited == edited && c.Trashed == trashed);
|
||||
Assert.AreEqual(expectedResult, DocumentVariantStateHelper.GetState(content, culture: null));
|
||||
}
|
||||
|
||||
@@ -31,11 +32,12 @@ public class DocumentVariantStateHelperTests
|
||||
Assert.AreEqual(DocumentVariantState.NotCreated, DocumentVariantStateHelper.GetState(content, culture: null));
|
||||
}
|
||||
|
||||
[TestCase(false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, DocumentVariantState.PublishedPendingChanges)]
|
||||
public void Culture_Variant_Content_Existing_Culture_State(bool edited, bool published, DocumentVariantState expectedResult)
|
||||
[TestCase(false, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, false, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, false, DocumentVariantState.PublishedPendingChanges)]
|
||||
[TestCase(true, false, true, DocumentVariantState.Trashed)]
|
||||
public void Culture_Variant_Content_Existing_Culture_State(bool edited, bool published, bool trashed, DocumentVariantState expectedResult)
|
||||
{
|
||||
const string culture = "en";
|
||||
var content = Mock.Of<IContent>(c =>
|
||||
@@ -43,7 +45,8 @@ public class DocumentVariantStateHelperTests
|
||||
&& c.AvailableCultures == new[] { culture }
|
||||
&& c.EditedCultures == (edited ? new[] { culture } : Enumerable.Empty<string>())
|
||||
&& c.Published == published
|
||||
&& c.PublishedCultures == (published ? new[] { culture } : Enumerable.Empty<string>()));
|
||||
&& c.PublishedCultures == (published ? new[] { culture } : Enumerable.Empty<string>())
|
||||
&& c.Trashed == trashed);
|
||||
Assert.AreEqual(expectedResult, DocumentVariantStateHelper.GetState(content, culture));
|
||||
}
|
||||
|
||||
@@ -63,13 +66,14 @@ public class DocumentVariantStateHelperTests
|
||||
Assert.AreEqual(DocumentVariantState.NotCreated, DocumentVariantStateHelper.GetState(content, "dk"));
|
||||
}
|
||||
|
||||
[TestCase(false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, DocumentVariantState.PublishedPendingChanges)]
|
||||
public void Culture_Invariant_DocumentEntitySlim_State(bool edited, bool published, DocumentVariantState expectedResult)
|
||||
[TestCase(false, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, false, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, false, DocumentVariantState.PublishedPendingChanges)]
|
||||
[TestCase(true, false, true, DocumentVariantState.Trashed)]
|
||||
public void Culture_Invariant_DocumentEntitySlim_State(bool edited, bool published, bool trashed, DocumentVariantState expectedResult)
|
||||
{
|
||||
var entity = Mock.Of<IDocumentEntitySlim>(c => c.Id == 1 && c.Published == published && c.Edited == edited && c.CultureNames == new Dictionary<string, string>());
|
||||
var entity = Mock.Of<IDocumentEntitySlim>(c => c.Id == 1 && c.Published == published && c.Edited == edited && c.CultureNames == new Dictionary<string, string>() && c.Trashed == trashed);
|
||||
Assert.AreEqual(expectedResult, DocumentVariantStateHelper.GetState(entity, culture: null));
|
||||
}
|
||||
|
||||
@@ -83,11 +87,12 @@ public class DocumentVariantStateHelperTests
|
||||
Assert.AreEqual(DocumentVariantState.NotCreated, DocumentVariantStateHelper.GetState(entity, culture: null));
|
||||
}
|
||||
|
||||
[TestCase(false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, DocumentVariantState.PublishedPendingChanges)]
|
||||
public void Culture_Variant_DocumentEntitySlim_Existing_Culture_State(bool edited, bool published, DocumentVariantState expectedResult)
|
||||
[TestCase(false, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(false, true, false, DocumentVariantState.Published)]
|
||||
[TestCase(true, false, false, DocumentVariantState.Draft)]
|
||||
[TestCase(true, true, false, DocumentVariantState.PublishedPendingChanges)]
|
||||
[TestCase(true, false, true, DocumentVariantState.Trashed)]
|
||||
public void Culture_Variant_DocumentEntitySlim_Existing_Culture_State(bool edited, bool published, bool trashed, DocumentVariantState expectedResult)
|
||||
{
|
||||
const string culture = "en";
|
||||
var entity = Mock.Of<IDocumentEntitySlim>(c =>
|
||||
@@ -95,7 +100,8 @@ public class DocumentVariantStateHelperTests
|
||||
&& c.CultureNames == new Dictionary<string, string> { { culture, "value does not matter" } }
|
||||
&& c.EditedCultures == (edited ? new[] { culture } : Enumerable.Empty<string>())
|
||||
&& c.Published == published
|
||||
&& c.PublishedCultures == (published ? new[] { culture } : Enumerable.Empty<string>()));
|
||||
&& c.PublishedCultures == (published ? new[] { culture } : Enumerable.Empty<string>())
|
||||
&& c.Trashed == trashed);
|
||||
Assert.AreEqual(expectedResult, DocumentVariantStateHelper.GetState(entity, culture));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user