|
37 | 37 | * Nothing is written back and nothing is memoised across metadata versions, so |
38 | 38 | * a renamed target shows its new name on the next render (the ruling accepts a |
39 | 39 | * reload). A metadata label that is an inline locale map resolves through the |
40 | | - * spec's own `resolveI18nLabel` in the active language. An object's or view's |
41 | | - * result passes through the same convention-based bundle lookup |
42 | | - * (`useObjectLabel`) the rest of the console applies to their names; a served |
43 | | - * dashboard's label is already translated by the server and is drawn as given, |
44 | | - * as its page header draws it (objectstack#30244). Either way the nav shows the |
45 | | - * name the target's own page shows. |
| 40 | + * spec's own `resolveI18nLabel` in the active language. A served label is |
| 41 | + * already translated by the server, by its label order for an overridden item, |
| 42 | + * and is drawn as given: an object's (every object in the cache is a served |
| 43 | + * document), a served view's (`isServedView`, the question the object page's |
| 44 | + * view tabs ask) and a dashboard's (objectstack#30244, objectstack#30311). The |
| 45 | + * convention-based bundle lookup (`useObjectLabel`) is asked only for text no |
| 46 | + * server translated: a view the client derived, a pending draft's label, or a |
| 47 | + * target with no served label. Running the bundle over a served label was a |
| 48 | + * second translation pass in which the base package's string won a rename |
| 49 | + * back. |
46 | 50 | * |
47 | 51 | * A target with no label answers `undefined` — the renderer then falls through |
48 | 52 | * the spec's ladder and, at the bottom, to the target's machine name. |
@@ -74,6 +78,7 @@ import type { NavLabelTarget, NavTargetLabelResolver } from '@object-ui/layout'; |
74 | 78 | import { useMetadata } from '../providers/MetadataProvider.js'; |
75 | 79 | import { bundledFirst, useBundledReads } from '../providers/bundledReads.js'; |
76 | 80 | import { readObjectsByName, useReadItemsByName } from './useObjectPresence.js'; |
| 81 | +import { isServedView } from './useServedViewItems.js'; |
77 | 82 |
|
78 | 83 | /** |
79 | 84 | * A metadata label (plain string or inline locale map) as display text, or |
@@ -141,6 +146,41 @@ function listViewsOf(def: LabelledRecord | undefined): Record<string, LabelledRe |
141 | 146 | return views && typeof views === 'object' ? (views as Record<string, LabelledRecord | undefined>) : {}; |
142 | 147 | } |
143 | 148 |
|
| 149 | +/** One identity for an absent read. */ |
| 150 | +const NO_ITEMS: readonly unknown[] = Object.freeze([]); |
| 151 | + |
| 152 | +/** |
| 153 | + * What a `view` target reads (objectstack#30311): its object, with the views |
| 154 | + * merged in, and the two served reads `isServedView` asks of it — the |
| 155 | + * `/meta/view` documents and the object documents as served, before the merge. |
| 156 | + * By name, all three come from the one names-only scope read |
| 157 | + * `readObjectsByName` makes; otherwise from the whole lists, as |
| 158 | + * `useServedViewItems` reads them outside an app scope. |
| 159 | + */ |
| 160 | +function readViewTarget( |
| 161 | + metadata: ReturnType<typeof useMetadata>, |
| 162 | + byName: boolean, |
| 163 | + objectName: string, |
| 164 | +): { objects: readonly unknown[]; served: { views: readonly unknown[]; objects: readonly unknown[] } } { |
| 165 | + const { readObjectScope, getTypeStatus } = metadata; |
| 166 | + if (byName && readObjectScope && getTypeStatus?.('object') === 'idle' && objectName) { |
| 167 | + // `views` rides beside the published shape for this package's own readers. |
| 168 | + const scope = readObjectScope({ names: [objectName] }) as { objects: unknown[]; served?: unknown; views?: unknown }; |
| 169 | + return { |
| 170 | + objects: scope.objects, |
| 171 | + served: { |
| 172 | + views: Array.isArray(scope.views) ? scope.views : NO_ITEMS, |
| 173 | + objects: Array.isArray(scope.served) ? scope.served : NO_ITEMS, |
| 174 | + }, |
| 175 | + }; |
| 176 | + } |
| 177 | + const objects = byName ? readObjectsByName(metadata, [objectName], { views: true }) : metadata.objects; |
| 178 | + return { |
| 179 | + objects: objects ?? NO_ITEMS, |
| 180 | + served: { views: metadata.getItemsByType?.('view') ?? NO_ITEMS, objects: metadata.getItemsByType?.('object') ?? NO_ITEMS }, |
| 181 | + }; |
| 182 | +} |
| 183 | + |
144 | 184 | /** |
145 | 185 | * How the resolver reads an object (objectstack#29121). By default from the |
146 | 186 | * whole `objects` list, as the Studio's and the search page's callers do. With |
@@ -171,15 +211,24 @@ export function useNavTargetLabel(options?: NavTargetLabelOptions): NavTargetLab |
171 | 211 | case 'object': { |
172 | 212 | const objects = byName ? readObjectsByName(metadata, [target.objectName]) : metadata.objects; |
173 | 213 | const def = findByName(objects, target.objectName); |
174 | | - const text = |
175 | | - metadataText(def?.label, language) ?? draftText(drafts, 'object', target.objectName, language); |
176 | | - return nonEmpty(objectLabel({ name: target.objectName, label: text ?? '' })); |
| 214 | + // A served object's label is already translated (objectstack#30311): |
| 215 | + // drawn as given. A pending draft's label, which no server |
| 216 | + // translated, still goes through the bundle. |
| 217 | + return metadataText(def?.label, language) |
| 218 | + ?? nonEmpty(objectLabel({ |
| 219 | + name: target.objectName, |
| 220 | + label: draftText(drafts, 'object', target.objectName, language) ?? '', |
| 221 | + })); |
177 | 222 | } |
178 | 223 | case 'view': { |
179 | | - const objects = byName ? readObjectsByName(metadata, [target.objectName], { views: true }) : metadata.objects; |
| 224 | + const { objects, served } = readViewTarget(metadata, byName, target.objectName); |
180 | 225 | const views = listViewsOf(findByName(objects, target.objectName)); |
181 | 226 | const id = resolveViewId(target.viewName, Object.keys(views), target.objectName); |
182 | 227 | const text = metadataText(id ? views[id]?.label : undefined, language); |
| 228 | + // A served view's label is already translated (objectstack#30311), |
| 229 | + // as its tab on the object page draws it; a view the client derived |
| 230 | + // still goes through the bundle. |
| 231 | + if (text !== undefined && isServedView(served, target.objectName, id)) return text; |
183 | 232 | return nonEmpty(viewLabel(target.objectName, target.viewName, text ?? '')); |
184 | 233 | } |
185 | 234 | case 'dashboard': { |
|
0 commit comments