Skip to content

Commit

Permalink
Avoid crash on empty query block ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Dec 2, 2024
1 parent a6378fa commit 19ba63b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 20 deletions.
2 changes: 0 additions & 2 deletions frontend/apps/desktop/src/components/site-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,10 @@ export function SiteNavigationLoader({onPress}: {onPress?: () => void}) {
const capability = useMyCapability(id)
const siteList = useListSite(id)

console.log(`== ~ SiteNavigationLoader ~ siteList:`, siteList)
const siteListQuery = siteList?.data
? {in: hmId('d', id.uid), results: siteList.data}
: null

console.log(`== ~ SiteNavigationLoader ~ siteListQuery:`, siteListQuery)
const embeds = useDocumentEmbeds(document)

let createDirItem: null | ((opts: {indented: number}) => ReactNode) = null
Expand Down
12 changes: 0 additions & 12 deletions frontend/apps/desktop/src/models/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,6 @@ export function usePublishDraft(

const deleteChanges = extractDeletes(blocksMap, changes.touchedBlocks)

console.log(`== ~ mutationFn: ~ changes:`, {
blocksMap,
content,
deleteChanges,
changes,
})
// return null
if (accts.data?.length == 0) {
dispatchWizardEvent(true)
Expand Down Expand Up @@ -574,17 +568,12 @@ export function useDraftEditor({id}: {id?: UnpackedHypermediaId}) {
const blocksMap2 = createBlocksMap(newEntity.document?.content || [], '')
const editorContent = removeTrailingBlocks(editor.topLevelBlocks)

console.log(`editorContent:`, editorContent)
const changes = compareBlocksWithMap(blocksMap1, editorContent, '')
const changes2 = compareDraftWithMap(
blocksMap1,
newEntity.document?.content,
'',
)
console.log('blocksMap1', blocksMap1)
console.log('blocksMap2', blocksMap2)
console.log('changes', changes)
console.log('changes2', changes2)

changes2.touchedBlocks.forEach((blockId) => {
const blockContent = blocksMap2[blockId]
Expand Down Expand Up @@ -1314,7 +1303,6 @@ function findDifferences(obj1, obj2) {
function removeTrailingBlocks(
blocks: Array<EditorBlock<typeof hmBlockSchema>>,
) {
console.log(`== ~ blocks:`, blocks)
let trailedBlocks = [...blocks]
while (true) {
let lastBlock = trailedBlocks[trailedBlocks.length - 1]
Expand Down
1 change: 0 additions & 1 deletion frontend/apps/desktop/src/pages/document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ function _MainDocumentPage({
}, [])
const entity = useSubscribedEntity(id)

console.log(`== ~ entity:`, entity)
const siteHomeEntity = useSubscribedEntity(hmId('d', id.uid))

if (entity.isInitialLoading) return <Spinner />
Expand Down
3 changes: 2 additions & 1 deletion frontend/apps/web/app/web-embeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ export function QueryBlockWeb({
// const query
const {supportQueries, supportDocuments} = ctx || {};
const includes = block.attributes.query.includes || [];

if (includes.length == 0) return null;
const queryInclude = includes[0];
if (!queryInclude || includes.length !== 1)
return (
<ErrorBlock message="Only one QueryBlock.attributes.query.includes is supported for now" />
);
if (!queryInclude.space) return <ErrorBlock message="Empty Query" />;

const queryResults = supportQueries?.find((q) => {
if (q.in.uid !== queryInclude.space) return false;
Expand Down
11 changes: 7 additions & 4 deletions frontend/packages/ui/src/document-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1769,10 +1769,13 @@ export function BlockContentQuery({block}: {block: HMBlockQuery}) {
throw new Error("BlockContentQuery requires a Query block type");

const query = block.attributes.query;
const id = hmId("d", query.includes[0].space, {
path: query.includes[0].path ? query.includes[0].path.split("/") : null,
latest: true,
});
const id =
query.includes[0].space &&
hmId("d", query.includes[0].space, {
path: query.includes[0].path ? query.includes[0].path.split("/") : null,
latest: true,
});
if (!id) return <ErrorBlock message="Empty Query" />;
return <EntityTypes.Query block={block} id={id} />;
// let docs = items?.filter((item) => !!item.data) || [];
// if (docs.length) {
Expand Down

0 comments on commit 19ba63b

Please sign in to comment.