mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
table connect filter
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
||||
import useAlgolia from "use-algolia";
|
||||
import _find from "lodash/find";
|
||||
import { useDebounce } from "use-debounce";
|
||||
import _get from "lodash/get";
|
||||
|
||||
import MultiSelect, { MultiSelectProps } from "@antlerengineering/multiselect";
|
||||
import Loading from "components/Loading";
|
||||
@@ -11,6 +12,12 @@ export type ConnectTableValue = {
|
||||
snapshot: Record<string, any>;
|
||||
};
|
||||
|
||||
const replacer = (data: any) => (m: string, key: string) => {
|
||||
const objKey = key.split(":")[0];
|
||||
const defaultValue = key.split(":")[1] || "";
|
||||
return _get(data, objKey, defaultValue);
|
||||
};
|
||||
|
||||
export interface IConnectTableSelectProps {
|
||||
value: ConnectTableValue[];
|
||||
onChange: (value: ConnectTableValue[]) => void;
|
||||
@@ -26,6 +33,7 @@ export interface IConnectTableSelectProps {
|
||||
disabled?: boolean;
|
||||
/** Optional style overrides for root MUI `TextField` component */
|
||||
className?: string;
|
||||
row:any;
|
||||
/** Override any props of the root MUI `TextField` component */
|
||||
TextFieldProps?: MultiSelectProps<ConnectTableValue[]>["TextFieldProps"];
|
||||
onClose?: MultiSelectProps<ConnectTableValue[]>["onClose"];
|
||||
@@ -37,7 +45,7 @@ export default function ConnectTableSelect({
|
||||
value = [],
|
||||
onChange,
|
||||
column,
|
||||
|
||||
row,
|
||||
config,
|
||||
disabled,
|
||||
className,
|
||||
@@ -51,7 +59,6 @@ export default function ConnectTableSelect({
|
||||
const [localValue, setLocalValue] = useState(
|
||||
Array.isArray(value) ? value : []
|
||||
);
|
||||
|
||||
const algoliaIndex = config.index;
|
||||
const [algoliaState, requestDispatch, , setAlgoliaConfig] = useAlgolia(
|
||||
process.env.REACT_APP_ALGOLIA_APP_ID!,
|
||||
@@ -110,7 +117,6 @@ export default function ConnectTableSelect({
|
||||
if (config.multiple !== false) onChange(localValue);
|
||||
if (onClose) onClose();
|
||||
};
|
||||
|
||||
// Change MultiSelect input field to search Algolia directly
|
||||
const [search, setSearch] = useState("");
|
||||
const [debouncedSearch] = useDebounce(search, 1000);
|
||||
@@ -122,7 +128,13 @@ export default function ConnectTableSelect({
|
||||
<MultiSelect
|
||||
value={config.multiple === false ? sanitisedValue[0] : sanitisedValue}
|
||||
onChange={handleChange}
|
||||
onOpen={() => setAlgoliaConfig({ indexName: algoliaIndex })}
|
||||
onOpen={() => {
|
||||
setAlgoliaConfig({ indexName: algoliaIndex })
|
||||
requestDispatch({ filters:config.filters.replace(
|
||||
/\{\{(.*?)\}\}/g,
|
||||
replacer(row)
|
||||
)});
|
||||
}}
|
||||
onClose={handleSave}
|
||||
options={options}
|
||||
TextFieldProps={{
|
||||
|
||||
@@ -10,6 +10,7 @@ export default function ConnectTable({
|
||||
column,
|
||||
parentRef,
|
||||
showPopoverCell,
|
||||
row,
|
||||
disabled,
|
||||
}: IPopoverCellProps) {
|
||||
const config = column.config ?? {};
|
||||
@@ -17,6 +18,7 @@ export default function ConnectTable({
|
||||
|
||||
return (
|
||||
<ConnectTableSelect
|
||||
row={row}
|
||||
column={column}
|
||||
value={value}
|
||||
onChange={onSubmit}
|
||||
|
||||
@@ -30,6 +30,7 @@ export default function ConnectTable({
|
||||
<>
|
||||
{!disabled && (
|
||||
<ConnectTableSelect
|
||||
row={control.getValues()}
|
||||
column={column}
|
||||
config={(config as any) ?? {}}
|
||||
value={value}
|
||||
|
||||
Reference in New Issue
Block a user