@@ -7,9 +7,10 @@ import { appEnvTitleTag } from "~/utils";
77 * is; the app title is added here.
88 *
99 * Shape (leading words carry the information, so a narrow tab still reads):
10- * page: `Runs | Trigger.dev`
11- * entity: `run_abc | Runs | Trigger.dev`
12- * else: `Login to Trigger.dev` etc.
10+ * env page: `Runs | Trigger.dev`
11+ * env entity: `run_abc | Runs | Trigger.dev`
12+ * org page: `Team | Acme | Trigger.dev`
13+ * else: `Login to Trigger.dev` etc.
1314 *
1415 * Remix v2 picks the meta of the deepest route that exports one; a route without a meta export
1516 * inherits its nearest ancestor's. So a layout's `pageMeta` is the fallback for children that
@@ -19,6 +20,9 @@ import { appEnvTitleTag } from "~/utils";
1920
2021const APP_NAME = "Trigger.dev" ;
2122
23+ /** The org route carries the organization the URL resolved to. */
24+ const ORGANIZATION_MATCH_ID = "routes/_app.orgs.$organizationSlug" ;
25+
2226/** One or more title segments, most specific first: `["run_abc", "Runs"]`. */
2327export type TitleSegments = string | string [ ] ;
2428
@@ -52,13 +56,24 @@ export function pageMeta<TLoader = unknown>(page: PageInput<TLoader>): MetaFunct
5256 } ;
5357}
5458
55- /** Builds the full title from the page segments plus the app title. */
59+ /** Builds the full title from the page segments, the org scope and the app title. */
5660export function composePageTitle ( segments : string [ ] , matches : Matches ) : string {
57- return [ ...segments , appTitle ( appEnvFromMatches ( matches ) ) ]
61+ return [ ...segments , scopeFromMatches ( matches ) , appTitle ( appEnvFromMatches ( matches ) ) ]
5862 . filter ( ( segment ) : segment is string => Boolean ( segment ) )
5963 . join ( " | " ) ;
6064}
6165
66+ /**
67+ * The organization, and only on its own pages: inside a project the tab is already about one
68+ * project, and the dashboard switches projects in every tab at once, so naming it adds nothing.
69+ */
70+ export function scopeFromMatches ( matches : Matches ) : string | undefined {
71+ const match = matches . find ( ( m ) => m . id === ORGANIZATION_MATCH_ID ) ;
72+ if ( ! match || match . params ?. projectParam ) return undefined ;
73+ const data = match . data as { organization ?: { title ?: string | null } } | undefined ;
74+ return data ?. organization ?. title ?? undefined ;
75+ }
76+
6277function appEnvFromMatches ( matches : Matches ) : string | undefined {
6378 const rootData = matches [ 0 ] ?. data as { appEnv ?: string } | undefined ;
6479 return rootData ?. appEnv ;
0 commit comments