fix marketplace search and better category disabling (#1991)

* fix marketplace search and better category disabling

* bump marketplace version

* fix issue with marketplace settings and absent community reg
This commit is contained in:
Matt Hill
2022-11-29 07:42:50 -07:00
committed by Aiden McClelland
parent f9a4699e84
commit ccb85737f7
6 changed files with 73 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@start9labs/marketplace", "name": "@start9labs/marketplace",
"version": "0.3.6", "version": "0.3.7",
"peerDependencies": { "peerDependencies": {
"@angular/common": ">=13.2.0", "@angular/common": ">=13.2.0",
"@angular/core": ">=13.2.0", "@angular/core": ">=13.2.0",

View File

@@ -2,7 +2,7 @@
*ngFor="let cat of categories" *ngFor="let cat of categories"
fill="clear" fill="clear"
class="category" class="category"
[class.category_selected]="cat === category && !disableCategories" [class.category_selected]="cat === category"
(click)="switchCategory(cat)" (click)="switchCategory(cat)"
> >
{{ cat }} {{ cat }}

View File

@@ -22,9 +22,6 @@ export class CategoriesComponent {
@Input() @Input()
category = '' category = ''
@Input()
disableCategories = false
@Output() @Output()
readonly categoryChange = new EventEmitter<string>() readonly categoryChange = new EventEmitter<string>()

View File

@@ -1,5 +1,4 @@
import { NgModule, Pipe, PipeTransform } from '@angular/core' import { NgModule, Pipe, PipeTransform } from '@angular/core'
import { Emver } from '@start9labs/shared'
import { MarketplacePkg } from '../types' import { MarketplacePkg } from '../types'
import Fuse from 'fuse.js' import Fuse from 'fuse.js'
@@ -7,8 +6,6 @@ import Fuse from 'fuse.js'
name: 'filterPackages', name: 'filterPackages',
}) })
export class FilterPackagesPipe implements PipeTransform { export class FilterPackagesPipe implements PipeTransform {
constructor(private readonly emver: Emver) {}
transform( transform(
packages: MarketplacePkg[], packages: MarketplacePkg[],
query: string, query: string,
@@ -19,6 +16,28 @@ export class FilterPackagesPipe implements PipeTransform {
let options: Fuse.IFuseOptions<MarketplacePkg> = { let options: Fuse.IFuseOptions<MarketplacePkg> = {
includeScore: true, includeScore: true,
includeMatches: true, includeMatches: true,
}
if (query.length < 4) {
options = {
...options,
threshold: 0.2,
location: 0,
distance: 16,
keys: [
{
name: 'manifest.title',
weight: 1,
},
{
name: 'manifest.id',
weight: 0.5,
},
],
}
} else {
options = {
...options,
ignoreLocation: true, ignoreLocation: true,
useExtendedSearch: true, useExtendedSearch: true,
keys: [ keys: [
@@ -40,8 +59,8 @@ export class FilterPackagesPipe implements PipeTransform {
}, },
], ],
} }
query = `'${query}` query = `'${query}`
}
const fuse = new Fuse(packages, options) const fuse = new Fuse(packages, options)
return fuse.search(query).map(p => p.item) return fuse.search(query).map(p => p.item)

View File

@@ -29,14 +29,14 @@ export class MarketplaceSettingsPage {
this.marketplaceService.getSelectedHost$(), this.marketplaceService.getSelectedHost$(),
]).pipe( ]).pipe(
map(([stores, selected]) => { map(([stores, selected]) => {
const hmmm = stores.map(s => ({ const toSlice = stores.map(s => ({
...s, ...s,
selected: s.url === selected.url, selected: s.url === selected.url,
})) }))
// 0 and 1 are prod and community // 0 and 1 are prod and community
const standard = hmmm.slice(0, 2) const standard = toSlice.slice(0, 1)
// 2 and beyond are alts // 2 and beyond are alts
const alt = hmmm.slice(2) const alt = toSlice.slice(1)
return { standard, alt } return { standard, alt }
}), }),

View File

@@ -38,8 +38,7 @@
<ng-container *ngIf="store$ | async as store; else loading"> <ng-container *ngIf="store$ | async as store; else loading">
<marketplace-categories <marketplace-categories
[categories]="store.categories" [categories]="store.categories"
[category]="category" [category]="query ? '' : category"
[disableCategories]="!!query"
(categoryChange)="onCategoryChange($event)" (categoryChange)="onCategoryChange($event)"
></marketplace-categories> ></marketplace-categories>
@@ -48,6 +47,7 @@
<ion-grid <ion-grid
*ngIf="store.packages | filterPackages: query:category as filtered" *ngIf="store.packages | filterPackages: query:category as filtered"
> >
<ng-container *ngIf="filtered.length; else empty">
<ion-row *ngIf="localPkgs$ | async as localPkgs"> <ion-row *ngIf="localPkgs$ | async as localPkgs">
<ion-col <ion-col
*ngFor="let pkg of filtered" *ngFor="let pkg of filtered"
@@ -64,6 +64,13 @@
</marketplace-item> </marketplace-item>
</ion-col> </ion-col>
</ion-row> </ion-row>
</ng-container>
<ng-template #empty>
<div class="ion-padding">
<h2>No results</h2>
</div>
</ng-template>
</ion-grid> </ion-grid>
</ng-container> </ng-container>