-
Notifications
You must be signed in to change notification settings - Fork 32
Refactor applies_to #1878
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
Merged
Merged
Refactor applies_to #1878
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c1f7ad
Refactor applies_to
reakaleek e0ac169
Update src/Elastic.Markdown/Myst/Components/ApplicabilityMappings.cs
reakaleek 3339962
Update src/Elastic.Markdown/Myst/Components/ApplicableToComponent.cshtml
reakaleek 327a2fa
Fix naming
reakaleek 19d04d5
Simplify a bit
reakaleek 324d1e1
Use properties instead of dictionary
reakaleek 6c2ffb8
Refactor repeating logic
reakaleek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using Elastic.Documentation.AppliesTo; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Components; | ||
|
|
||
| public record ApplicabilityItem( | ||
| string Key, | ||
| Applicability Applicability, | ||
| ApplicabilityRenderer.ApplicabilityRenderData RenderData | ||
| ); |
57 changes: 57 additions & 0 deletions
57
src/Elastic.Markdown/Myst/Components/ApplicabilityMappings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using Elastic.Documentation.Configuration.Versions; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Components; | ||
|
|
||
| public static class ApplicabilityMappings | ||
| { | ||
| public record ApplicabilityDefinition(string Key, string DisplayName, VersioningSystemId VersioningSystemId); | ||
|
|
||
| // Stack | ||
| public static readonly ApplicabilityDefinition Stack = new("Stack", "Elastic Stack", VersioningSystemId.Stack); | ||
|
|
||
| // Serverless | ||
| public static readonly ApplicabilityDefinition Serverless = new("Serverless", "Elastic Cloud Serverless", VersioningSystemId.Serverless); | ||
| public static readonly ApplicabilityDefinition ServerlessElasticsearch = new("Serverless Elasticsearch", "Serverless Elasticsearch projects", VersioningSystemId.ElasticsearchProject); | ||
| public static readonly ApplicabilityDefinition ServerlessObservability = new("Serverless Observability", "Serverless Observability projects", VersioningSystemId.ObservabilityProject); | ||
| public static readonly ApplicabilityDefinition ServerlessSecurity = new("Serverless Security", "Serverless Security projects", VersioningSystemId.SecurityProject); | ||
|
|
||
| // Deployment | ||
| public static readonly ApplicabilityDefinition Ech = new("ECH", "Elastic Cloud Hosted", VersioningSystemId.Ess); | ||
| public static readonly ApplicabilityDefinition Eck = new("ECK", "Elastic Cloud on Kubernetes", VersioningSystemId.Eck); | ||
| public static readonly ApplicabilityDefinition Ece = new("ECE", "Elastic Cloud Enterprise", VersioningSystemId.Ece); | ||
| public static readonly ApplicabilityDefinition Self = new("Self-Managed", "Self-managed Elastic deployments", VersioningSystemId.Self); | ||
|
|
||
| // Product Applicability | ||
| public static readonly ApplicabilityDefinition Ecctl = new("ECCTL", "Elastic Cloud Control", VersioningSystemId.Ecctl); | ||
| public static readonly ApplicabilityDefinition Curator = new("Curator", "Curator", VersioningSystemId.Curator); | ||
|
|
||
| // EDOT Products | ||
| public static readonly ApplicabilityDefinition EdotAndroid = new("EDOT Android", "Elastic Distribution of OpenTelemetry Android", VersioningSystemId.EdotAndroid); | ||
| public static readonly ApplicabilityDefinition EdotCfAws = new("EDOT CF AWS", "Elastic Distribution of OpenTelemetry Cloud Forwarder for AWS", VersioningSystemId.EdotCfAws); | ||
| public static readonly ApplicabilityDefinition EdotCollector = new("EDOT Collector", "Elastic Distribution of OpenTelemetry Collector", VersioningSystemId.EdotCollector); | ||
| public static readonly ApplicabilityDefinition EdotDotnet = new("EDOT .NET", "Elastic Distribution of OpenTelemetry .NET", VersioningSystemId.EdotDotnet); | ||
| public static readonly ApplicabilityDefinition EdotIos = new("EDOT iOS", "Elastic Distribution of OpenTelemetry iOS", VersioningSystemId.EdotIos); | ||
| public static readonly ApplicabilityDefinition EdotJava = new("EDOT Java", "Elastic Distribution of OpenTelemetry Java", VersioningSystemId.EdotJava); | ||
| public static readonly ApplicabilityDefinition EdotNode = new("EDOT Node.js", "Elastic Distribution of OpenTelemetry Node.js", VersioningSystemId.EdotNode); | ||
| public static readonly ApplicabilityDefinition EdotPhp = new("EDOT PHP", "Elastic Distribution of OpenTelemetry PHP", VersioningSystemId.EdotPhp); | ||
| public static readonly ApplicabilityDefinition EdotPython = new("EDOT Python", "Elastic Distribution of OpenTelemetry Python", VersioningSystemId.EdotPython); | ||
|
|
||
| // APM Agents | ||
| public static readonly ApplicabilityDefinition ApmAgentAndroid = new("APM Agent Android", "Application Performance Monitoring Agent for Android", VersioningSystemId.ApmAgentAndroid); | ||
| public static readonly ApplicabilityDefinition ApmAgentDotnet = new("APM Agent .NET", "Application Performance Monitoring Agent for .NET", VersioningSystemId.ApmAgentDotnet); | ||
| public static readonly ApplicabilityDefinition ApmAgentGo = new("APM Agent Go", "Application Performance Monitoring Agent for Go", VersioningSystemId.ApmAgentGo); | ||
| public static readonly ApplicabilityDefinition ApmAgentIos = new("APM Agent iOS", "Application Performance Monitoring Agent for iOS", VersioningSystemId.ApmAgentIos); | ||
| public static readonly ApplicabilityDefinition ApmAgentJava = new("APM Agent Java", "Application Performance Monitoring Agent for Java", VersioningSystemId.ApmAgentJava); | ||
| public static readonly ApplicabilityDefinition ApmAgentNode = new("APM Agent Node.js", "Application Performance Monitoring Agent for Node.js", VersioningSystemId.ApmAgentNode); | ||
| public static readonly ApplicabilityDefinition ApmAgentPhp = new("APM Agent PHP", "Application Performance Monitoring Agent for PHP", VersioningSystemId.ApmAgentPhp); | ||
| public static readonly ApplicabilityDefinition ApmAgentPython = new("APM Agent Python", "Application Performance Monitoring Agent for Python", VersioningSystemId.ApmAgentPython); | ||
| public static readonly ApplicabilityDefinition ApmAgentRuby = new("APM Agent Ruby", "Application Performance Monitoring Agent for Ruby", VersioningSystemId.ApmAgentRuby); | ||
| public static readonly ApplicabilityDefinition ApmAgentRum = new("APM Agent RUM", "Application Performance Monitoring Agent for Real User Monitoring", VersioningSystemId.ApmAgentRum); | ||
|
|
||
| // Generic product | ||
| public static readonly ApplicabilityDefinition Product = new("", "", VersioningSystemId.All); | ||
| } |
141 changes: 141 additions & 0 deletions
141
src/Elastic.Markdown/Myst/Components/ApplicabilityRenderer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using Elastic.Documentation; | ||
| using Elastic.Documentation.AppliesTo; | ||
| using Elastic.Documentation.Configuration.Versions; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Components; | ||
|
|
||
| public class ApplicabilityRenderer | ||
| { | ||
| public record ApplicabilityRenderData( | ||
| string BadgeLifecycleText, | ||
| string Version, | ||
| string TooltipText, | ||
| string LifecycleClass, | ||
| bool ShowLifecycleName, | ||
| bool ShowVersion | ||
| ); | ||
|
|
||
| public ApplicabilityRenderData RenderApplicability( | ||
| Applicability applicability, | ||
| ApplicabilityMappings.ApplicabilityDefinition applicabilityDefinition, | ||
| VersioningSystem versioningSystem, | ||
| AppliesCollection allApplications) | ||
| { | ||
| var lifecycleClass = applicability.GetLifeCycleName().ToLowerInvariant().Replace(" ", "-"); | ||
| var lifecycleFull = GetLifecycleFullText(applicability.Lifecycle); | ||
| var realVersion = TryGetRealVersion(applicability, out var v) ? v : null; | ||
|
|
||
| var tooltipText = BuildTooltipText(applicability, applicabilityDefinition, versioningSystem, realVersion, lifecycleFull); | ||
| var badgeLifecycleText = BuildBadgeLifecycleText(applicability, versioningSystem, realVersion, allApplications); | ||
|
|
||
| var showLifecycle = applicability.Lifecycle != ProductLifecycle.GenerallyAvailable && string.IsNullOrEmpty(badgeLifecycleText); | ||
| var showVersion = applicability.Version is not null and not AllVersions && versioningSystem.Current >= applicability.Version; | ||
| var version = applicability.Version?.ToString() ?? ""; | ||
| return new ApplicabilityRenderData( | ||
| BadgeLifecycleText: badgeLifecycleText, | ||
| Version: version, | ||
| TooltipText: tooltipText, | ||
| LifecycleClass: lifecycleClass, | ||
| ShowLifecycleName: showLifecycle, | ||
| ShowVersion: showVersion | ||
| ); | ||
| } | ||
|
|
||
| private static string GetLifecycleFullText(ProductLifecycle lifecycle) => lifecycle switch | ||
| { | ||
| ProductLifecycle.GenerallyAvailable => "Available", | ||
| ProductLifecycle.Beta => "Available in beta", | ||
| ProductLifecycle.TechnicalPreview => "Available in technical preview", | ||
| ProductLifecycle.Deprecated => "Deprecated", | ||
| ProductLifecycle.Removed => "Removed", | ||
| ProductLifecycle.Unavailable => "Not available", | ||
| _ => "" | ||
| }; | ||
|
|
||
| private static string BuildTooltipText( | ||
| Applicability applicability, | ||
| ApplicabilityMappings.ApplicabilityDefinition applicabilityDefinition, | ||
| VersioningSystem versioningSystem, | ||
| SemVersion? realVersion, | ||
| string lifecycleFull) | ||
| { | ||
| var tooltipText = ""; | ||
|
|
||
| tooltipText = realVersion is not null | ||
| ? realVersion <= versioningSystem.Current | ||
| ? $"{lifecycleFull} on {applicabilityDefinition.DisplayName} version {realVersion} and later unless otherwise specified." | ||
| : applicability.Lifecycle switch | ||
| { | ||
| ProductLifecycle.GenerallyAvailable | ||
| or ProductLifecycle.Beta | ||
| or ProductLifecycle.TechnicalPreview | ||
| or ProductLifecycle.Planned => | ||
| $"We plan to add this functionality in a future {applicabilityDefinition.DisplayName} update. Subject to change.", | ||
| ProductLifecycle.Deprecated => $"We plan to deprecate this functionality in a future {applicabilityDefinition.DisplayName} update. Subject to change.", | ||
| ProductLifecycle.Removed => $"We plan to remove this functionality in a future {applicabilityDefinition.DisplayName} update. Subject to change.", | ||
| _ => tooltipText | ||
| } | ||
| : $"{lifecycleFull} on {applicabilityDefinition.DisplayName} unless otherwise specified."; | ||
|
|
||
| var disclaimer = GetDisclaimer(applicability.Lifecycle, versioningSystem.Id); | ||
| if (disclaimer is not null) | ||
| tooltipText = $"{tooltipText}\n\n{disclaimer}"; | ||
|
|
||
| return tooltipText; | ||
| } | ||
|
|
||
| private static string? GetDisclaimer(ProductLifecycle lifecycle, VersioningSystemId versioningSystemId) => lifecycle switch | ||
| { | ||
| ProductLifecycle.Beta => "Beta features are subject to change. The design and code is less mature than official GA features and is being provided as-is with no warranties. Beta features are not subject to the support SLA of official GA features.", | ||
| ProductLifecycle.TechnicalPreview => "This functionality may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.", | ||
| ProductLifecycle.GenerallyAvailable => versioningSystemId is VersioningSystemId.Stack | ||
| ? "If this functionality is unavailable or behaves differently when deployed on ECH, ECE, ECK, or a self-managed installation, it will be indicated on the page." | ||
| : null, | ||
| _ => null | ||
| }; | ||
|
|
||
| private static string BuildBadgeLifecycleText( | ||
| Applicability applicability, | ||
| VersioningSystem versioningSystem, | ||
| SemVersion? realVersion, | ||
| AppliesCollection allApplications) | ||
| { | ||
| var badgeText = ""; | ||
| if (realVersion is not null && realVersion > versioningSystem.Current) | ||
| { | ||
| badgeText = applicability.Lifecycle switch | ||
| { | ||
| ProductLifecycle.TechnicalPreview => "Planned", | ||
| ProductLifecycle.Beta => "Planned", | ||
| ProductLifecycle.GenerallyAvailable => | ||
| allApplications.Any(a => a.Lifecycle is ProductLifecycle.TechnicalPreview or ProductLifecycle.Beta) | ||
| ? "GA planned" | ||
| : "Planned", | ||
| ProductLifecycle.Deprecated => "Deprecation planned", | ||
| ProductLifecycle.Removed => "Removal planned", | ||
| ProductLifecycle.Planned => "Planned", | ||
| ProductLifecycle.Unavailable => "Unavailable", | ||
| _ => badgeText | ||
| }; | ||
| } | ||
|
|
||
| return badgeText; | ||
| } | ||
|
|
||
| private static bool TryGetRealVersion(Applicability applicability, [NotNullWhen(true)] out SemVersion? version) | ||
| { | ||
| version = null; | ||
| if (applicability.Version is not null && applicability.Version != AllVersions.Instance) | ||
| { | ||
| version = applicability.Version; | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.