2019-11-26 14:14:21 +00:00
|
|
|
import {
|
|
|
|
QuickSearchAction,
|
|
|
|
QuickSearchActionInput,
|
2022-06-21 09:36:55 +00:00
|
|
|
QuickSearchMode,
|
2019-11-26 14:14:21 +00:00
|
|
|
} from "../types";
|
2019-11-22 15:39:20 +00:00
|
|
|
|
|
|
|
export function getActions(actions: QuickSearchAction[]): QuickSearchAction[] {
|
|
|
|
return actions.filter(action => action.type === "action");
|
|
|
|
}
|
|
|
|
export function hasActions(actions: QuickSearchAction[]): boolean {
|
|
|
|
return getActions(actions).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getViews(actions: QuickSearchAction[]): QuickSearchAction[] {
|
|
|
|
return actions.filter(action => action.type === "view");
|
|
|
|
}
|
|
|
|
export function hasViews(actions: QuickSearchAction[]): boolean {
|
|
|
|
return getViews(actions).length > 0;
|
|
|
|
}
|
2019-11-25 11:29:07 +00:00
|
|
|
|
|
|
|
export function getCustomers(
|
2022-06-21 09:36:55 +00:00
|
|
|
actions: QuickSearchAction[],
|
2019-11-25 11:29:07 +00:00
|
|
|
): QuickSearchAction[] {
|
|
|
|
return actions.filter(action => action.type === "customer");
|
|
|
|
}
|
|
|
|
export function hasCustomers(actions: QuickSearchAction[]): boolean {
|
|
|
|
return getCustomers(actions).length > 0;
|
|
|
|
}
|
2019-11-25 14:32:10 +00:00
|
|
|
|
|
|
|
export function getCatalog(actions: QuickSearchAction[]): QuickSearchAction[] {
|
|
|
|
return actions.filter(action => action.type === "catalog");
|
|
|
|
}
|
|
|
|
export function hasCatalog(actions: QuickSearchAction[]): boolean {
|
|
|
|
return getCatalog(actions).length > 0;
|
|
|
|
}
|
2019-11-25 14:57:50 +00:00
|
|
|
|
|
|
|
export function sortScores(
|
|
|
|
a: QuickSearchActionInput,
|
2022-06-21 09:36:55 +00:00
|
|
|
b: QuickSearchActionInput,
|
2019-11-25 14:57:50 +00:00
|
|
|
) {
|
|
|
|
return a.score <= b.score ? 1 : -1;
|
|
|
|
}
|
2019-11-26 14:14:21 +00:00
|
|
|
|
|
|
|
export function getMode(command: string): QuickSearchMode {
|
|
|
|
switch (command) {
|
|
|
|
case ">":
|
|
|
|
return "commands";
|
|
|
|
case "@":
|
|
|
|
return "customers";
|
|
|
|
case "#":
|
|
|
|
return "orders";
|
|
|
|
case "$":
|
|
|
|
return "catalog";
|
|
|
|
case "?":
|
|
|
|
return "help";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|