Skip to content

Commit

Permalink
Add the pickChildren option to link fields
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 29, 2024
1 parent ad18b2e commit f1d69db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/field/link/EntryLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export function entry<Fields = undefined>(
pickers: {
entry: entryPicker({
...options,
withNavigation: Boolean(options.location || !options.condition),
withNavigation: Boolean(
options.location || (!options.condition && !options.pickChildren)
),
title: 'Select a page',
max: 1,
selection: EntryLink
Expand All @@ -73,7 +75,9 @@ export namespace entry {
pickers: {
entry: entryPicker<EntryReference, Fields>({
...options,
withNavigation: !options.condition,
withNavigation: Boolean(
options.location || (!options.condition && !options.pickChildren)
),
title: 'Select a page',
selection: EntryLink
})
Expand Down
6 changes: 5 additions & 1 deletion src/picker/entry/EntryPicker.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Workspace} from 'alinea/core/Workspace'
import {workspaceMediaDir} from 'alinea/core/util/EntryFilenames'
import {entries} from 'alinea/core/util/Objects'
import {useConfig} from 'alinea/dashboard/hook/UseConfig'
import {useEntryEditor} from 'alinea/dashboard/hook/UseEntryEditor'
import {useFocusList} from 'alinea/dashboard/hook/UseFocusList'
import {useGraph} from 'alinea/dashboard/hook/UseGraph'
import {useLocale} from 'alinea/dashboard/hook/UseLocale'
Expand Down Expand Up @@ -68,11 +69,13 @@ export function EntryPickerModal({
}: EntryPickerModalProps) {
const config = useConfig()
const graph = useGraph()
const editor = useEntryEditor()
const {
title,
defaultView,
location,
max,
pickChildren,
condition,
withNavigation = true,
showMedia
Expand All @@ -89,6 +92,7 @@ export function EntryPickerModal({
const locale = useLocale()
const [destination, setDestination] = useState<PickerLocation>({
workspace: currentWorkspace,
parentId: pickChildren ? editor?.entryId : undefined,
root: showMedia
? Workspace.defaultMediaRoot(config.workspaces[currentWorkspace])
: currentRoot,
Expand Down Expand Up @@ -137,7 +141,7 @@ export function EntryPickerModal({
)
const query = useMemo((): QueryWithResult<ExporerItemSelect> => {
const terms = search.replace(/,/g, ' ').split(' ').filter(Boolean)
if (!withNavigation && condition) {
if (!withNavigation && condition && !pickChildren) {
return {
select: Entry,
search: terms,
Expand Down
4 changes: 4 additions & 0 deletions src/picker/entry/EntryPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import {EntryReference} from './EntryReference.js'
export interface EntryPickerOptions<Definition = {}> {
selection: Projection
defaultView?: 'row' | 'thumb'
/** Show entries from a specific workspace/root */
location?: {workspace: string; root: string}
/** Choose from direct children of the currently edited entry */
pickChildren?: boolean
/** Filter entries by a condition */
condition?: Filter<EntryFields & Entry>
withNavigation?: boolean
showMedia?: boolean
Expand Down

0 comments on commit f1d69db

Please sign in to comment.