Skip to content

Commit

Permalink
feat: SP-1716 Add select licenses dropdown (#63)
Browse files Browse the repository at this point in the history
* feat: Add code editor manager, scroll to first matched line on mount, sync cursors

* feat: Add LicenseService, add license selector in replace component modal

* fet: Consider license and replaceWith for bom entry duplicated values

* feat: SP-1716 Add dropdown item for selecting a different license while including/dismissing

* feat: SP-1708 Fix scanoss settings default folder location

* feat: SP-1708 Handle command line arguments with tilde

* feat: SP-1708 Prevent syncing scroll to interfere with reveal line

* feat: SP-1716 Centralize all dialogs in just one provider

* feat: SP-1708 Add more timeout for editor cursor sync

* feat: SP-1708 Fix editor autoscroll

* feat: SP-1708 Add button to toggle scroll sync

* feat: SP-1708 Small design adjustments in editor toolbar

* feat: SP-1708 Variable name changes

* feat: SP-1716 - Make scroll sync enabled by default

* feat: SP-1716 Calculate relative percentages on scroll position

* feat: SP-1716 Fix relative scroll sync, add keyboard shortuct and menu option

* feat: SP-1716 Get component name from purl, sort licenses and declared components lists

* feat: SP-1716 Reset license when selecting a new component

* feat: SP-1716 Add optional labels, add clear selected license button

* feat: Add LicenseService, add license selector in replace component modal

* fet: Consider license and replaceWith for bom entry duplicated values

* feat: SP-1716 Add dropdown item for selecting a different license while including/dismissing

* feat: SP-1716 Centralize all dialogs in just one provider

* feat: Add code editor manager, scroll to first matched line on mount, sync cursors

* feat: SP-1708 Fix scanoss settings default folder location

* feat: SP-1708 Handle command line arguments with tilde

* feat: SP-1708 Prevent syncing scroll to interfere with reveal line

* feat: SP-1708 Add more timeout for editor cursor sync

* feat: SP-1708 Fix editor autoscroll

* feat: SP-1708 Add button to toggle scroll sync

* feat: SP-1708 Small design adjustments in editor toolbar

* feat: SP-1708 Variable name changes

* feat: SP-1716 - Make scroll sync enabled by default

* feat: SP-1716 Calculate relative percentages on scroll position

* feat: SP-1716 Fix relative scroll sync, add keyboard shortuct and menu option

* feat: SP-1716 Get component name from purl, sort licenses and declared components lists

* feat: SP-1716 Reset license when selecting a new component

* feat: SP-1716 Add optional labels, add clear selected license button

* feat: SP-1716 Get modifier key from current environment

* feat: SP-1716 Simplify and refactor code, handle unfocus search bar

* feat: SP-1716 When changing the search query, reset selected results

* feat: SP-1716 Move filters to results store

* feat: SP-1716 Add tooltip for sync scroll position button

---------

Co-authored-by: eeisegn <[email protected]>
  • Loading branch information
matiasdaloia and eeisegn authored Nov 8, 2024
1 parent 24a2a6f commit 0b3940a
Show file tree
Hide file tree
Showing 62 changed files with 7,540 additions and 885 deletions.
4 changes: 4 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (a *App) initializeMenu() {
ActionsMenu.AddText(shortcut.Name, shortcut.Accelerator, func(cd *menu.CallbackData) {})
}

// View menu
ViewMenu := AppMenu.AddSubmenu("View")
ViewMenu.AddText("Sync Scroll Position", keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey), func(cd *menu.CallbackData) {})

// Help menu
HelpMenu := AppMenu.AddSubmenu("Help")
HelpMenu.AddText("Report Issue", nil, func(cd *menu.CallbackData) {
Expand Down
5 changes: 3 additions & 2 deletions backend/main/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/scanoss/scanoss.lui/backend/main/config"
"github.com/scanoss/scanoss.lui/backend/main/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -120,7 +121,7 @@ func initConfigModule() {

func setInputFile() {
if inputFile != "" {
config.Get().ResultFilePath = inputFile
config.Get().ResultFilePath = utils.ExpandPath(inputFile)
} else {
resultFilePath := config.Get().ResultFilePath
if resultFilePath != "" && strings.HasPrefix(resultFilePath, ROOT_FOLDER) {
Expand All @@ -141,7 +142,7 @@ func setScanRoot() {
pathForwardSlash := re.ReplaceAllString(scanRoot, "/")
config.Get().ScanRoot = pathForwardSlash
} else {
config.Get().ScanRoot = scanRoot
config.Get().ScanRoot = utils.ExpandPath(scanRoot)
}
}
if config.Get().ScanRoot == ROOT_FOLDER || config.Get().ScanRoot == "" {
Expand Down
4 changes: 2 additions & 2 deletions backend/main/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
const (
DEFAULT_API_URL = "https://api.osskb.org"
GLOBAL_CONFIG_FILE_NAME = "scanoss-lui-settings.json"
GLOBAL_CONFIG_FOLDER = "scanoss"
GLOBAL_CONFIG_FOLDER = ".scanoss"
ROOT_FOLDER = "."
SCNOSS_PREMIUM_API_URL = "https://api.scanoss.com"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ func Get() *Config {
}

func NewConfigModule(configPath string) *ConfigModule {
GetInstance().configPath = configPath
GetInstance().configPath = utils.ExpandPath(configPath)
return GetInstance()
}

Expand Down
56 changes: 28 additions & 28 deletions backend/main/entities/component.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package entities

type License interface {
type ComponentLicense interface {
}

type LicenseDTO struct {
Expand Down Expand Up @@ -28,26 +28,26 @@ func NewLicenseDTO(name string, patentHints string, copyleft string, checklistUR
}

type ComponentDTO struct {
ID string `json:"id"`
Lines string `json:"lines,omitempty"`
OssLines string `json:"oss_lines,omitempty"`
Matched string `json:"matched,omitempty"`
FileHash string `json:"file_hash,omitempty"`
SourceHash string `json:"source_hash,omitempty"`
FileURL string `json:"file_url,omitempty"`
Purl []string `json:"purl"`
Vendor string `json:"vendor,omitempty"`
Component string `json:"component,omitempty"`
Version string `json:"version,omitempty"`
Latest string `json:"latest,omitempty"`
URL string `json:"url,omitempty"`
Status string `json:"status,omitempty"`
ReleaseDate string `json:"release_date,omitempty"`
File string `json:"file,omitempty"`
URLHash string `json:"url_hash,omitempty"`
URLStats struct{} `json:"url_stats,omitempty"`
Provenance string `json:"provenance,omitempty"`
Licenses []License `json:"licenses,omitempty"`
ID string `json:"id"`
Lines string `json:"lines,omitempty"`
OssLines string `json:"oss_lines,omitempty"`
Matched string `json:"matched,omitempty"`
FileHash string `json:"file_hash,omitempty"`
SourceHash string `json:"source_hash,omitempty"`
FileURL string `json:"file_url,omitempty"`
Purl []string `json:"purl"`
Vendor string `json:"vendor,omitempty"`
Component string `json:"component,omitempty"`
Version string `json:"version,omitempty"`
Latest string `json:"latest,omitempty"`
URL string `json:"url,omitempty"`
Status string `json:"status,omitempty"`
ReleaseDate string `json:"release_date,omitempty"`
File string `json:"file,omitempty"`
URLHash string `json:"url_hash,omitempty"`
URLStats struct{} `json:"url_stats,omitempty"`
Provenance string `json:"provenance,omitempty"`
Licenses []ComponentLicense `json:"licenses,omitempty"`
Server struct {
Version string `json:"version,omitempty"`
KbVersion struct {
Expand All @@ -69,13 +69,13 @@ const (
)

type ComponentFilterDTO struct {
Path string `json:"path,omitempty"`
Purl string `json:"purl" validate:"required"`
Usage string `json:"usage,omitempty"`
Action FilterAction `json:"action" validate:"required,eq=include|eq=remove|eq=replace"`
Comment string `json:"comment,omitempty"`
ReplaceWithPurl string `json:"replace_with_purl,omitempty" validate:"omitempty,valid-purl"`
ReplaceWithName string `json:"replace_with_name,omitempty"`
Path string `json:"path,omitempty"`
Purl string `json:"purl" validate:"required"`
Usage string `json:"usage,omitempty"`
Action FilterAction `json:"action" validate:"required,eq=include|eq=remove|eq=replace"`
Comment string `json:"comment,omitempty"`
ReplaceWith string `json:"replace_with,omitempty" validate:"omitempty,valid-purl"`
License string `json:"license,omitempty"`
}

type Component struct {
Expand Down
14 changes: 14 additions & 0 deletions backend/main/entities/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
ActionReplaceFileWithComments Action = "replaceFileWithComments"
ActionReplaceComponentWithoutComments Action = "replaceComponentWithoutComments"
ActionReplaceComponentWithComments Action = "replaceComponentWithComments"

// View
ActionSyncScrollPosition Action = "toggleSyncScrollPosition"
)

type Shortcut struct {
Expand All @@ -44,6 +47,7 @@ const (
GroupGlobal Group = "Global"
GroupNavigation Group = "Navigation"
GroupActions Group = "Actions"
GroupView Group = "View"
)

// This is necessary to bind the enum in main.go
Expand Down Expand Up @@ -71,6 +75,7 @@ var AllShortcutActions = []struct {
{ActionReplaceFileWithComments, "ReplaceFileWithComments"},
{ActionReplaceComponentWithoutComments, "ReplaceComponentWithoutComments"},
{ActionReplaceComponentWithComments, "ReplaceComponentWithComments"},
{ActionSyncScrollPosition, "ToggleSyncScrollPosition"},
}

var DefaultShortcuts = []Shortcut{
Expand Down Expand Up @@ -253,4 +258,13 @@ var DefaultShortcuts = []Shortcut{
Group: GroupActions,
Action: ActionReplaceComponentWithComments,
},

{
Name: "Sync Scroll Position",
Description: "Sync the scroll position of the editors",
Accelerator: keys.Combo("e", keys.ShiftKey, keys.CmdOrCtrlKey),
Keys: "shift+mod+e",
Group: GroupActions,
Action: ActionReplaceComponentWithComments,
},
}
13 changes: 13 additions & 0 deletions backend/main/entities/license.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package entities

type LicenseFile struct {
LicenseListVersion string `json:"licenseListVersion"`
Licenses []License `json:"licenses"`
ReleaseDate string `json:"releaseDate"`
}

type License struct {
Name string `json:"name"`
LicenseId string `json:"licenseId"`
Reference string `json:"reference"`
}
12 changes: 6 additions & 6 deletions backend/main/entities/scanoss_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ type Bom struct {
}

type ComponentFilter struct {
Path string `json:"path,omitempty"`
Purl string `json:"purl"`
Usage ComponentFilterUsage `json:"usage,omitempty"`
Comment string `json:"comment,omitempty"`
ReplaceWith string `json:"replace_with,omitempty"`
ComponentName string `json:"component_name,omitempty"`
Path string `json:"path,omitempty"`
Purl string `json:"purl"`
Usage ComponentFilterUsage `json:"usage,omitempty"`
Comment string `json:"comment,omitempty"`
ReplaceWith string `json:"replace_with,omitempty"`
License string `json:"license,omitempty"`
}

type InitialFilters struct {
Expand Down
2 changes: 1 addition & 1 deletion backend/main/mappers/component_mapper_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (m *ComponentMapperImpl) MapToComponentDTO(componentEntity entities.Compone
Latest: componentEntity.Latest,
}

var licenses []entities.License
var licenses []entities.ComponentLicense
if len(componentEntity.Licenses) > 0 {
for _, l := range componentEntity.Licenses {
// patentHints ,copyleft0 checklistURL string, osadlUpdated string, source string, url string, incompatibleWith string
Expand Down
17 changes: 16 additions & 1 deletion backend/main/mappers/result_mapper_impl.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package mappers

import (
"strings"

"github.com/labstack/gommon/log"
purlutils "github.com/scanoss/go-purl-helper/pkg"
"github.com/scanoss/scanoss.lui/backend/main/entities"
Expand Down Expand Up @@ -77,5 +79,18 @@ func (m *ResultMapperImpl) mapConcludedPurlUrl(result entities.Result) string {
return purlUrl
}
func (m ResultMapperImpl) mapConcludedName(result entities.Result) string {
return m.scanossSettings.SettingsFile.GetBomEntryFromResult(result).ComponentName
replacedPurl := m.scanossSettings.SettingsFile.GetBomEntryFromResult(result).ReplaceWith
if replacedPurl == "" {
return ""
}

purlName, err := purlutils.PurlNameFromString(replacedPurl)
if err != nil {
log.Errorf("Error getting component name from purl: %v", err)
return ""
}

componentName := strings.Split(purlName, "/")[1]

return componentName
}
Loading

0 comments on commit 0b3940a

Please sign in to comment.