Skip to content

Conversation

@zamoore
Copy link
Contributor

@zamoore zamoore commented Apr 2, 2025

πŸ“Œ Summary

If merged, this PR allows for the usage of ember-data model instances as model data in the Advanced Table component.

πŸ› οΈ Detailed description

We use duck typing to avoid bringing in ember-data as a direct dependency.

export const isEmberDataModel = (
  item: HdsAdvancedTableModelItem
): item is import('@ember-data/model').default => {
  return (
    'constructor' in item &&
    typeof item.constructor === 'function' &&
    'modelName' in item.constructor &&
    typeof item.constructor.modelName === 'string' &&
    'serialize' in item &&
    typeof item.serialize === 'function'
  );
};

If the data is an ember-data model, we can extract its attributes during serialization into an HdsAdvancedTableTableModel.

if (isEmberDataModel(row)) {
  const attrs: Record<string, unknown> = {};
  const modelClass = row.constructor as typeof Model;

  modelClass.eachAttribute((key: string) => {
    attrs[key] = (row as Model).get(key);
  });

  attrs['id'] = row.id;

  rowData = attrs;
}

πŸ”— External links

Jira ticket: HDS-4749


πŸ‘€ Component checklist

πŸ’¬ Please consider using conventional comments when reviewing this PR.

@vercel
Copy link

vercel bot commented Apr 2, 2025

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
hds-showcase βœ… Ready (Inspect) Visit Preview Apr 2, 2025 7:14pm
hds-website βœ… Ready (Inspect) Visit Preview Apr 2, 2025 7:14pm

@hashibot-hds hashibot-hds added the docs-website Content updates to the documentation website label Apr 2, 2025
@zamoore zamoore changed the title Zamoore/hds 4749/advanced table/ember data support AdvancedTable - @model ember-data support Apr 2, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Apr 2, 2025

πŸ“¦ RC Packages Published

Latest commit: 9ac0b12

Published 1 packages

@hashicorp/design-system-components@4.19.0-rc-20250402205606

yarn up -C @hashicorp/design-system-components@rc

@zamoore
Copy link
Contributor Author

zamoore commented Apr 29, 2025

Not implementing this for now as we have varied ember-data support across all of our downstream apps. Consumers will need to convert ember-data records to plain js objects.

@zamoore zamoore closed this Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-website Content updates to the documentation website packages/components release-candidate Publishes release candidates to npm showcase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants