优化地图编辑中的字段管理

This commit is contained in:
18086616529
2026-06-26 09:23:16 +08:00
parent e7bd326ea2
commit ce66da772e
10 changed files with 598 additions and 139 deletions
@@ -34,14 +34,17 @@ public sealed class DashboardShortcutService
if (row == null)
{
var defaults = FilterKeys(DashboardShortcutCatalog.DefaultKeysForScope(scope), scope, allowed);
var defaults = EnsureMandatoryKeys(
FilterKeys(DashboardShortcutCatalog.DefaultKeysForScope(scope), scope, allowed),
scope, allowed);
return new QuickEntriesResult(
defaults.Take(DashboardShortcutCatalog.MaxKeysPerUser).ToList(),
UsingDefaults: true);
}
var keys = ParseKeys(row.KeysJson);
var filtered = FilterKeys(keys, scope, allowed)
var filtered = EnsureMandatoryKeys(
FilterKeys(keys, scope, allowed), scope, allowed)
.Take(DashboardShortcutCatalog.MaxKeysPerUser)
.ToList();
return new QuickEntriesResult(filtered, UsingDefaults: false);
@@ -52,7 +55,8 @@ public sealed class DashboardShortcutService
{
scope = NormalizeScope(scope);
var allowed = AllowedPages(userId, scope);
var sanitized = FilterKeys(Deduplicate(keys ?? []), scope, allowed);
var sanitized = EnsureMandatoryKeys(
FilterKeys(Deduplicate(keys ?? []), scope, allowed), scope, allowed);
if (sanitized.Count > DashboardShortcutCatalog.MaxKeysPerUser)
sanitized = sanitized.Take(DashboardShortcutCatalog.MaxKeysPerUser).ToList();
@@ -114,6 +118,32 @@ public sealed class DashboardShortcutService
return outKeys;
}
private static List<string> EnsureMandatoryKeys(
List<string> keys, string scope, HashSet<string> allowedPages)
{
if (!string.Equals(scope, PageCatalog.ScopePlatform, StringComparison.OrdinalIgnoreCase))
return keys;
var result = new List<string>();
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var raw in DashboardShortcutCatalog.MandatoryPlatformKeys)
{
var key = DashboardShortcutCatalog.NormalizeKey(raw);
if (!DashboardShortcutCatalog.IsValidKey(key)) continue;
var pageKey = DashboardShortcutCatalog.PageKeyFor(key);
if (!allowedPages.Contains(pageKey)) continue;
if (seen.Add(key)) result.Add(key);
}
foreach (var key in keys)
{
if (seen.Add(key)) result.Add(key);
}
return result;
}
private static List<string> Deduplicate(IReadOnlyList<string> keys)
{
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);