-
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 5 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 | ||
| ); |
64 changes: 64 additions & 0 deletions
64
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,64 @@ | ||
| // 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); | ||
|
|
||
| private static readonly Dictionary<string, ApplicabilityDefinition> Mappings = new() | ||
| { | ||
| // Stack | ||
| ["stack"] = new ApplicabilityDefinition("Stack", "Elastic Stack", VersioningSystemId.Stack), | ||
|
|
||
| // Serverless | ||
| ["serverless"] = new ApplicabilityDefinition("Serverless", "Elastic Cloud Serverless", VersioningSystemId.Serverless), | ||
| ["serverless-elasticsearch"] = new ApplicabilityDefinition("Serverless Elasticsearch", "Serverless Elasticsearch projects", VersioningSystemId.ElasticsearchProject), | ||
| ["serverless-observability"] = new ApplicabilityDefinition("Serverless Observability", "Serverless Observability projects", VersioningSystemId.ObservabilityProject), | ||
| ["serverless-security"] = new ApplicabilityDefinition("Serverless Security", "Serverless Security projects", VersioningSystemId.SecurityProject), | ||
|
|
||
| // Deployment | ||
| ["ech"] = new ApplicabilityDefinition("ECH", "Elastic Cloud Hosted", VersioningSystemId.Ess), | ||
| ["eck"] = new ApplicabilityDefinition("ECK", "Elastic Cloud on Kubernetes", VersioningSystemId.Eck), | ||
| ["ece"] = new ApplicabilityDefinition("ECE", "Elastic Cloud Enterprise", VersioningSystemId.Ece), | ||
| ["self"] = new ApplicabilityDefinition("Self-Managed", "Self-managed Elastic deployments", VersioningSystemId.Self), | ||
|
|
||
| // Product Applicability | ||
| ["ecctl"] = new ApplicabilityDefinition("ECCTL", "Elastic Cloud Control", VersioningSystemId.Ecctl), | ||
| ["curator"] = new ApplicabilityDefinition("Curator", "Curator", VersioningSystemId.Curator), | ||
|
|
||
| // EDOT Products | ||
| ["edot-android"] = new ApplicabilityDefinition("EDOT Android", "Elastic Distribution of OpenTelemetry Android", VersioningSystemId.EdotAndroid), | ||
| ["edot-cf-aws"] = new ApplicabilityDefinition("EDOT CF AWS", "Elastic Distribution of OpenTelemetry Cloud Forwarder for AWS", VersioningSystemId.EdotCfAws), | ||
| ["edot-collector"] = new ApplicabilityDefinition("EDOT Collector", "Elastic Distribution of OpenTelemetry Collector", VersioningSystemId.EdotCollector), | ||
| ["edot-dotnet"] = new ApplicabilityDefinition("EDOT .NET", "Elastic Distribution of OpenTelemetry .NET", VersioningSystemId.EdotDotnet), | ||
| ["edot-ios"] = new ApplicabilityDefinition("EDOT iOS", "Elastic Distribution of OpenTelemetry iOS", VersioningSystemId.EdotIos), | ||
| ["edot-java"] = new ApplicabilityDefinition("EDOT Java", "Elastic Distribution of OpenTelemetry Java", VersioningSystemId.EdotJava), | ||
| ["edot-node"] = new ApplicabilityDefinition("EDOT Node.js", "Elastic Distribution of OpenTelemetry Node.js", VersioningSystemId.EdotNode), | ||
| ["edot-php"] = new ApplicabilityDefinition("EDOT PHP", "Elastic Distribution of OpenTelemetry PHP", VersioningSystemId.EdotPhp), | ||
| ["edot-python"] = new ApplicabilityDefinition("EDOT Python", "Elastic Distribution of OpenTelemetry Python", VersioningSystemId.EdotPython), | ||
|
|
||
| // APM Agents | ||
| ["apm-agent-android"] = new ApplicabilityDefinition("APM Agent Android", "Application Performance Monitoring Agent for Android", VersioningSystemId.ApmAgentAndroid), | ||
| ["apm-agent-dotnet"] = new ApplicabilityDefinition("APM Agent .NET", "Application Performance Monitoring Agent for .NET", VersioningSystemId.ApmAgentDotnet), | ||
| ["apm-agent-go"] = new ApplicabilityDefinition("APM Agent Go", "Application Performance Monitoring Agent for Go", VersioningSystemId.ApmAgentGo), | ||
| ["apm-agent-ios"] = new ApplicabilityDefinition("APM Agent iOS", "Application Performance Monitoring Agent for iOS", VersioningSystemId.ApmAgentIos), | ||
| ["apm-agent-java"] = new ApplicabilityDefinition("APM Agent Java", "Application Performance Monitoring Agent for Java", VersioningSystemId.ApmAgentJava), | ||
| ["apm-agent-node"] = new ApplicabilityDefinition("APM Agent Node.js", "Application Performance Monitoring Agent for Node.js", VersioningSystemId.ApmAgentNode), | ||
| ["apm-agent-php"] = new ApplicabilityDefinition("APM Agent PHP", "Application Performance Monitoring Agent for PHP", VersioningSystemId.ApmAgentPhp), | ||
| ["apm-agent-python"] = new ApplicabilityDefinition("APM Agent Python", "Application Performance Monitoring Agent for Python", VersioningSystemId.ApmAgentPython), | ||
| ["apm-agent-ruby"] = new ApplicabilityDefinition("APM Agent Ruby", "Application Performance Monitoring Agent for Ruby", VersioningSystemId.ApmAgentRuby), | ||
| ["apm-agent-rum"] = new ApplicabilityDefinition("APM Agent RUM", "Application Performance Monitoring Agent for Real User Monitoring", VersioningSystemId.ApmAgentRum), | ||
|
|
||
| // Generic product | ||
| ["product"] = new ApplicabilityDefinition("", "", VersioningSystemId.All) | ||
| }; | ||
|
|
||
| public static ApplicabilityDefinition GetApplicabilityDefinition(string key) => Mappings.TryGetValue(key, out var definition) | ||
| ? definition | ||
| : throw new ArgumentException($"Unknown product key: {key}"); | ||
| } | ||
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(" ", "-"); | ||
reakaleek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.