Resolve BE reviews

This commit is contained in:
kinyaelgrande
2024-01-30 17:46:03 +03:00
committed by Mumbi Francis
parent 0095663f60
commit dcc0876254
11 changed files with 681 additions and 640 deletions
+17 -21
View File
@@ -3,13 +3,15 @@ package provision
import (
"context"
"encoding/json"
"github.com/cortezaproject/corteza/server/pkg/sass"
"github.com/cortezaproject/corteza/server/store"
"github.com/cortezaproject/corteza/server/system/types"
"go.uber.org/zap"
"strconv"
"unicode"
)
// updateWebappTheme is a function that provisions webapp themes.
// It migrates the old custom css and branding sass settings to the new webapp themes setting.
func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (err error) {
vv, _, err := store.SearchSettingValues(ctx, s, types.SettingsFilter{})
if err != nil {
@@ -27,31 +29,25 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
var themes []types.Theme
for _, themeID := range themeIDs {
title := []rune(themeID)
title[0] = unicode.ToUpper(title[0])
if len(themeIDs) > 2 {
if themeID == "general" {
themes = append(themes, types.Theme{
ID: themeID,
Title: string(title),
Values: oldValueStr,
})
continue
}
if len(themeIDs) == 2 {
themes = append(themes, types.Theme{
ID: themeID,
Title: string(title),
Values: "",
Values: oldValueStr,
})
continue
}
if themeID == sass.GeneralTheme {
themes = append(themes, types.Theme{
ID: themeID,
Values: oldValueStr,
})
continue
}
themes = append(themes, types.Theme{
ID: themeID,
Title: string(title),
Values: oldValueStr,
Values: "",
})
}
@@ -71,7 +67,7 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
return err
}
// delete old custom css from the database
// delete old custom css and branding sass settings from the database
err = store.DeleteSettingValue(ctx, s, oldValue)
if err != nil {
return err
@@ -82,7 +78,7 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
// provision custom CSS
if !oldCustomCSS.IsNull() {
err = provisionTheme("ui.studio.custom-css", oldCustomCSS, "general", "light", "dark")
err = provisionTheme("ui.studio.custom-css", oldCustomCSS, sass.GeneralTheme, sass.LightTheme, sass.DarkTheme)
if err != nil {
return err
}
@@ -90,7 +86,7 @@ func updateWebappTheme(ctx context.Context, log *zap.Logger, s store.Storer) (er
// provision branding sass
if !oldBranding.IsNull() {
err = provisionTheme("ui.studio.themes", oldBranding, "light", "dark")
err = provisionTheme("ui.studio.themes", oldBranding, sass.LightTheme, sass.DarkTheme)
}
return nil
+16 -5
View File
@@ -15,6 +15,15 @@ import (
"go.uber.org/zap"
)
const (
GeneralTheme = "general"
LightTheme = "light"
DarkTheme = "dark"
SectionRoot = "root"
SectionMain = "main"
SectionTheme = "theme"
)
var (
StylesheetCache = newStylesheetCache()
sassVariablesPattern = regexp.MustCompile(`(\$[a-zA-Z_-]+):\s*([^;]+);`)
@@ -49,19 +58,21 @@ func DefaultCSS(log *zap.Logger, customCSS string) string {
func Transpile(transpiler *godartsass.Transpiler, log *zap.Logger, themeID, themeSASS, customCSS, sassDirPath string) (err error) {
// process root section
err = processSass(transpiler, log, "root", themeID, themeSASS, customCSS, sassDirPath)
err = processSass(transpiler, log, SectionRoot, themeID, themeSASS, customCSS, sassDirPath)
if err != nil {
return err
}
// process main section
err = processSass(transpiler, log, "main", themeID, themeSASS, customCSS, sassDirPath)
if err != nil {
return err
if themeID == LightTheme {
err = processSass(transpiler, log, SectionMain, themeID, themeSASS, customCSS, sassDirPath)
if err != nil {
return err
}
}
//process theme section
err = processSass(transpiler, log, "theme", themeID, themeSASS, customCSS, sassDirPath)
err = processSass(transpiler, log, SectionTheme, themeID, themeSASS, customCSS, sassDirPath)
if err != nil {
return err
}