Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow Link and Array type references as variables #685

Open
wants to merge 11 commits into
base: development
Choose a base branch
from

Conversation

elylucas
Copy link
Member

@elylucas elylucas commented Jul 2, 2024

Purpose

This PR allows a dev to set up variables that can bind to lists (arrays) and entry references as such:

variables: {
  // bind to a string list
  listText: {
    displayName: 'List Text',
    type: 'Array',
  },
  // bind to an entry reference
  entryReference: {
    displayName: 'Entry Reference',
    type: 'Link',
  },
  // bind to a list of entries
  listReference: {
    displayName: 'List Entry Reference',
    type: 'Array',
  },
}

Copy link

vercel bot commented Jul 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
experience-builder-test-app ✅ Ready (Inspect) Visit Preview Jul 8, 2024 10:20pm

@elylucas elylucas changed the title fix: allow List and Link type references as variables fix: allow Link and Array type references as variables Jul 8, 2024
@elylucas elylucas marked this pull request as ready for review July 8, 2024 23:25
@elylucas elylucas requested review from a team as code owners July 8, 2024 23:25
Copy link
Contributor

@primeinteger primeinteger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this PR be marked as a feat instead? Great work on this one! 🚀

return entryOrAsset;
}

const arrayValue = get(entryOrAsset, path.split('/').slice(2, -1));
Copy link
Contributor

@primeinteger primeinteger Jul 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the type for arrayValue is being inferred as any here. It might be nice to add a type argument so TS can help catch type errors if this code is updated in the future.

Suggested change
const arrayValue = get(entryOrAsset, path.split('/').slice(2, -1));
const arrayValue = get<Array<string | UnresolvedLink<'Entry' | 'Asset'>>>(entryOrAsset, path.split('/').slice(2, -1));

const arrayValue = get(entryOrAsset, path.split('/').slice(2, -1));

if (!isArray(arrayValue)) {
console.warn(`Expected a value to an array, but got: ${JSON.stringify(arrayValue)}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.warn(`Expected a value to an array, but got: ${JSON.stringify(arrayValue)}`);
console.warn(`Expected a value to be an array, but got: ${JSON.stringify(arrayValue)}`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants