Skip to content

Commit

Permalink
Package manager UI-related tweaks (#4382)
Browse files Browse the repository at this point in the history
* Add Plugins Path setting
* Fix/improve cache invalidation
* Hide load error when collapsing package source
* Package manager style tweaks
* Show error if installed packages query failed
* Prevent "No packages found" flicker
* Show <unknown> if empty version
* Always show latest version, highlight if new version available
* Fix issues with non-unique cross-source package ids
* Don't wrap id, version and date
* Decrease collapse button padding
* Display description for scraper packages
* Fix default packages population
* Change default package path to community
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
  • Loading branch information
DingDongSoLong4 authored Dec 22, 2023
1 parent 23b4d4f commit a1bd7cf
Show file tree
Hide file tree
Showing 16 changed files with 610 additions and 499 deletions.
1 change: 1 addition & 0 deletions graphql/documents/data/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ fragment ConfigGeneralData on ConfigGeneralResult {
generatedPath
metadataPath
scrapersPath
pluginsPath
cachePath
blobsPath
blobsStorage
Expand Down
2 changes: 1 addition & 1 deletion graphql/documents/queries/plugins.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ query InstalledPluginPackages {
query InstalledPluginPackagesStatus {
installedPackages(type: Plugin) {
...PackageData
upgrade {
source_package {
...PackageData
}
}
Expand Down
2 changes: 1 addition & 1 deletion graphql/documents/queries/scrapers/scrapers.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ query InstalledScraperPackages {
query InstalledScraperPackagesStatus {
installedPackages(type: Scraper) {
...PackageData
upgrade {
source_package {
...PackageData
}
}
Expand Down
4 changes: 4 additions & 0 deletions graphql/schema/types/config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ input ConfigGeneralInput {
metadataPath: String
"Path to scrapers"
scrapersPath: String
"Path to plugins"
pluginsPath: String
"Path to cache"
cachePath: String
"Path to blobs - required for filesystem blob storage"
Expand Down Expand Up @@ -189,6 +191,8 @@ type ConfigGeneralResult {
configFilePath: String!
"Path to scrapers"
scrapersPath: String!
"Path to plugins"
pluginsPath: String!
"Path to cache"
cachePath: String!
"Path to blobs - required for filesystem blob storage"
Expand Down
4 changes: 2 additions & 2 deletions graphql/schema/types/package.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type Package {

sourceURL: String!

"The available upgraded version of this package"
upgrade: Package
"The version of this package currently available from the remote source"
source_package: Package

metadata: Map!
}
Expand Down
20 changes: 18 additions & 2 deletions internal/api/resolver_mutation_configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,31 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input ConfigGen
}

refreshScraperCache := false
refreshScraperSource := false
existingScrapersPath := c.GetScrapersPath()
if input.ScrapersPath != nil && existingScrapersPath != *input.ScrapersPath {
if err := validateDir(config.ScrapersPath, *input.ScrapersPath, false); err != nil {
return makeConfigGeneralResult(), err
}

refreshScraperCache = true
refreshScraperSource = true
c.Set(config.ScrapersPath, input.ScrapersPath)
}

refreshPluginCache := false
refreshPluginSource := false
existingPluginsPath := c.GetPluginsPath()
if input.PluginsPath != nil && existingPluginsPath != *input.PluginsPath {
if err := validateDir(config.PluginsPath, *input.PluginsPath, false); err != nil {
return makeConfigGeneralResult(), err
}

refreshPluginCache = true
refreshPluginSource = true
c.Set(config.PluginsPath, input.PluginsPath)
}

existingMetadataPath := c.GetMetadataPath()
if input.MetadataPath != nil && existingMetadataPath != *input.MetadataPath {
if err := validateDir(config.Metadata, *input.MetadataPath, true); err != nil {
Expand Down Expand Up @@ -347,13 +362,11 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input ConfigGen
c.Set(config.DrawFunscriptHeatmapRange, input.DrawFunscriptHeatmapRange)
}

refreshScraperSource := false
if input.ScraperPackageSources != nil {
c.Set(config.ScraperPackageSources, input.ScraperPackageSources)
refreshScraperSource = true
}

refreshPluginSource := false
if input.PluginPackageSources != nil {
c.Set(config.PluginPackageSources, input.PluginPackageSources)
refreshPluginSource = true
Expand All @@ -367,6 +380,9 @@ func (r *mutationResolver) ConfigureGeneral(ctx context.Context, input ConfigGen
if refreshScraperCache {
manager.GetInstance().RefreshScraperCache()
}
if refreshPluginCache {
manager.GetInstance().RefreshPluginCache()
}
if refreshStreamManager {
manager.GetInstance().RefreshStreamManager()
}
Expand Down
1 change: 1 addition & 0 deletions internal/api/resolver_query_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func makeConfigGeneralResult() *ConfigGeneralResult {
MetadataPath: config.GetMetadataPath(),
ConfigFilePath: config.GetConfigFile(),
ScrapersPath: config.GetScrapersPath(),
PluginsPath: config.GetPluginsPath(),
CachePath: config.GetCachePath(),
BlobsPath: config.GetBlobsPath(),
BlobsStorage: config.GetBlobsStorage(),
Expand Down
35 changes: 24 additions & 11 deletions internal/api/resolver_query_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,24 @@ func sortedPackageSpecKeys[V any](m map[models.PackageSpecInput]V) []models.Pack
}

sort.Slice(keys, func(i, j int) bool {
if strings.EqualFold(keys[i].ID, keys[j].ID) {
return keys[i].ID < keys[j].ID
a := keys[i]
b := keys[j]

aID := a.ID
bID := b.ID

if aID == bID {
return a.SourceURL < b.SourceURL
}

return strings.ToLower(keys[i].ID) < strings.ToLower(keys[j].ID)
aIDL := strings.ToLower(aID)
bIDL := strings.ToLower(bID)

if aIDL == bIDL {
return aID < bID
}

return aIDL < bIDL
})

return keys
Expand All @@ -129,9 +142,9 @@ func (r *queryResolver) getInstalledPackagesWithUpgrades(ctx context.Context, pm
for _, k := range sortedPackageSpecKeys(packageStatusIndex) {
v := packageStatusIndex[k]
p := manifestToPackage(*v.Local)
if v.Upgradable() {
if v.Remote != nil {
pp := remotePackageToPackage(*v.Remote, allRemoteList)
p.Upgrade = pp
p.SourcePackage = pp
}
ret[i] = p
i++
Expand All @@ -146,19 +159,19 @@ func (r *queryResolver) InstalledPackages(ctx context.Context, typeArg PackageTy
return nil, err
}

installed, err := pm.ListInstalled(ctx)
if err != nil {
return nil, err
}

var ret []*Package

if sliceutil.Contains(graphql.CollectAllFields(ctx), "upgrade") {
if sliceutil.Contains(graphql.CollectAllFields(ctx), "source_package") {
ret, err = r.getInstalledPackagesWithUpgrades(ctx, pm)
if err != nil {
return nil, err
}
} else {
installed, err := pm.ListInstalled(ctx)
if err != nil {
return nil, err
}

ret = make([]*Package, len(installed))
i := 0
for _, k := range sortedPackageSpecKeys(installed) {
Expand Down
22 changes: 11 additions & 11 deletions internal/manager/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const (
PluginsSettingPrefix = PluginsSetting + "."
DisabledPlugins = "plugins.disabled"

sourceDefaultPath = "stable"
sourceDefaultPath = "community"
sourceDefaultName = "Community (stable)"

PluginPackageSources = "plugins.package_sources"
Expand Down Expand Up @@ -1666,16 +1666,16 @@ func (i *Config) setDefaultValues() {
i.main.SetDefault(NoProxy, noProxyDefault)

// set default package sources
i.main.SetDefault(PluginPackageSources, map[string]string{
"name": sourceDefaultName,
"url": pluginPackageSourcesDefault,
"local_path": sourceDefaultPath,
})
i.main.SetDefault(ScraperPackageSources, map[string]string{
"name": sourceDefaultName,
"url": scraperPackageSourcesDefault,
"local_path": sourceDefaultPath,
})
i.main.SetDefault(PluginPackageSources, []map[string]string{{
"name": sourceDefaultName,
"url": pluginPackageSourcesDefault,
"localpath": sourceDefaultPath,
}})
i.main.SetDefault(ScraperPackageSources, []map[string]string{{
"name": sourceDefaultName,
"url": scraperPackageSourcesDefault,
"localpath": sourceDefaultPath,
}})
}

// setExistingSystemDefaults sets config options that are new and unset in an existing install,
Expand Down
Loading

0 comments on commit a1bd7cf

Please sign in to comment.