Repository navigation
Conversation
…a unit that has never been saved A unit's metadata gets its authors when the unit is first saved. Opening Advanced Settings on a unit that has just been created and not yet saved makes ngOnInit() call some() on undefined authors, which throws "Cannot read properties of undefined (reading 'some')". A unit without authors is now treated as not the user's unit without throwing, so the Publish Unit link stays hidden until the first save, as it already was.
hirokiterashima
left a comment
There was a problem hiding this comment.
When a new project is created in AddProjectComponent, we call registerProjectService.register() with the project that doesn't include the author in the metadata. Can we add the author field then, so that we don't need to do this check in this component?
|
Thanks, that makes sense. That would cover units created from now on. Units that already exist without Would you prefer to add the author at creation and keep the optional chaining for those existing units, or add the author at creation and drop the check? I'm happy to update the PR either way. |
Opening Advanced Settings for a unit that has just been created and not yet saved logs
TypeError: Cannot read properties of undefined (reading 'some')in the console. Since the Unit Info page was reorganised into tabs (#2304),AdvancedProjectAuthoringComponent.ngOnInit()decides whether to show the Publish Unit link withthis.metadata.authors.some(...), but a unit's metadata getsauthorsonly when the unit is first saved.The exception is raised from
ngOnInit(), soisMyUnitis never assigned. The page still renders, and once the unit has been saved the error no longer occurs.Changes
authorsis treated as not the user's unit without throwing. The Publish Unit link stays hidden until the first save, as it already was.Test
advanced-project-authoring.component.spec.tswith three cases: a unit that has never been saved, a unit the user authored, and a unit someone else authored. Against the currentdevelopthe first fails withTypeError: Cannot read properties of undefined (reading 'some').authoringToolpass (143).