Skip to content

Refactor: use Schema.walk() in AdaptFrameworkImport.extractAssets instead of manual recursion #155

@taylortom

Description

@taylortom

AdaptFrameworkImport.extractAssets() manually recurses through schema properties and data to find Asset-type fields and remap their values via this.assetMap. This duplicates the traversal logic already provided by Schema.walk().

The call site already has a schema instance:

this.extractAssets(schema.built.properties, insertData)

Could be refactored to:

extractAssets (schema, data) {
  if (!schema) return
  const matches = schema.walk(data, field =>
    field?._backboneForms?.type === 'Asset' || field?._backboneForms === 'Asset'
  )
  matches.forEach(({ data: parent, key, value }) => {
    value !== '' ? parent[key] = this.assetMap[value] ?? value : delete parent[key]
  })
}

This eliminates the manual recursion and uses the shared schema walking infrastructure.

See also: adapt-security/adapt-authoring-courseassets#40 (same pattern for extractAssetIds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions