feat: fuzzy search

This commit is contained in:
mehulmathur16
2024-02-01 16:45:51 +05:30
parent f8e6aa8448
commit fa5dc188c5
27 changed files with 53 additions and 0 deletions

View File

@@ -34,6 +34,7 @@
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"firebase": "^9.12.1", "firebase": "^9.12.1",
"firebaseui": "^6.0.1", "firebaseui": "^6.0.1",
"fuse.js": "^7.0.0",
"jotai": "^1.8.4", "jotai": "^1.8.4",
"json-stable-stringify-without-jsonify": "^1.0.1", "json-stable-stringify-without-jsonify": "^1.0.1",
"jszip": "^3.10.0", "jszip": "^3.10.0",

View File

@@ -1,5 +1,6 @@
import MultiSelect from "@rowy/multiselect"; import MultiSelect from "@rowy/multiselect";
import { Box, ListItemIcon, Typography } from "@mui/material"; import { Box, ListItemIcon, Typography } from "@mui/material";
import Fuse from 'fuse.js';
import { FIELDS } from "@src/components/fields"; import { FIELDS } from "@src/components/fields";
import { FieldType } from "@src/constants/fields"; import { FieldType } from "@src/constants/fields";
@@ -23,6 +24,15 @@ export interface IFieldsDropdownProps {
[key: string]: any; [key: string]: any;
} }
export interface OptionsType {
label: string;
value: string;
disabled: boolean;
requireCloudFunctionSetup: boolean;
requireCollectionTable: boolean;
keywords: string[];
}
/** /**
* Returns dropdown component of all available types * Returns dropdown component of all available types
*/ */
@@ -52,9 +62,21 @@ export default function FieldsDropdown({
disabled: requireCloudFunctionSetup || requireCollectionTable, disabled: requireCloudFunctionSetup || requireCollectionTable,
requireCloudFunctionSetup, requireCloudFunctionSetup,
requireCollectionTable, requireCollectionTable,
keywords: fieldConfig.keywords || []
}; };
}); });
const filterOptions = (options: OptionsType[], inputConfig: any) => {
const fuse = new Fuse(options, {
keys: [{name:'label', weight: 2}, 'keywords'],
includeScore: true,
threshold: 0.4,
});
const results = fuse.search(inputConfig?.inputValue);
return results.length > 0 ? results.map((result) => result.item) : options;
}
return ( return (
<MultiSelect <MultiSelect
multiple={false} multiple={false}
@@ -80,6 +102,7 @@ export default function FieldsDropdown({
}, },
}, },
}, },
filterOptions
}, },
} as any)} } as any)}
itemRenderer={(option) => ( itemRenderer={(option) => (

View File

@@ -31,5 +31,6 @@ export const config: IFieldConfig = {
filter: { operators, defaultValue: [] }, filter: { operators, defaultValue: [] },
requireConfiguration: false, requireConfiguration: false,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["list"]
}; };
export default config; export default config;

View File

@@ -45,5 +45,6 @@ export const config: IFieldConfig = {
}, },
SideDrawerField, SideDrawerField,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["boolean", "switch", "true", "false", "on", "off"]
}; };
export default config; export default config;

View File

@@ -34,5 +34,6 @@ export const config: IFieldConfig = {
SideDrawerField, SideDrawerField,
settings: Settings, settings: Settings,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["snippet", "block"]
}; };
export default config; export default config;

View File

@@ -44,5 +44,6 @@ export const config: IFieldConfig = {
} }
}, },
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["hexcode"]
}; };
export default config; export default config;

View File

@@ -30,5 +30,6 @@ export const config: IFieldConfig = {
settings: Settings, settings: Settings,
requireCollectionTable: true, requireCollectionTable: true,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["date", "time"]
}; };
export default config; export default config;

View File

@@ -31,5 +31,6 @@ export const config: IFieldConfig = {
settings: Settings, settings: Settings,
requireCollectionTable: true, requireCollectionTable: true,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["date", "time"]
}; };
export default config; export default config;

View File

@@ -27,5 +27,6 @@ export const config: IFieldConfig = {
settings: Settings, settings: Settings,
settingsValidator: settingsValidator, settingsValidator: settingsValidator,
requireConfiguration: true, requireConfiguration: true,
keywords: ["equation"]
}; };
export default config; export default config;

View File

@@ -26,5 +26,6 @@ export const config: IFieldConfig = {
}), }),
SideDrawerField, SideDrawerField,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["location", "latitude", "longitude", "point"]
}; };
export default config; export default config;

View File

@@ -19,5 +19,6 @@ export const config: IFieldConfig = {
description: "Displays the rows ID. Read-only. Cannot be sorted.", description: "Displays the rows ID. Read-only. Cannot be sorted.",
TableCell: withRenderTableCell(DisplayCell, null), TableCell: withRenderTableCell(DisplayCell, null),
SideDrawerField, SideDrawerField,
keywords: ["unique"]
}; };
export default config; export default config;

View File

@@ -28,6 +28,7 @@ export const config: IFieldConfig = {
}), }),
SideDrawerField, SideDrawerField,
contextMenuActions: ContextMenuActions, contextMenuActions: ContextMenuActions,
keywords: ["picture"]
}; };
export default config; export default config;

View File

@@ -35,5 +35,6 @@ export const config: IFieldConfig = {
filter: { filter: {
operators: filterOperators, operators: filterOperators,
}, },
keywords: ["string"]
}; };
export default config; export default config;

View File

@@ -25,5 +25,6 @@ export const config: IFieldConfig = {
TableCell: withRenderTableCell(DisplayCell, SideDrawerField, "popover"), TableCell: withRenderTableCell(DisplayCell, SideDrawerField, "popover"),
SideDrawerField, SideDrawerField,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["md"]
}; };
export default config; export default config;

View File

@@ -50,5 +50,6 @@ export const config: IFieldConfig = {
operators: filterOperators, operators: filterOperators,
}, },
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["options"]
}; };
export default config; export default config;

View File

@@ -35,5 +35,6 @@ export const config: IFieldConfig = {
return null; return null;
} }
}, },
keywords: ["digit"]
}; };
export default config; export default config;

View File

@@ -28,5 +28,6 @@ export const config: IFieldConfig = {
filter: { filter: {
operators: filterOperators, operators: filterOperators,
}, },
keywords: ["number", "contact"]
}; };
export default config; export default config;

View File

@@ -46,5 +46,6 @@ export const config: IFieldConfig = {
} }
}, },
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["star"]
}; };
export default config; export default config;

View File

@@ -25,5 +25,6 @@ export const config: IFieldConfig = {
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
TableCell: withRenderTableCell(DisplayCell, SideDrawerField, "popover"), TableCell: withRenderTableCell(DisplayCell, SideDrawerField, "popover"),
SideDrawerField, SideDrawerField,
keywords: ["string"]
}; };
export default config; export default config;

View File

@@ -36,5 +36,6 @@ export const config: IFieldConfig = {
filter: { filter: {
operators: filterOperators, operators: filterOperators,
}, },
keywords: ["string"]
}; };
export default config; export default config;

View File

@@ -37,5 +37,6 @@ export const config: IFieldConfig = {
filter: { operators: filterOperators }, filter: { operators: filterOperators },
requireConfiguration: true, requireConfiguration: true,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["options"]
}; };
export default config; export default config;

View File

@@ -31,5 +31,6 @@ export const config: IFieldConfig = {
settings: Settings, settings: Settings,
requireCollectionTable: true, requireCollectionTable: true,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["date", "time"]
}; };
export default config; export default config;

View File

@@ -33,5 +33,6 @@ export const config: IFieldConfig = {
settings: Settings, settings: Settings,
requireCollectionTable: true, requireCollectionTable: true,
contextMenuActions: BasicContextMenuActions, contextMenuActions: BasicContextMenuActions,
keywords: ["date", "time"]
}; };
export default config; export default config;

View File

@@ -30,5 +30,6 @@ export const config: IFieldConfig = {
filter: { filter: {
operators: filterOperators, operators: filterOperators,
}, },
keywords: ["link", "path"]
}; };
export default config; export default config;

View File

@@ -29,5 +29,6 @@ export const config: IFieldConfig = {
}), }),
SideDrawerField, SideDrawerField,
settings: Settings, settings: Settings,
keywords: ["entity"]
}; };
export default config; export default config;

View File

@@ -42,6 +42,7 @@ export interface IFieldConfig {
sortKey?: string; sortKey?: string;
csvExportFormatter?: (value: any, config?: any) => string; csvExportFormatter?: (value: any, config?: any) => string;
csvImportParser?: (value: string, config?: any) => any; csvImportParser?: (value: string, config?: any) => any;
keywords?: string[];
} }
/** See {@link IRenderedTableCellProps | `withRenderTableCell` } for guidance */ /** See {@link IRenderedTableCellProps | `withRenderTableCell` } for guidance */

View File

@@ -5208,6 +5208,11 @@ functions-have-names@^1.2.2:
resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834" resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834"
integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ== integrity sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==
fuse.js@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/fuse.js/-/fuse.js-7.0.0.tgz#6573c9fcd4c8268e403b4fc7d7131ffcf99a9eb2"
integrity sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==
gensync@^1.0.0-beta.2: gensync@^1.0.0-beta.2:
version "1.0.0-beta.2" version "1.0.0-beta.2"
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0" resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"