-
Notifications
You must be signed in to change notification settings - Fork 191
Feat: multi-terminology support #2413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ItzNotABug
wants to merge
52
commits into
8.x
Choose a base branch
from
multiple-terminologies
base: 8.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 47 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
f6f2d94
feat: multi-terminology support [wip].
ItzNotABug 3fae9d6
update: restructure dirs.
ItzNotABug bc16dea
update: abstracted indexes for base views.
ItzNotABug cd5c781
remove: duplicate components.
ItzNotABug e451f18
Merge branch 'index-suggestions' into 'multiple-terminologies'.
ItzNotABug a3eb1c8
fix: import.
ItzNotABug 5eca86e
update: imports and folder structure.
ItzNotABug aca5241
lint.
ItzNotABug 88a153e
Merge branch 'main' into multiple-terminologies
ItzNotABug d00e280
misc: changes, docs update, svelte5 migration.
ItzNotABug 7410780
Merge branch 'main' into 'multiple-terminologies'.
ItzNotABug 8f5f4c1
simplify.
ItzNotABug 645ae62
update: migrate empty sheet as a reusable component.
ItzNotABug 6cecb2c
lint.
ItzNotABug 4354c90
update: misc, address a todo.
ItzNotABug e87894d
update: make breadcrumbs and header reusable.
ItzNotABug ef7d6d4
update: improved context and terminology sharing.
ItzNotABug d2c2870
lint.
ItzNotABug d5afa9b
remove: leftover log
ItzNotABug 466cc8d
address: todo.
ItzNotABug 31aa0ff
address: todo for `trackError`.
ItzNotABug e1aa598
fixes, stricter params.
ItzNotABug 74e6eae
fixes, stricter params.
ItzNotABug e06980a
fix: `getContext` undefined issue.
ItzNotABug 95bbe56
update: resizing on indexes.
ItzNotABug 4288215
fix: accessor.
ItzNotABug a871810
fix: slash issues on routes causing flawed selection on tabs.
ItzNotABug 470a4e1
Merge branch 'main' into 'multiple-terminologies'.
ItzNotABug 7d7dfab
use: `creatingEntity`.
ItzNotABug fc78c44
remove: legacy logic.
ItzNotABug 6fef9a2
update: proper type.
ItzNotABug 4ef68a4
update: migrate.
ItzNotABug 2ce3811
remove: database derived store.
ItzNotABug db8420d
address comments, fix nav bug.
ItzNotABug aea5e82
misc.
ItzNotABug 2abb2bc
address comment with hardcoded paths for `nonSheetPages` checks.
ItzNotABug 9d1f4ce
misc: fixes.
ItzNotABug ea665d7
misc: fixes.
ItzNotABug 8a449d5
update: moreee changes!
ItzNotABug 43eff98
feat: wrapped sdk support.
ItzNotABug e97ef6c
bump: sdk for `DocumentsDB`.
ItzNotABug f0d1a5d
update: sdks side updates.
ItzNotABug f49f888
update: sdks side updates.
ItzNotABug 1f254a6
address comments.
ItzNotABug 604f0ab
Merge branch 'main' into multiple-terminologies
ItzNotABug d53c8ef
fix: add fallback.
ItzNotABug ae9aa07
fix: infy-loop
ItzNotABug 0e7938a
fix: `$derived` overuse.
ItzNotABug 222eb9a
fix: relationships.
ItzNotABug 7c4c256
address: pending todo.
ItzNotABug 83a8870
address rabbits comment.
ItzNotABug f1712be
address rabbits comment.
ItzNotABug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { resolve } from '$app/paths'; | ||
import { goto } from '$app/navigation'; | ||
import type { Pathname, RouteId, RouteParams } from '$app/types'; | ||
|
||
// taken directly from svelte's source! | ||
type ResolveArgs<T extends RouteId | Pathname> = T extends RouteId | ||
? RouteParams<T> extends Record<string, never> | ||
? [route: T] | ||
: [route: T, params: RouteParams<T>] | ||
: [route: T]; | ||
|
||
export function withPath(base: string, ...parts: string[]) { | ||
// remove slashes at the end if any | ||
const normalizedBase = base.replace(/\/+$/, ''); | ||
|
||
// remove slashes at the start of each part if any | ||
const normalizedParts = parts.map((part) => part.replace(/^\/+/, '')); | ||
|
||
// join em with slashes | ||
return [normalizedBase, ...normalizedParts].join('/'); | ||
} | ||
|
||
export function resolveRoute<T extends RouteId>(route: T, params?: Record<string, string>) { | ||
// type cast is necessary here! | ||
const resolveArgs = params ? ([route, params] as [T, RouteParams<T>]) : [route]; | ||
|
||
return resolve(...(resolveArgs as ResolveArgs<T>)); | ||
} | ||
ItzNotABug marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export function navigate<T extends RouteId>( | ||
route: T, | ||
params?: Record<string, string> | ||
): Promise<void> { | ||
// type cast is necessary here! | ||
return goto(resolveRoute(route, params)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...e)/project-[region]-[project]/databases/database-[database]/(entity)/helpers/analytics.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { Page } from '@sveltejs/kit'; | ||
|
||
import { useTerminology } from './terminology'; | ||
import { Submit, Click } from '$lib/actions/analytics'; | ||
import type { AnalyticsResult, TerminologyResult, TerminologyShape } from './types'; | ||
|
||
export function useAnalytics(pageOrTerms: Page | TerminologyResult): AnalyticsResult { | ||
// source is in `TerminologyResult`. | ||
const terminology = 'source' in pageOrTerms ? pageOrTerms : useTerminology(pageOrTerms); | ||
|
||
const createSubmitHandler = <TAction extends string>(termType: keyof TerminologyShape) => { | ||
return (action: TAction) => { | ||
const term = terminology.source[termType]; | ||
if (!term) { | ||
throw new Error(`No ${termType} terminology found`); | ||
} | ||
const enumKey = `${term.title.singular}${action}`; | ||
return Submit[enumKey as keyof typeof Submit]; | ||
abnegate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
}; | ||
|
||
const createClickHandler = <TAction extends string>(termType: keyof TerminologyShape) => { | ||
return (action: TAction) => { | ||
const term = terminology.source[termType]; | ||
if (!term) { | ||
throw new Error(`No ${termType} terminology found`); | ||
} | ||
const enumKey = `Database${term.title.singular}${action}`; | ||
return Click[enumKey as keyof typeof Click]; | ||
abnegate marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
}; | ||
|
||
const result: AnalyticsResult = { submit: {}, click: {} }; | ||
|
||
if (terminology.entity) { | ||
result.click.entity = createClickHandler('entity'); | ||
result.submit.entity = createSubmitHandler('entity'); | ||
} | ||
|
||
if (terminology.field) { | ||
result.click.field = createClickHandler('field'); | ||
result.submit.field = createSubmitHandler('field'); | ||
} | ||
|
||
if (terminology.record) { | ||
result.click.record = createClickHandler('record'); | ||
result.submit.record = createSubmitHandler('record'); | ||
} | ||
|
||
return result; | ||
} |
21 changes: 21 additions & 0 deletions
21
...project-[region]-[project]/databases/database-[database]/(entity)/helpers/dependencies.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Page } from '@sveltejs/kit'; | ||
|
||
import { useTerminology } from './terminology'; | ||
import { Dependencies } from '$lib/constants'; | ||
import type { DependenciesResult, Term, TerminologyResult } from './types'; | ||
|
||
export function useDependencies(pageOrTerms: Page | TerminologyResult): DependenciesResult { | ||
// source is in `TerminologyResult`. | ||
const terminology = 'source' in pageOrTerms ? pageOrTerms : useTerminology(pageOrTerms); | ||
|
||
const getDependencies = (term: { title: Term }) => ({ | ||
singular: Dependencies[term.title.singular.toUpperCase() as keyof typeof Dependencies], | ||
plural: Dependencies[term.title.plural.toUpperCase() as keyof typeof Dependencies] | ||
}); | ||
|
||
return { | ||
entity: terminology.entity ? getDependencies(terminology.entity) : undefined, | ||
field: terminology.field ? getDependencies(terminology.field) : undefined, | ||
record: terminology.record ? getDependencies(terminology.record) : undefined | ||
}; | ||
} |
6 changes: 6 additions & 0 deletions
6
...nsole)/project-[region]-[project]/databases/database-[database]/(entity)/helpers/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './sdk'; | ||
export * from './init'; | ||
export * from './types'; | ||
export * from './analytics'; | ||
export * from './terminology'; | ||
export * from './dependencies'; |
39 changes: 39 additions & 0 deletions
39
...onsole)/project-[region]-[project]/databases/database-[database]/(entity)/helpers/init.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { Page } from '@sveltejs/kit'; | ||
import { getContext, setContext } from 'svelte'; | ||
import { | ||
type AnalyticsResult, | ||
type DatabaseSdkResult, | ||
type DependenciesResult, | ||
type TerminologyResult, | ||
useAnalytics, | ||
useDependencies, | ||
useTerminology, | ||
useDatabasesSdk | ||
} from '$database/(entity)'; | ||
|
||
const TERMINOLOGIES_KEY = Symbol('terminologies'); | ||
|
||
export type Terminologies = { | ||
analytics: AnalyticsResult; | ||
terminology: TerminologyResult; | ||
dependencies: DependenciesResult; | ||
databaseSdk: DatabaseSdkResult; | ||
}; | ||
|
||
export function getTerminologies(): Terminologies { | ||
return getContext<Terminologies>(TERMINOLOGIES_KEY); | ||
} | ||
|
||
export function setTerminologies(page: Page) { | ||
setContext(TERMINOLOGIES_KEY, buildTerminologies(page)); | ||
} | ||
|
||
function buildTerminologies(page: Page) { | ||
const terminology = useTerminology(page); | ||
return { | ||
terminology, | ||
analytics: useAnalytics(terminology), | ||
dependencies: useDependencies(terminology), | ||
databaseSdk: useDatabasesSdk(page, terminology) | ||
}; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.