mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 00:36:00 +00:00
SYNC: support OR in filterName
This commit is contained in:
committed by
Diflow
parent
c8462fb50b
commit
d3d97b5924
@@ -6,6 +6,29 @@ import _startCase from 'lodash/startCase';
|
|||||||
// childName: string;
|
// childName: string;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
interface TokenFactor {
|
||||||
|
tokens: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TokenTree {
|
||||||
|
factors: TokenFactor[];
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTokenTree(filter: string): TokenTree {
|
||||||
|
const factors = filter
|
||||||
|
.split(',')
|
||||||
|
.map(x => x.trim())
|
||||||
|
.filter(x => x.length > 0);
|
||||||
|
return {
|
||||||
|
factors: factors.map(x => ({
|
||||||
|
tokens: x
|
||||||
|
.split(' ')
|
||||||
|
.map(x => x.trim())
|
||||||
|
.filter(x => x.length > 0),
|
||||||
|
})),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function camelMatch(filter: string, text: string): boolean {
|
function camelMatch(filter: string, text: string): boolean {
|
||||||
if (!text) return false;
|
if (!text) return false;
|
||||||
if (!filter) return true;
|
if (!filter) return true;
|
||||||
@@ -24,31 +47,27 @@ export function filterName(filter: string, ...names: string[]) {
|
|||||||
if (!filter) return true;
|
if (!filter) return true;
|
||||||
|
|
||||||
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
|
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
|
||||||
const tokens = filter.split(' ').map(x => x.trim());
|
const tree = parseTokenTree(filter);
|
||||||
|
|
||||||
|
if (tree.factors.length == 0) return true;
|
||||||
|
|
||||||
const namesCompacted = _compact(names);
|
const namesCompacted = _compact(names);
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const factor of tree.factors) {
|
||||||
const found = namesCompacted.find(name => camelMatch(token, name));
|
let factorOk = true;
|
||||||
if (!found) return false;
|
for (const token of factor.tokens) {
|
||||||
|
const found = namesCompacted.find(name => camelMatch(token, name));
|
||||||
|
if (!found) factorOk = false;
|
||||||
|
}
|
||||||
|
if (factorOk) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function filterNameCompoud(
|
function clasifyCompoudCategory(tokens: string[], namesCompactedMain: string[], namesCompactedChild: string[]) {
|
||||||
filter: string,
|
|
||||||
namesMain: string[],
|
|
||||||
namesChild: string[]
|
|
||||||
): 'main' | 'child' | 'both' | 'none' {
|
|
||||||
if (!filter) return 'both';
|
|
||||||
|
|
||||||
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
|
|
||||||
const tokens = filter.split(' ').map(x => x.trim());
|
|
||||||
|
|
||||||
const namesCompactedMain = _compact(namesMain);
|
|
||||||
const namesCompactedChild = _compact(namesChild);
|
|
||||||
|
|
||||||
let isMainOnly = true;
|
let isMainOnly = true;
|
||||||
let isChildOnly = true;
|
let isChildOnly = true;
|
||||||
|
|
||||||
@@ -67,10 +86,39 @@ export function filterNameCompoud(
|
|||||||
return 'none';
|
return 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function filterNameCompoud(
|
||||||
|
filter: string,
|
||||||
|
namesMain: string[],
|
||||||
|
namesChild: string[]
|
||||||
|
): 'main' | 'child' | 'both' | 'none' {
|
||||||
|
if (!filter) return 'both';
|
||||||
|
|
||||||
|
// const camelVariants = [name.replace(/[^A-Z]/g, '')]
|
||||||
|
const tree = parseTokenTree(filter);
|
||||||
|
|
||||||
|
const namesCompactedMain = _compact(namesMain);
|
||||||
|
const namesCompactedChild = _compact(namesChild);
|
||||||
|
|
||||||
|
if (tree.factors.length == 0) return 'both';
|
||||||
|
|
||||||
|
const factorRes = [];
|
||||||
|
|
||||||
|
for (const factor of tree.factors) {
|
||||||
|
const category = clasifyCompoudCategory(factor.tokens, namesCompactedMain, namesCompactedChild);
|
||||||
|
factorRes.push(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (factorRes.includes('both')) return 'both';
|
||||||
|
if (factorRes.includes('main') && factorRes.includes('child')) return 'both';
|
||||||
|
if (factorRes.includes('main')) return 'main';
|
||||||
|
if (factorRes.includes('child')) return 'child';
|
||||||
|
return 'none';
|
||||||
|
}
|
||||||
|
|
||||||
export function tokenizeBySearchFilter(text: string, filter: string): { text: string; isMatch: boolean }[] {
|
export function tokenizeBySearchFilter(text: string, filter: string): { text: string; isMatch: boolean }[] {
|
||||||
const camelTokens = [];
|
const camelTokens = [];
|
||||||
const stdTokens = [];
|
const stdTokens = [];
|
||||||
for (const token of filter.split(' ').map(x => x.trim())) {
|
for (const token of filter.split(/ ,/).map(x => x.trim())) {
|
||||||
if (token.replace(/[A-Z]/g, '').length == 0) {
|
if (token.replace(/[A-Z]/g, '').length == 0) {
|
||||||
camelTokens.push(token);
|
camelTokens.push(token);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -117,7 +117,6 @@
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
$: console.log('$styleStore', $styleStore);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ToolStripContainer>
|
<ToolStripContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user