From 669d58e6f08e635ff22994ada7a8635c92caf9e7 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 17 Dec 2024 09:31:58 +0100 Subject: [PATCH 1/2] Set product availability by product type in applies blocks --- .../Myst/FrontMatter/Deployment.cs | 21 +++++++-- .../FrontMatter/ProductConstraintTests.cs | 43 ++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/src/Elastic.Markdown/Myst/FrontMatter/Deployment.cs b/src/Elastic.Markdown/Myst/FrontMatter/Deployment.cs index 511c13fe2..9d4a9ff04 100644 --- a/src/Elastic.Markdown/Myst/FrontMatter/Deployment.cs +++ b/src/Elastic.Markdown/Myst/FrontMatter/Deployment.cs @@ -74,12 +74,27 @@ public class DeploymentConverter : IYamlTypeConverter if (string.Equals(value.Value, "all", StringComparison.InvariantCultureIgnoreCase)) return Deployment.All; } - var x = rootDeserializer.Invoke(typeof(Dictionary)); - if (x is not Dictionary { Count: > 0 } dictionary) + var deserialized = rootDeserializer.Invoke(typeof(Dictionary)); + if (deserialized is not Dictionary { Count: > 0 } dictionary) return null; var deployment = new Deployment(); - if (TryGetAvailability("stack", out var version)) + + if (TryGetAvailability("cloud", out var version)) + { + deployment.Cloud ??= new CloudManagedDeployment(); + deployment.Cloud.Serverless = version; + deployment.Cloud.Hosted = version; + } + if (TryGetAvailability("self", out version)) + { + deployment.SelfManaged ??= new SelfManagedDeployment(); + deployment.SelfManaged.Ece = version; + deployment.SelfManaged.Eck = version; + deployment.SelfManaged.Stack = version; + } + + if (TryGetAvailability("stack", out version)) { deployment.SelfManaged ??= new SelfManagedDeployment(); deployment.SelfManaged.Stack = version; diff --git a/tests/Elastic.Markdown.Tests/FrontMatter/ProductConstraintTests.cs b/tests/Elastic.Markdown.Tests/FrontMatter/ProductConstraintTests.cs index 63bbc2a3c..dd6a1b9cc 100644 --- a/tests/Elastic.Markdown.Tests/FrontMatter/ProductConstraintTests.cs +++ b/tests/Elastic.Markdown.Tests/FrontMatter/ProductConstraintTests.cs @@ -111,13 +111,13 @@ public void Assert() => File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Stack.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable); } -public class EmptyCloudSetsAllProductsToAll(ITestOutputHelper output) : DirectiveTest(output, +public class EmptyCloudSetsAllCloudProductsToAll(ITestOutputHelper output) : DirectiveTest(output, """ --- title: Elastic Docs v3 navigation_title: "Documentation Guide" applies: - hosted: + cloud: --- """ ) @@ -126,3 +126,42 @@ public class EmptyCloudSetsAllProductsToAll(ITestOutputHelper output) : Directiv public void Assert() => File.YamlFrontMatter!.AppliesTo!.Cloud!.Hosted.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable); } + +public class EmptySelfSetsAllSelfManagedProductsToAll(ITestOutputHelper output) : DirectiveTest(output, +""" +--- +title: Elastic Docs v3 +navigation_title: "Documentation Guide" +applies: + self: + stack: deprecated 9.0.0 +--- +""" +) +{ + [Fact] + public void Assert() + { + File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Eck.Should() + .BeEquivalentTo(ProductAvailability.GenerallyAvailable); + File.YamlFrontMatter!.AppliesTo!.SelfManaged!.Stack.Should() + .BeEquivalentTo(new ProductAvailability { Lifecycle = Deprecated, Version = new (9,0,0) }); + } +} + +public class CloudProductsOverwriteDeploymentType(ITestOutputHelper output) : DirectiveTest(output, +""" +--- +title: Elastic Docs v3 +navigation_title: "Documentation Guide" +applies: + cloud: +--- +""" +) +{ + [Fact] + public void Assert() => + File.YamlFrontMatter!.AppliesTo!.Cloud!.Hosted.Should().BeEquivalentTo(ProductAvailability.GenerallyAvailable); +} + From 0cedc8a8427220b476ef98843c9303e6a9969691 Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Tue, 17 Dec 2024 09:36:58 +0100 Subject: [PATCH 2/2] Add cloud/self support to {applies} directive --- docs/source/markup/applies.md | 12 ++++++++---- .../Myst/Directives/AppliesBlock.cs | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/docs/source/markup/applies.md b/docs/source/markup/applies.md index fece0b0d9..2d540cdd7 100644 --- a/docs/source/markup/applies.md +++ b/docs/source/markup/applies.md @@ -49,12 +49,16 @@ Are equivalent, note `all` just means we won't be rendering the version portion ## This section has its own applies annotations -```{applies} +:::{applies} :stack: unavailable :serverless: tech-preview -``` +:cloud: ga +::: -This section describes a feature that's unavailable in `stack` and in tech preview on `serverless` +:::{note} +the `{applies}` directive **MUST** be preceded by a heading. +::: -the `{applies}` directive **MUST** be preceded by a heading. \ No newline at end of file +This section describes a feature that's unavailable in `stack` and `ga` in all cloud products +however its tech preview on `serverless` since it overrides what `cloud` specified. diff --git a/src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs b/src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs index f4750344f..a825c7633 100644 --- a/src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs @@ -16,7 +16,23 @@ public class AppliesBlock(DirectiveBlockParser parser, Dictionary