Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions library/.bitmap
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
/**
* The Bitmap file is an auto generated file used by Bit to track all your Bit components. It maps the component to a folder in your file system.
* This file should be committed to VCS(version control).
* Components are listed using their component ID (https://bit.dev/docs/components/component-id).
* Components are listed using their component ID (https://harmony-docs.bit.dev/aspects/component/#component-id).
* If you want to delete components you can use the "bit remove <component-id>" command.
* See the docs (https://bit.dev/docs/components/removing-components) for more information, or use "bit remove --help".
* See the docs (https://harmony-docs.bit.dev/building-with-bit/removing-components) for more information, or use "bit remove --help".
*/

{
"components": {
"scope": "quarkusio.code-quarkus",
"version": "0.0.43",
"mainFile": "index.ts",
"rootDir": "components"
"rootDir": "components",
"nextVersion": {
"version": "patch",
"message": "",
"username": "Andy Damevin",
"email": "ia3andy@gmail.com"
}
},
"core/analytics": {
"scope": "quarkusio.code-quarkus",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ const entries: ExtensionEntry[] = [
'order': 0,
},
{
'id': 'io.quarkus:quarkus-camel-netty4-http',
'id': 'io.quarkus:quarkus-camel-netty4-http-bab-ejfn-eafjna-fejanfj',
'version': 'test-version',
'name': 'Camel Netty4 test HTTP foo',
'tags': [ 'status:preview', 'status:foo', 'some:test' ],
'default': false,
'keywords': [
'quarkus-camel-netty4-http-bab-ejfn-eafjna-fejanfj',
'cdi',
'test',
'camel-netty4-http',
Expand Down Expand Up @@ -107,4 +108,8 @@ describe('search', () => {
() => expect(search('cdi', processedEntries)).toEqual([ entries[3], entries[0], entries[1], entries[2] ]));
it('"cdi test" is like "cdi test in name,shortname,keywords,category"',
() => expect(search('cdi test', processedEntries)).toEqual(entries));
it('"quarkus-camel-netty4-http-bab-ejfn-eafjna-fejanfj" works with default search"',
() => expect(search('quarkus-camel-netty4-http-bab-ejfn-eafjna-fejanfj', processedEntries)).toEqual([ entries[1] ]));
it('"quarkus-camel-netty4-http-bab-ejfn-eafjna-fejanfj in artifact" works with default search"',
() => expect(search('quarkus-camel-netty4-http-bab-ejfn-eafjna-fejanfj', processedEntries)).toEqual([ entries[1] ]));
});
28 changes: 24 additions & 4 deletions library/components/extensions-picker/extensions-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { ExtensionEntry } from './extensions-picker';
import { Extension } from '../api/model';
import _ from 'lodash';

const matchAll = require('string.prototype.matchall');
function* matchAll(str, regexp) {
const flags = regexp.global ? regexp.flags : regexp.flags + 'g';
const re = new RegExp(regexp, flags);
let match;
while (match = re.exec(str)) {
yield match;
}
}

type ExtensionFieldValueSupplier = (e: Extension) => string | string[] | undefined

Expand All @@ -25,7 +32,7 @@ const FIELD_IDENTIFIERS: ExtensionFieldIdentifier[] = [

const FIELD_KEYS = FIELD_IDENTIFIERS.map(s => s.keys).reduce((acc, value) => acc.concat(value), [])

const getInPattern = keys => `(?<expr>(([a-zA-Z0-9-._]+)\\s*)+)\\sin\\s(?<fields>((${keys.join('|')}),?)+)`;
const getInPattern = keys => `(?<expr>([a-zA-Z0-9-._]+\\s+)*[a-zA-Z0-9-._]+)\\sin\\s(?<fields>((${keys.join('|')}),?)+)`;
const getInRegexp = keys => new RegExp(getInPattern(keys), 'gi');
const getEqualsPattern = keys => `(?<field>${keys.join('|')}):(?<expr>([a-zA-Z0-9-._,]+|("([a-zA-Z0-9-._,:]+\\s*)+")))`;
const getEqualsRegexp = keys => new RegExp(getEqualsPattern(keys), 'gi');
Expand Down Expand Up @@ -108,8 +115,8 @@ export function processExtensionsValues(extensions: Extension[]): ProcessedExten
function inFilter(e: ExtensionValues, expr: string[], fields: string[]) {
for (const field of fields) {
const val = e.values.get(field);
//console.log(`${field} ${val}==${expr}`);
if (val) {
console.log(`${field} ${val}==${expr}`);
let allFoundInValue = true;
for (const e of expr) {
if (val.indexOf(e) < 0) {
Expand Down Expand Up @@ -141,6 +148,11 @@ function equalsFilter(e: ExtensionValues, expr: string[], field: string) {
return false;
}

function defaultFiltering(filtered: ExtensionValues[], formattedSearch: string) {
return filtered.filter(e => inFilter(e, formattedSearch.split(/\s+/), [ 'name', 'shortname', 'keywords', 'category' ]));
}


export function search(search: string, processedExtensions: ProcessedExtensions): Extension[] {
let formattedSearch = search.trim().toLowerCase();
if (!formattedSearch) {
Expand All @@ -152,6 +164,13 @@ export function search(search: string, processedExtensions: ProcessedExtensions)
const val = filtered.splice(shortNameIndex, 1);
filtered.unshift(val[0]);
}
// Basic search
if(formattedSearch.indexOf(' in ') < 0 && formattedSearch.indexOf(':') < 0) {
filtered = defaultFiltering(filtered, formattedSearch);
return filtered.map(e => e.extension);
}

// Complex search
const equalsRegex = getEqualsRegexp(processedExtensions.fieldKeys)
const equalsMatches = matchAll(formattedSearch, equalsRegex);
for (const e of equalsMatches) {
Expand All @@ -165,6 +184,7 @@ export function search(search: string, processedExtensions: ProcessedExtensions)
}

formattedSearch = formattedSearch.replace(equalsRegex, ';').replace(ORIGIN_REGEX, ';').trim();

if (formattedSearch) {
const inRegex = getInRegexp(processedExtensions.fieldKeys)
const inMatches = matchAll(formattedSearch, inRegex);
Expand All @@ -178,7 +198,7 @@ export function search(search: string, processedExtensions: ProcessedExtensions)
}
formattedSearch = formattedSearch.replace(inRegex, '').replace(/;/g, '').trim();
if (formattedSearch) {
filtered = filtered.filter(e => inFilter(e, formattedSearch.split(/\s+/), [ 'name', 'shortname', 'keywords', 'category' ]));
filtered = defaultFiltering(filtered, formattedSearch);
}
}
return filtered.map(e => e.extension);
Expand Down
1 change: 0 additions & 1 deletion library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"react-dom": "17.0.2",
"react-hotkeys-hook": "3.4.4",
"react-icons": "4.3.1",
"string.prototype.matchall": "4.0.7",
"typescript": "4.6.2",
"use-persisted-state": "0.3.3"
},
Expand Down
2 changes: 1 addition & 1 deletion library/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ string-width@^4.1.0, string-width@^4.2.0:
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.0"

string.prototype.matchall@4.0.7, string.prototype.matchall@^4.0.6:
string.prototype.matchall@^4.0.6:
version "4.0.7"
resolved "https://registry.yarnpkg.com/string.prototype.matchall/-/string.prototype.matchall-4.0.7.tgz#8e6ecb0d8a1fb1fda470d81acecb2dba057a481d"
integrity sha512-f48okCX7JiwVi1NXCVWcFnZgADDC/n2vePlQ/KUCNqCikLLilQvwjMO8+BHVKvgzH0JB0J9LEPgxOGT02RoETg==
Expand Down