Skip to content

Commit 050fe68

Browse files
committed
Add types to documenation
1 parent 8e31580 commit 050fe68

File tree

3 files changed

+129
-20
lines changed

3 files changed

+129
-20
lines changed

src/browser/documentation/index.ts

Lines changed: 125 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,148 @@ import guideTypography from './guides/typography'
103103
import guideUnfound from './guides/unfound'
104104
import guideWritecode from './guides/write-code'
105105

106-
export default {
106+
type AllDocumentation = {
107+
help: HelpDocs
108+
cypher: CypherDocs
109+
bolt: BoltDocs
110+
play: GuideDocs
111+
}
112+
type GuideDocs = {
113+
title: 'Guides & Examples'
114+
chapters: Record<GuideChapter, DocItem>
115+
}
116+
117+
export type GuideChapter =
118+
| 'concepts'
119+
| 'cypher'
120+
| 'iconography'
121+
| 'intro'
122+
| 'learn'
123+
| 'movieGraph'
124+
| 'movies'
125+
| 'northwind'
126+
| 'northwindGraph'
127+
| 'start'
128+
| 'typography'
129+
| 'unfound'
130+
| 'writeCode'
131+
132+
type DocItem = {
133+
title: string
134+
subtitle?: string
135+
category?: string
136+
content?: JSX.Element | null
137+
footer?: JSX.Element
138+
slides?: JSX.Element[]
139+
}
140+
141+
type BoltDocs = { title: 'Bolt'; chapters: Record<BoltChapter, DocItem> }
142+
type BoltChapter = 'boltEncryption' | 'boltRouting'
143+
type CypherDocs = { title: 'Cypher'; chapters: Record<CypherChapter, DocItem> }
144+
type CypherChapter =
145+
| 'alterUser'
146+
| 'contains'
147+
| 'create'
148+
| 'createConstraintOn'
149+
| 'createDatabase'
150+
| 'createIndexOn'
151+
| 'createRole'
152+
| 'createUser'
153+
| 'delete'
154+
| 'deny'
155+
| 'detachDelete'
156+
| 'dropConstraintOn'
157+
| 'dropDatabase'
158+
| 'dropIndexOn'
159+
| 'dropRole'
160+
| 'dropUser'
161+
| 'endsWith'
162+
| 'explain'
163+
| 'foreach'
164+
| 'grant'
165+
| 'grantRole'
166+
| 'loadCsv'
167+
| 'match'
168+
| 'merge'
169+
| 'param'
170+
| 'params'
171+
| 'profile'
172+
| 'queryPlan'
173+
| 'remove'
174+
| 'rest'
175+
| 'restDelete'
176+
| 'restGet'
177+
| 'restPost'
178+
| 'restPut'
179+
| 'return'
180+
| 'revoke'
181+
| 'revokeRole'
182+
| 'schema'
183+
| 'set'
184+
| 'showDatabases'
185+
| 'showPrivileges'
186+
| 'showRoles'
187+
| 'showUsers'
188+
| 'startsWith'
189+
| 'template'
190+
| 'unwind'
191+
| 'where'
192+
| 'with'
193+
194+
type HelpDocs = { title: 'Commands'; chapters: Record<HelpChapter, DocItem> }
195+
type HelpChapter =
196+
| 'auto'
197+
| 'bolt'
198+
| 'clear'
199+
| 'commands'
200+
| 'cypher'
201+
| 'guides'
202+
| 'help'
203+
| 'history'
204+
| 'historyClear'
205+
| 'keys'
206+
| 'play'
207+
| 'queries'
208+
| 'server'
209+
| 'serverUser'
210+
| 'style'
211+
| 'unfound'
212+
| 'unknown'
213+
214+
const docs: AllDocumentation = {
107215
help: {
108216
title: 'Commands',
109217
chapters: {
110218
auto: helpAuto,
111-
clear: helpClear,
112-
cypher: helpCypher,
113219
bolt: helpBolt,
220+
clear: helpClear,
114221
commands: helpCommands,
222+
cypher: helpCypher,
115223
guides: helpPlay,
116224
help: helpHelp,
117225
history: helpHistory,
118226
historyClear: helpHistoryClear,
119227
keys: helpKeys,
120228
play: helpPlay,
229+
queries: helpQueries,
121230
server: helpServer,
122231
serverUser: helpServerUser,
123232
style: helpStyle,
124233
unfound: helpUnfound,
125-
unknown: helpUnknown,
126-
queries: helpQueries
234+
unknown: helpUnknown
127235
}
128236
},
129237
cypher: {
130238
title: 'Cypher',
131239
chapters: {
132240
alterUser: helpAlterUser,
133241
contains: helpContains,
242+
create: helpCreate,
134243
createConstraintOn: helpCreateConstraintOn,
135244
createDatabase: helpCreateDatabase,
136245
createIndexOn: helpCreateIndexOn,
137246
createRole: helpCreateRole,
138247
createUser: helpCreateUser,
139-
create: helpCreate,
140248
delete: helpDelete,
141249
deny: helpDeny,
142250
detachDelete: helpDetachDelete,
@@ -191,22 +299,24 @@ export default {
191299
chapters: {
192300
concepts: guideConcepts,
193301
cypher: guideCypher,
302+
iconography: guideIconography,
194303
intro: guideIntro,
195304
learn: guideLearn,
196305
movieGraph: guideMovieGraph,
197306
movies: guideMovieGraph,
198-
northwindGraph: guideNorthwindGraph,
199307
northwind: guideNorthwindGraph,
200-
iconography: guideIconography,
308+
northwindGraph: guideNorthwindGraph,
201309
start: guideStart,
202310
typography: guideTypography,
203311
unfound: guideUnfound,
204-
writeCode: guideWritecode,
205-
// Commands only
206-
'query-template': {
207-
title: 'Query Templates',
208-
category: 'guides'
209-
}
210-
} as any
312+
writeCode: guideWritecode
313+
}
211314
}
212315
}
316+
317+
// TypeGuard function to ts to understand that a string is a valid key
318+
export function isGuideChapter(name: string): name is GuideChapter {
319+
return name in docs.play.chapters
320+
}
321+
322+
export default docs

src/browser/modules/Stream/PlayFrame.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { withBus } from 'react-suber'
2323
import { fetchGuideFromAllowlistAction } from 'shared/modules/commands/commandsDuck'
2424

2525
import Docs from '../Docs/Docs'
26-
import docs from '../../documentation'
26+
import docs, { isGuideChapter } from '../../documentation'
2727
import FrameTemplate from '../Frame/FrameTemplate'
2828
import FrameAside from '../Frame/FrameAside'
2929
import {
@@ -239,10 +239,9 @@ function generateContent(
239239
stackFrame.cmd.trim() === ':play' ? ':play start' : stackFrame.cmd
240240
)
241241

242-
const guide = chapters[guideName] || {}
243242
// Check if content exists locally
244-
if (Object.keys(guide).length) {
245-
const { content, title, subtitle, slides = null } = guide
243+
if (isGuideChapter(guideName)) {
244+
const { content, title, subtitle, slides = null } = chapters[guideName]
246245
return {
247246
guide: (
248247
<Docs

src/shared/services/commandUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const camelToSnake = (name: any, separator: any) => {
103103
.toLowerCase()
104104
}
105105

106-
export const transformCommandToHelpTopic = (inputStr: any) =>
106+
export const transformCommandToHelpTopic = (inputStr?: string): string =>
107107
[inputStr || '']
108108
.map(stripPound)
109109
.map(getHelpTopic)

0 commit comments

Comments
 (0)