Skip to content

Commit

Permalink
Merge branch 'main' of github.com:alineacms/alinea
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Dec 2, 2024
2 parents c103aea + 0b545c2 commit b3ac023
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 23 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.5]
- Alinea will now fail if linked entries cannot be resolved during querying.
Before it would log the error but continue - but this is rarely desired.

## [1.0.4]
- Fix removing field contents in `Edit.update`. Pass an undefined value to remove
field contents:
Expand Down
37 changes: 20 additions & 17 deletions src/backend/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,23 +836,26 @@ export class Database implements Syncable {
if (noChanges) return

await Database.index(tx)
const isInserted = sql<boolean>`(${EntryRow.id}, ${coalesce(
EntryRow.locale,
sql`'null'`
)}, ${EntryRow.status}) in ${values(...inserted)}`
const entries = await tx.select().from(EntryRow).where(isInserted)
for (const entry of entries) {
const rowHash = await createRowHash(entry)
await tx
.update(EntryRow)
.set({
rowHash
})
.where(
eq(EntryRow.id, entry.id),
is(EntryRow.locale, entry.locale),
eq(EntryRow.status, entry.status)
)

if (inserted.length > 0) {
const isInserted = sql<boolean>`(${EntryRow.id}, ${coalesce(
EntryRow.locale,
sql`'null'`
)}, ${EntryRow.status}) in ${values(...inserted)}`
const entries = await tx.select().from(EntryRow).where(isInserted)
for (const entry of entries) {
const rowHash = await createRowHash(entry)
await tx
.update(EntryRow)
.set({
rowHash
})
.where(
eq(EntryRow.id, entry.id),
is(EntryRow.locale, entry.locale),
eq(EntryRow.status, entry.status)
)
}
}
await this.writeMeta(tx, commitHash)
})
Expand Down
4 changes: 2 additions & 2 deletions src/backend/resolver/LinkResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class LinkResolver {
function skipErrors(results: Array<any>) {
return results.map(result => {
if (result instanceof Error) {
console.error(result)
return undefined
Error.captureStackTrace(result)
throw result
}
return result
})
Expand Down
2 changes: 1 addition & 1 deletion src/core/shape/RichTextShape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ export class RichTextShape<Blocks>
iterMarks(doc, mark => {
if (mark[Mark.type] !== 'link') return
const entryId = mark[LinkMark.entry]
if (entryId) links.set(mark, entryId)
if (typeof entryId === 'string') links.set(mark, entryId)
})
async function loadLinks() {
const linkIds = Array.from(new Set(links.values()))
Expand Down
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 b3ac023

Please sign in to comment.