Skip to content

Commit

Permalink
Fix creating new entries without parent
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 28, 2023
1 parent 6c10590 commit f4ab065
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [Unreleased]

- A type check before creating new entries was incorrect making it impossible
create new entries on the root level.

## [0.4.0]

- This release contains a major rewrite. Read the blog post for more information.
Expand Down
11 changes: 6 additions & 5 deletions src/dashboard/view/entry/NewEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ function NewEntryForm({parentId}: NewEntryProps) {
{suspense: true, keepPreviousData: true, staleTime: 0}
)
const parentPaths = parent ? parent.parentPaths.concat(parent.path) : []
const type = parent && config.schema[parent.type]
const parentType = parent && config.schema[parent.type]
const types: Array<string> = !parent
? root.contains || []
: (type && Type.meta(type).contains) || keys(config.schema)
: (parentType && Type.meta(parentType).contains) || keys(config.schema)
const selectedType = useField(
select(
'Select type',
Expand All @@ -124,7 +124,7 @@ function NewEntryForm({parentId}: NewEntryProps) {
),
{initialValue: types[0]}
),
[type]
[parentType]
)
const titleField = useField(text('Title', {autoFocus: true}))
const [isCreating, setIsCreating] = useState(false)
Expand All @@ -134,7 +134,7 @@ function NewEntryForm({parentId}: NewEntryProps) {
e.preventDefault()
const title = titleField()
const selected = selectedType()
if (!selected || !title || !type) return
if (!selected || !title) return
setIsCreating(true)
const path = slugify(title)
const entryId = createId()
Expand All @@ -148,7 +148,8 @@ function NewEntryForm({parentId}: NewEntryProps) {
const filePath = entryFilepath(config, data, parentPaths)
const childrenDir = entryChildrenDir(config, data, parentPaths)
const parentDir = dirname(filePath)
const url = entryUrl(type, {...data, parentPaths})
const entryType = config.schema[selected]!
const url = entryUrl(entryType, {...data, parentPaths})
const entry = await createEntryRow(config, {
entryId,
...data,
Expand Down

0 comments on commit f4ab065

Please sign in to comment.