diff --git a/packages/core/src/components/collections/NestedCollection.tsx b/packages/core/src/components/collections/NestedCollection.tsx index d0744ea6..02ddbb99 100644 --- a/packages/core/src/components/collections/NestedCollection.tsx +++ b/packages/core/src/components/collections/NestedCollection.tsx @@ -135,7 +135,6 @@ const NestedCollection = ({ collection, filterTerm }: NestedCollectionProps) => const entries = useEntries(collection); const [treeData, setTreeData] = useState(getTreeData(collection, entries)); - console.log('TREE DATA', treeData, collection, entries); const [selected, setSelected] = useState(null); const [useFilter, setUseFilter] = useState(true); diff --git a/packages/core/src/components/common/field/Field.tsx b/packages/core/src/components/common/field/Field.tsx index ddd54230..f0b97744 100644 --- a/packages/core/src/components/common/field/Field.tsx +++ b/packages/core/src/components/common/field/Field.tsx @@ -21,6 +21,7 @@ export interface FieldProps { noPadding?: boolean; noHightlight?: boolean; disabled: boolean; + disableClick?: boolean; } const Field: FC = ({ @@ -35,13 +36,14 @@ const Field: FC = ({ noPadding = false, noHightlight = false, disabled, + disableClick = false, }) => { const finalCursor = useCursor(cursor, disabled); const hasErrors = useMemo(() => errors.length > 0, [errors.length]); const handleOnClick = (event: MouseEvent) => { - if (disabled) { + if (disabled || disableClick) { return; } diff --git a/packages/core/src/components/common/select/Select.tsx b/packages/core/src/components/common/select/Select.tsx index 509dff53..c0bada1d 100644 --- a/packages/core/src/components/common/select/Select.tsx +++ b/packages/core/src/components/common/select/Select.tsx @@ -2,7 +2,6 @@ import SelectUnstyled from '@mui/base/SelectUnstyled'; import { KeyboardArrowDown as KeyboardArrowDownIcon } from '@styled-icons/material/KeyboardArrowDown'; import React, { forwardRef, useCallback, useState } from 'react'; -import useDebounce from '@staticcms/core/lib/hooks/useDebounce'; import useElementSize from '@staticcms/core/lib/hooks/useElementSize'; import classNames from '@staticcms/core/lib/util/classNames.util'; import { isNotEmpty } from '@staticcms/core/lib/util/string.util'; @@ -33,26 +32,32 @@ export interface SelectProps { required?: boolean; disabled?: boolean; onChange: SelectChangeEventHandler; + onOpenChange?: (open: boolean) => void; } const Select = forwardRef( ( - { label, placeholder, value, options, required = false, disabled, onChange }: SelectProps, + { + label, + placeholder, + value, + options, + required = false, + disabled, + onChange, + onOpenChange, + }: SelectProps, ref: Ref, ) => { const { width } = useElementSize(ref); const [open, setOpen] = useState(false); - const debouncedOpen = useDebounce(open, 200); const handleOpenChange = useCallback( (newOpen: boolean) => { - if (debouncedOpen !== open) { - return; - } - setOpen(newOpen); + onOpenChange?.(newOpen); }, - [debouncedOpen, open], + [onOpenChange], ); const handleButtonClick = useCallback(() => handleOpenChange(!open), [handleOpenChange, open]); diff --git a/packages/core/src/lib/util/__tests__/nested.util.spec.ts b/packages/core/src/lib/util/__tests__/nested.util.spec.ts index 16677ffb..dc884f8a 100644 --- a/packages/core/src/lib/util/__tests__/nested.util.spec.ts +++ b/packages/core/src/lib/util/__tests__/nested.util.spec.ts @@ -179,7 +179,7 @@ describe('nested.util', () => { expect(authorsNode.isDir).toBe(true); expect(authorsNode.isRoot).toBe(false); expect(authorsNode.path).toBe('/authors'); - expect(authorsNode.title).toBe('/authors'); + expect(authorsNode.title).toBe('authors'); expect(authorsNode.children.length).toBe(2); // ROOT > Authors Node > index.md @@ -195,7 +195,7 @@ describe('nested.util', () => { expect(anAuthorNode.isDir).toBe(true); expect(anAuthorNode.isRoot).toBe(false); expect(anAuthorNode.path).toBe('/authors/author-1'); - expect(anAuthorNode.title).toBe('/authors/author-1'); + expect(anAuthorNode.title).toBe('author-1'); expect(anAuthorNode.children.length).toBe(1); // ROOT > Authors Node > An Author Node > index.md @@ -211,7 +211,7 @@ describe('nested.util', () => { expect(postsNode.isDir).toBe(true); expect(postsNode.isRoot).toBe(false); expect(postsNode.path).toBe('/posts'); - expect(postsNode.title).toBe('/posts'); + expect(postsNode.title).toBe('posts'); expect(postsNode.children.length).toBe(3); // ROOT > Posts Node > index.md @@ -227,7 +227,7 @@ describe('nested.util', () => { expect(helloWorldNode.isDir).toBe(true); expect(helloWorldNode.isRoot).toBe(false); expect(helloWorldNode.path).toBe('/posts/hello-world'); - expect(helloWorldNode.title).toBe('/posts/hello-world'); + expect(helloWorldNode.title).toBe('hello-world'); expect(helloWorldNode.children.length).toBe(1); // ROOT > Posts Node > Hello World Node > index.md @@ -243,7 +243,7 @@ describe('nested.util', () => { expect(newsArticlesNode.isDir).toBe(true); expect(newsArticlesNode.isRoot).toBe(false); expect(newsArticlesNode.path).toBe('/posts/news'); - expect(newsArticlesNode.title).toBe('/posts/news'); + expect(newsArticlesNode.title).toBe('news'); expect(newsArticlesNode.children.length).toBe(2); // ROOT > Posts Node > Hello World Node > index.md @@ -259,7 +259,7 @@ describe('nested.util', () => { expect(helloWorldNewsNode.isDir).toBe(true); expect(helloWorldNewsNode.isRoot).toBe(false); expect(helloWorldNewsNode.path).toBe('/posts/news/hello-world-news'); - expect(helloWorldNewsNode.title).toBe('/posts/news/hello-world-news'); + expect(helloWorldNewsNode.title).toBe('hello-world-news'); expect(helloWorldNewsNode.children.length).toBe(1); // ROOT > Posts Node > Hello World Node > Hello World News Node > index.md diff --git a/packages/core/src/lib/util/nested.util.ts b/packages/core/src/lib/util/nested.util.ts index adae1109..276937e3 100644 --- a/packages/core/src/lib/util/nested.util.ts +++ b/packages/core/src/lib/util/nested.util.ts @@ -1,5 +1,5 @@ import trim from 'lodash/trim'; -import { basename, dirname, extname, join, sep } from 'path'; +import { basename, dirname, extname, join } from 'path'; import { sanitizeSlug } from '../urlHelper'; import { selectEntryCollectionTitle, selectFolderEntryExtension } from './collection.util'; @@ -104,9 +104,9 @@ export function getTreeData( const dirs = entriesObj.reduce((acc, entry) => { let dir: string | undefined = dirname(entry.path); while (dir && !acc[dir] && dir !== rootFolder) { - const parts: string[] = dir.split(sep); + const parts: string[] = dir.split('/'); acc[dir] = parts.pop(); - dir = parts.length ? parts.join(sep) : undefined; + dir = parts.length ? parts.join('/') : undefined; } return acc; }, {} as Record); diff --git a/packages/core/src/widgets/select/SelectControl.tsx b/packages/core/src/widgets/select/SelectControl.tsx index d5d357f5..9778bd62 100644 --- a/packages/core/src/widgets/select/SelectControl.tsx +++ b/packages/core/src/widgets/select/SelectControl.tsx @@ -112,6 +112,11 @@ const SelectControl: FC { + setOpen(open); + }, []); + return (