mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-15 19:27:49 +01:00
feat: fuzzy search
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"file-saver": "^2.0.5",
|
||||
"firebase": "^9.12.1",
|
||||
"firebaseui": "^6.0.1",
|
||||
"fuse.js": "^7.0.0",
|
||||
"jotai": "^1.8.4",
|
||||
"json-stable-stringify-without-jsonify": "^1.0.1",
|
||||
"jszip": "^3.10.0",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import MultiSelect from "@rowy/multiselect";
|
||||
import { Box, ListItemIcon, Typography } from "@mui/material";
|
||||
import Fuse from 'fuse.js';
|
||||
|
||||
import { FIELDS } from "@src/components/fields";
|
||||
import { FieldType } from "@src/constants/fields";
|
||||
@@ -23,6 +24,15 @@ export interface IFieldsDropdownProps {
|
||||
[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
|
||||
*/
|
||||
@@ -52,9 +62,21 @@ export default function FieldsDropdown({
|
||||
disabled: requireCloudFunctionSetup || requireCollectionTable,
|
||||
requireCloudFunctionSetup,
|
||||
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 (
|
||||
<MultiSelect
|
||||
multiple={false}
|
||||
@@ -80,6 +102,7 @@ export default function FieldsDropdown({
|
||||
},
|
||||
},
|
||||
},
|
||||
filterOptions
|
||||
},
|
||||
} as any)}
|
||||
itemRenderer={(option) => (
|
||||
|
||||
@@ -31,5 +31,6 @@ export const config: IFieldConfig = {
|
||||
filter: { operators, defaultValue: [] },
|
||||
requireConfiguration: false,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["list"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -45,5 +45,6 @@ export const config: IFieldConfig = {
|
||||
},
|
||||
SideDrawerField,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["boolean", "switch", "true", "false", "on", "off"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -34,5 +34,6 @@ export const config: IFieldConfig = {
|
||||
SideDrawerField,
|
||||
settings: Settings,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["snippet", "block"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -44,5 +44,6 @@ export const config: IFieldConfig = {
|
||||
}
|
||||
},
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["hexcode"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -30,5 +30,6 @@ export const config: IFieldConfig = {
|
||||
settings: Settings,
|
||||
requireCollectionTable: true,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["date", "time"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -31,5 +31,6 @@ export const config: IFieldConfig = {
|
||||
settings: Settings,
|
||||
requireCollectionTable: true,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["date", "time"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -27,5 +27,6 @@ export const config: IFieldConfig = {
|
||||
settings: Settings,
|
||||
settingsValidator: settingsValidator,
|
||||
requireConfiguration: true,
|
||||
keywords: ["equation"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -26,5 +26,6 @@ export const config: IFieldConfig = {
|
||||
}),
|
||||
SideDrawerField,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["location", "latitude", "longitude", "point"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -19,5 +19,6 @@ export const config: IFieldConfig = {
|
||||
description: "Displays the row’s ID. Read-only. Cannot be sorted.",
|
||||
TableCell: withRenderTableCell(DisplayCell, null),
|
||||
SideDrawerField,
|
||||
keywords: ["unique"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -28,6 +28,7 @@ export const config: IFieldConfig = {
|
||||
}),
|
||||
SideDrawerField,
|
||||
contextMenuActions: ContextMenuActions,
|
||||
keywords: ["picture"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
|
||||
@@ -35,5 +35,6 @@ export const config: IFieldConfig = {
|
||||
filter: {
|
||||
operators: filterOperators,
|
||||
},
|
||||
keywords: ["string"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -25,5 +25,6 @@ export const config: IFieldConfig = {
|
||||
TableCell: withRenderTableCell(DisplayCell, SideDrawerField, "popover"),
|
||||
SideDrawerField,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["md"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -50,5 +50,6 @@ export const config: IFieldConfig = {
|
||||
operators: filterOperators,
|
||||
},
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["options"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -35,5 +35,6 @@ export const config: IFieldConfig = {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
keywords: ["digit"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -28,5 +28,6 @@ export const config: IFieldConfig = {
|
||||
filter: {
|
||||
operators: filterOperators,
|
||||
},
|
||||
keywords: ["number", "contact"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -46,5 +46,6 @@ export const config: IFieldConfig = {
|
||||
}
|
||||
},
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["star"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -25,5 +25,6 @@ export const config: IFieldConfig = {
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
TableCell: withRenderTableCell(DisplayCell, SideDrawerField, "popover"),
|
||||
SideDrawerField,
|
||||
keywords: ["string"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -36,5 +36,6 @@ export const config: IFieldConfig = {
|
||||
filter: {
|
||||
operators: filterOperators,
|
||||
},
|
||||
keywords: ["string"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -37,5 +37,6 @@ export const config: IFieldConfig = {
|
||||
filter: { operators: filterOperators },
|
||||
requireConfiguration: true,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["options"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -31,5 +31,6 @@ export const config: IFieldConfig = {
|
||||
settings: Settings,
|
||||
requireCollectionTable: true,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["date", "time"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -33,5 +33,6 @@ export const config: IFieldConfig = {
|
||||
settings: Settings,
|
||||
requireCollectionTable: true,
|
||||
contextMenuActions: BasicContextMenuActions,
|
||||
keywords: ["date", "time"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -30,5 +30,6 @@ export const config: IFieldConfig = {
|
||||
filter: {
|
||||
operators: filterOperators,
|
||||
},
|
||||
keywords: ["link", "path"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -29,5 +29,6 @@ export const config: IFieldConfig = {
|
||||
}),
|
||||
SideDrawerField,
|
||||
settings: Settings,
|
||||
keywords: ["entity"]
|
||||
};
|
||||
export default config;
|
||||
|
||||
@@ -42,6 +42,7 @@ export interface IFieldConfig {
|
||||
sortKey?: string;
|
||||
csvExportFormatter?: (value: any, config?: any) => string;
|
||||
csvImportParser?: (value: string, config?: any) => any;
|
||||
keywords?: string[];
|
||||
}
|
||||
|
||||
/** See {@link IRenderedTableCellProps | `withRenderTableCell` } for guidance */
|
||||
|
||||
@@ -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"
|
||||
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:
|
||||
version "1.0.0-beta.2"
|
||||
resolved "https://registry.yarnpkg.com/gensync/-/gensync-1.0.0-beta.2.tgz#32a6ee76c3d7f52d46b2b1ae5d93fea8580a25e0"
|
||||
|
||||
Reference in New Issue
Block a user