feat: Add support for flyout menu mode in MegaMenu

- Introduced `MegaMenuMode` type and `normalizeMegaMenuMode` function to handle menu modes.
- Updated `MegaMenuApplicationCustomizer` to accept `menuMode` property.
- Enhanced `MegaMenuRenderer` to render flyout menus based on the selected mode.
- Created new HTML previews for both flyout and mega menu modes.
- Removed unused mock services and user custom action service interfaces.
This commit is contained in:
Torsten Brendgen
2026-07-20 20:37:32 +02:00
parent e75b11117f
commit bc61166267
27 changed files with 1320 additions and 1833 deletions

View File

@@ -1,6 +1,5 @@
param(
[Parameter(Mandatory = $true)]
[Alias('WebUrl')]
[string]$SiteUrl,
[string]$TermSetName = '',
@@ -10,6 +9,9 @@ param(
[ValidateRange(1, 1440)]
[int]$CacheMinutes = 15,
[ValidateSet('megaMenu', 'flyout')]
[string]$MenuMode = 'megaMenu',
[switch]$EnableDebug,
[string]$Description = 'MSFT-Custom-Solution:MegaMenu'
@@ -29,107 +31,85 @@ if (-not (Get-Command -Name Get-SPSite -ErrorAction SilentlyContinue)) {
$componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506'
$legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b'
$location = 'ClientSideExtension.ApplicationCustomizer'
$configurationProperty = 'PortalSettings.MegaMenu.Configuration'
$legacyPropertyName = 'PortalSettings.MegaMenu.Configuration'
if ([string]::IsNullOrWhiteSpace($TermSetId) -and [string]::IsNullOrWhiteSpace($TermSetName)) {
throw 'Bitte TermSetId oder TermSetName angeben.'
}
$properties = [string](@{
termSetName = $TermSetName
termSetId = $TermSetId
termSetName = $TermSetName.Trim()
termSetId = $TermSetId.Trim()
cacheMinutes = $CacheMinutes
menuMode = $MenuMode
debug = [bool]$EnableDebug.IsPresent
} | ConvertTo-Json -Depth 10 -Compress)
$site = Get-SPSite -Identity $SiteUrl
try {
$rootWeb = $site.RootWeb
$rootWeb.AllProperties[$configurationProperty] = [string]$properties
$rootWeb.Update()
$siteActions = @(
$site.UserCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
)
foreach ($siteAction in $siteActions) {
$siteAction.Delete()
@($site.UserCustomActions | Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}) | ForEach-Object {
Write-Host ('Entferne alte Site-Action: ' + $_.Id)
$_.Delete()
}
$created = 0
$updated = 0
$removedLegacy = 0
try {
if ($site.RootWeb.AllProperties.ContainsKey($legacyPropertyName)) {
$site.RootWeb.AllProperties.Remove($legacyPropertyName)
$site.RootWeb.Update()
Write-Host ('Alte Property-Bag-Konfiguration entfernt: ' + $legacyPropertyName)
}
}
catch {
Write-Warning ('Die alte Property-Bag-Konfiguration konnte nicht entfernt werden: ' + $_.Exception.Message)
}
foreach ($web in $site.AllWebs) {
try {
$webUrl = $web.Url
$userCustomActions = $web.UserCustomActions
$actions = @($web.UserCustomActions | Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
})
if ($null -eq $userCustomActions) {
throw ('UserCustomActions konnten fuer das Web nicht geladen werden: ' + $webUrl)
foreach ($action in $actions) {
Write-Host ('Entferne alte Web-Action: ' + $webUrl + ' / ' + $action.Id)
$action.Delete()
}
$actions = @(
$userCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
)
$currentAction = $actions |
Where-Object {
$_.ClientSideComponentId -eq $componentId
} |
Select-Object -First 1
foreach ($existingAction in $actions) {
if ($currentAction -and $existingAction.Id -eq $currentAction.Id) {
continue
}
$existingAction.Delete()
$removedLegacy++
}
if (-not $currentAction) {
$currentAction = $userCustomActions.Add()
$currentAction.Name = [Guid]::NewGuid().ToString('B')
$created++
}
else {
$updated++
}
$currentAction.Title = 'MegaMenu Application Customizer'
$currentAction.Description = $Description
$currentAction.Location = $location
$currentAction.ClientSideComponentId = $componentId
$currentAction.ClientSideComponentProperties = $properties
$currentAction.Sequence = 100
$currentAction.Update()
$web.Update()
Write-Host ('MegaMenu synchronisiert: ' + $webUrl) -ForegroundColor Green
}
finally {
$web.Dispose()
}
}
Write-Host ''
Write-Host 'MegaMenu wurde fuer die gesamte Site Collection konfiguriert.' -ForegroundColor Green
Write-Host ('Zentrale Konfiguration: ' + $configurationProperty)
Write-Host ('Neu registrierte Webs: ' + $created)
Write-Host ('Aktualisierte Webs: ' + $updated)
Write-Host ('Entfernte alte oder doppelte Registrierungen: ' + $removedLegacy)
Write-Host ('Properties: ' + $properties)
Write-Host 'Neue Unterwebs koennen durch erneutes Ausfuehren idempotent synchronisiert werden.' -ForegroundColor Yellow
}
finally {
if ($site) {
$site.Dispose()
}
$site.Dispose()
}
$site = Get-SPSite -Identity $SiteUrl
try {
$action = $site.UserCustomActions.Add()
$action.Name = [Guid]::NewGuid().ToString('B')
$action.Title = 'MegaMenu Application Customizer'
$action.Description = $Description
$action.Location = 'ClientSideExtension.ApplicationCustomizer'
$action.ClientSideComponentId = $componentId
$action.ClientSideComponentProperties = $properties
$action.Sequence = 100
$action.Update()
Write-Host ''
Write-Host 'MegaMenu wurde zentral fuer die Site Collection registriert.' -ForegroundColor Green
Write-Host ('Site Collection: ' + $site.Url)
Write-Host ('Action-ID: ' + $action.Id)
Write-Host ('Menu mode: ' + $MenuMode)
Write-Host ('Properties: ' + $properties)
Write-Host 'Das MegaMenu-SPFx-Paket muss im App Catalog zentral bereitgestellt sein.' -ForegroundColor Yellow
}
finally {
$site.Dispose()
}

View File

@@ -1,136 +0,0 @@
param(
[Parameter(Mandatory = $true)]
[string]$SiteUrl,
[string]$Description = 'MSFT-Custom-Solution:MegaMenu'
)
if (-not (Get-Command -Name Get-SPSite -ErrorAction SilentlyContinue)) {
if (Get-Module -ListAvailable -Name Microsoft.SharePoint.PowerShell) {
Import-Module Microsoft.SharePoint.PowerShell -DisableNameChecking
}
elseif (Get-PSSnapin -Registered -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) {
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
else {
throw 'Die SharePoint PowerShell-Komponenten wurden nicht gefunden. Bitte in der SharePoint Management Shell ausfuehren.'
}
}
$componentId = [Guid]'c0abbffb-355d-4d4e-bd38-9e15fb811506'
$legacyComponentId = [Guid]'abc3361f-bb2d-491f-aba3-cd51c19a299b'
$location = 'ClientSideExtension.ApplicationCustomizer'
$configurationProperty = 'PortalSettings.MegaMenu.Configuration'
$site = Get-SPSite -Identity $SiteUrl
try {
$rootWeb = $site.RootWeb
$properties = [string]$rootWeb.AllProperties[$configurationProperty]
if ([string]::IsNullOrWhiteSpace($properties)) {
$existingAction = $null
foreach ($web in $site.AllWebs) {
try {
$existingAction = @(
$web.UserCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
) | Select-Object -First 1
if ($existingAction) {
$properties = [string]$existingAction.ClientSideComponentProperties
break
}
}
finally {
$web.Dispose()
}
}
}
if ([string]::IsNullOrWhiteSpace($properties)) {
throw ('Keine MegaMenu-Konfiguration im Property Bag oder in einer bestehenden ' +
'Web-Registrierung gefunden. Bitte zuerst add-megamenu.ps1 ausfuehren.')
}
try {
$null = $properties | ConvertFrom-Json
}
catch {
throw ('Die gefundene MegaMenu-Konfiguration ist kein gueltiges JSON: ' + $_.Exception.Message)
}
$removedSiteActions = 0
@(
$site.UserCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
) | ForEach-Object {
$_.Delete()
$removedSiteActions++
}
$siteAction = $site.UserCustomActions.Add()
$siteAction.Name = [Guid]::NewGuid().ToString('B')
$siteAction.Title = 'MegaMenu Application Customizer'
$siteAction.Description = $Description
$siteAction.Location = $location
$siteAction.ClientSideComponentId = $componentId
$siteAction.ClientSideComponentProperties = $properties
$siteAction.Sequence = 100
$siteAction.Update()
$removedWebActions = 0
$testedWebUrls = @()
foreach ($web in $site.AllWebs) {
try {
$testedWebUrls += $web.Url
@(
$web.UserCustomActions |
Where-Object {
$_.ClientSideComponentId -eq $componentId -or
$_.ClientSideComponentId -eq $legacyComponentId
}
) | ForEach-Object {
$_.Delete()
$removedWebActions++
}
}
finally {
$web.Dispose()
}
}
$verification = @(
$site.UserCustomActions |
Where-Object { $_.ClientSideComponentId -eq $componentId }
)
Write-Host ''
Write-Host '=== MegaMenu Site-Scope-Test vorbereitet ===' -ForegroundColor Green
Write-Host ('Site-Action-ID: ' + $siteAction.Id)
Write-Host ('Component-ID: ' + $componentId)
Write-Host ('Entfernte vorherige Site-Actions: ' + $removedSiteActions)
Write-Host ('Entfernte Web-Actions: ' + $removedWebActions)
Write-Host ('Verifizierte Site-Actions: ' + $verification.Count)
Write-Host ('Properties: ' + $properties)
Write-Host ''
Write-Host 'Bitte jeweils mit Strg+F5 testen:' -ForegroundColor Cyan
$testedWebUrls | ForEach-Object { Write-Host (' ' + $_) }
Write-Host ''
Write-Host 'Rueckkehr zum bisherigen Web-Scope:' -ForegroundColor Yellow
Write-Host ('.\deployment\add-megamenu.ps1 -SiteUrl ''' + $site.Url + '''')
}
finally {
if ($site) {
$site.Dispose()
}
}