Skip to content

Commit

Permalink
feat(journal): inline journal view
Browse files Browse the repository at this point in the history
  • Loading branch information
TheExGenesis committed Jan 16, 2022
1 parent 5f6063f commit 97ad9f7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/unigraph-dev-explorer/src/examples/notes/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
registerQuickAdder,
} from '../../unigraph-react';
import { NoteBlock, DetailedNoteBlock } from './NoteBlock';
import { noteQuery, noteQueryDetailed, journalQueryDetailed } from './noteQuery';
import { noteQuery, noteQueryDetailed, journalQuery, journalQueryDetailed } from './noteQuery';

export const init = () => {
registerDynamicViews({
Expand All @@ -21,6 +21,12 @@ export const init = () => {
query: noteQueryDetailed,
},
});
registerDynamicViews({
'$/schema/journal': {
view: ({ data }: { data: any }) => NoteBlock({ data: new UnigraphObject(data._value.note._value) }),
query: journalQuery,
},
});
registerDetailedDynamicViews({
'$/schema/journal': {
view: (props: any) => (
Expand Down
18 changes: 16 additions & 2 deletions packages/unigraph-dev-explorer/src/examples/notes/noteQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const MAX_DEPTH = 8;
const getQuery: (depth: number) => string = (depth: number) => {
if (depth >= 8) return '{ uid _hide type {<unigraph.id>} }';
if (depth >= MAX_DEPTH) return '{ uid _hide type {<unigraph.id>} }';
return `{
_updatedAt
uid
Expand Down Expand Up @@ -64,4 +65,17 @@ export const journalQueryDetailed = (uid: string, depth = 0) => `(func: uid(${ui
}
}`;

export const noteQuery = (uid: string) => `(func: uid(${uid})) ${getQuery(7)}`;
export const noteQuery = (uid: string) => `(func: uid(${uid})) ${getQuery(MAX_DEPTH - 1)}`;
export const journalQuery = (uid: string) => `(func: uid(${uid})) {
_updatedAt
uid
_hide
type {
<unigraph.id>
}
_value {
note {
_value ${getQuery(MAX_DEPTH - 1)}
}
}
}`;

0 comments on commit 97ad9f7

Please sign in to comment.