diff --git a/super-pane/create-super-pane.tsx b/super-pane/create-super-pane.tsx index 0c2002d..894a3a2 100644 --- a/super-pane/create-super-pane.tsx +++ b/super-pane/create-super-pane.tsx @@ -26,8 +26,10 @@ import { SyncIcon, SpinnerIcon, ControlsIcon, + SearchIcon, } from '@sanity/icons'; import styles from './styles.module.css'; +import SearchField from './search-field'; function parentHasClass(el: HTMLElement | null, className: string): boolean { if (!el) return false; @@ -39,6 +41,14 @@ function createSuperPane(typeName: string, S: any) { const schemaType = schema.get(typeName); const selectColumns = createEmitter(); const refresh = createEmitter(); + const search = createEmitter(); + + const fieldsToChooseFrom = (schemaType.fields as any[]) + .filter((field: any) => field?.type?.jsonType === 'string') + .map((field: any) => ({ + name: field.name as string, + title: field.type.title as string, + })); function SuperPane() { const router = useRouter(); @@ -46,13 +56,17 @@ function createSuperPane(typeName: string, S: any) { const [columnSelectorOpen, setColumnSelectorOpen] = useState(false); const [selectedColumns, setSelectedColumns] = useState(new Set()); const [selectedIds, setSelectedIds] = useState(new Set()); - + const [selectedSearchField, setSelectedSearchField] = useState< + string | null + >(fieldsToChooseFrom[0].name || null); + const [showSearch, setShowSearch] = useState(false); const containerRef = useRef(null); const client = usePaginatedClient({ typeName, pageSize, selectedColumns, + searchField: selectedSearchField, }); useEffect(() => { @@ -63,6 +77,10 @@ function createSuperPane(typeName: string, S: any) { return refresh.subscribe(client.refresh); }, [client.refresh]); + useEffect(() => { + return search.subscribe(() => setShowSearch((prev) => !prev)); + }, []); + const fields = schemaType.fields.filter((field: any) => selectedColumns.has(field.name) ); @@ -106,7 +124,16 @@ function createSuperPane(typeName: string, S: any) { /> - + {showSearch && ( +
+ +
+ )}
25 + +
@@ -332,7 +361,8 @@ function createSuperPane(typeName: string, S: any) { mode="bleed" />