Skip to content
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

Widgets for itless environment #716

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rest/models/DashboardTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ type ModuleFederationMetadata struct {
Scope string `json:"scope"`
Module string `json:"module"`
ImportName string `json:"importName,omitempty"`
FeatureFlag string `json:"featureFlag,omitempty"`
Defaults BaseWidgetDimensions `json:"defaults"`
Config WidgetConfiguration `json:"config"`
}
Expand Down
27 changes: 25 additions & 2 deletions rest/routes/dashboardTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/RedHatInsights/chrome-service-backend/rest/models"
"github.com/RedHatInsights/chrome-service-backend/rest/service"
"github.com/RedHatInsights/chrome-service-backend/rest/util"
"github.com/RedHatInsights/chrome-service-backend/rest/featureflags"
"github.com/go-chi/chi/v5"
"github.com/sirupsen/logrus"
"gorm.io/gorm"
Expand Down Expand Up @@ -271,10 +272,32 @@ func DecodeDashboardTemplate(w http.ResponseWriter, r *http.Request) {
handleDashboardResponse[models.DashboardTemplate](resp, err, w)
}

func FilterWidgetMapping(widgetMapping models.WidgetModuleFederationMapping) models.WidgetModuleFederationMapping {
filteredWidgets := make(map[models.AvailableWidgets]models.ModuleFederationMetadata)

for key, value := range widgetMapping {
if !featureflags.IsEnabled(value.FeatureFlag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Care to add a comment here, please? Because this is inverted it might be a headscratcher for us when we look at the code in a couple fo weeks. I had to read it twice already 😆

filteredWidgets[key] = value
}
}

return filteredWidgets
}

func GetWidgetMappings(w http.ResponseWriter, r *http.Request) {
var err error
resp := util.EntityResponse[models.WidgetModuleFederationMapping]{
Data: service.WidgetMapping,
var resp util.EntityResponse[models.WidgetModuleFederationMapping]

if featureflags.IsEnabled("chrome-service.filterWidgets.enable") {
filteredWidgetMapping := FilterWidgetMapping(service.WidgetMapping)

resp = util.EntityResponse[models.WidgetModuleFederationMapping]{
Data: filteredWidgetMapping,
}
} else {
resp = util.EntityResponse[models.WidgetModuleFederationMapping]{
Data: service.WidgetMapping,
}
}

handleDashboardResponse[models.WidgetModuleFederationMapping](resp, err, w)
Expand Down
16 changes: 15 additions & 1 deletion rest/service/dashboardTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var (
Scope: "landing",
Module: "./ExploreCapabilities",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 3, 5, 10, 1),

FeatureFlag: "widget.exploreCapabilities.hidden",
Config: models.WidgetConfiguration{
Icon: models.RocketIcon,
Title: "Explore capabilities",
Expand All @@ -37,6 +37,7 @@ var (
Scope: "landing",
Module: "./EdgeWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.edge.hidden",
Config: models.WidgetConfiguration{
Icon: models.EdgeIcon,
Title: "Edge Management",
Expand All @@ -46,6 +47,7 @@ var (
Scope: "landing",
Module: "./AnsibleWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.ansible.hidden",
Config: models.WidgetConfiguration{
Icon: models.AnsibleIcon,
Title: "Ansible Automation Platform",
Expand All @@ -55,6 +57,7 @@ var (
Scope: "landing",
Module: "./RhelWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.rhel.hidden",
Config: models.WidgetConfiguration{
Icon: models.RhelIcon,
Title: "Red Hat Enterprise Linux",
Expand All @@ -64,6 +67,7 @@ var (
Scope: "landing",
Module: "./OpenShiftWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.openshift.hidden",
Config: models.WidgetConfiguration{
Icon: models.OpenShiftIcon,
Title: "Red Hat OpenShift",
Expand All @@ -73,6 +77,7 @@ var (
Scope: "landing",
Module: "./QuayWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.quay.hidden",
Config: models.WidgetConfiguration{
Icon: models.QuayIcon,
Title: "Quay.io",
Expand All @@ -82,6 +87,7 @@ var (
Scope: "landing",
Module: "./AcsWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.acs.hidden",
Config: models.WidgetConfiguration{
Icon: models.ACSIcon,
Title: "Advanced Cluster Security",
Expand All @@ -91,6 +97,7 @@ var (
Scope: "landing",
Module: "./OpenShiftAiWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 4, 10, 1),
FeatureFlag: "widget.openshiftAI.hidden",
Config: models.WidgetConfiguration{
Icon: models.OpenShiftAiIcon,
Title: "Red Hat OpenShift AI",
Expand All @@ -100,6 +107,7 @@ var (
Scope: "landing",
Module: "./RecentlyVisited",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 7, 10, 1),
FeatureFlag: "widget.recentlyVisited.hidden",
Config: models.WidgetConfiguration{
Icon: models.HistoryIcon,
Title: "Recently visited",
Expand All @@ -109,6 +117,7 @@ var (
Scope: "chrome",
Module: "./DashboardFavorites",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 6, 10, 1),
FeatureFlag: "widget.favoriteServices.hidden",
Config: models.WidgetConfiguration{
HeaderLink: models.WidgetHeaderLink{
Title: "View all services",
Expand All @@ -122,6 +131,7 @@ var (
Scope: "notifications",
Module: "./DashboardWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 1, 3, 10, 1),
FeatureFlag: "widget.notificationsEvents.hidden",
Config: models.WidgetConfiguration{
HeaderLink: models.WidgetHeaderLink{
Title: "View event log",
Expand All @@ -140,6 +150,7 @@ var (
Scope: "learningResources",
Module: "./BookmarkedLearningResourcesWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 2, 4, 10, 1),
FeatureFlag: "widget.learningResources.hidden",
Config: models.WidgetConfiguration{
Icon: models.OutlinedBookmarkIcon,
Title: "Bookmarked learning resources",
Expand All @@ -149,6 +160,7 @@ var (
Scope: "landing",
Module: "./SupportCaseWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 2, 4, 10, 1),
FeatureFlag: "widget.supportCases.hidden",
Config: models.WidgetConfiguration{
HeaderLink: models.WidgetHeaderLink{
Title: "Open a support case",
Expand All @@ -162,6 +174,7 @@ var (
Scope: "subscriptionInventory",
Module: "./SubscriptionsWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 4, 4, 10, 1),
FeatureFlag: "widget.subscriptions.hidden",
Config: models.WidgetConfiguration{
HeaderLink: models.WidgetHeaderLink{
Title: "Manage subscriptions",
Expand Down Expand Up @@ -190,6 +203,7 @@ var (
Scope: "sources",
Module: "./IntegrationsWidget",
Defaults: models.BaseWidgetDimensions.InitDimensions(models.BaseWidgetDimensions{}, 2, 4, 10, 1),
FeatureFlag: "widget.integrations.hidden",
Config: models.WidgetConfiguration{
HeaderLink: models.WidgetHeaderLink{
Title: "Explore integrations",
Expand Down
Loading