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

Can autogenerate spec or containedExamples from playground #2322

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

burieberry
Copy link
Contributor

@burieberry burieberry commented Mar 21, 2025

This is for fields only:

  • If there's a spec for field but it has no containedExamples, then on opening playground panel, autogenerate a field instance and add to containedExamples.
  • If there's no pre-existing spec for field, on opening playground panel, autogenerate a Spec instance and then add a field instance to containedExamples.

Review needed: See my comments below in using a search resource and a modifier to check if spec exists and to auto-generate it if it doesn't.

Copy link

github-actions bot commented Mar 21, 2025

Host Test Results

  1 files  ±0    1 suites  ±0   27m 9s ⏱️ +55s
838 tests ±0  833 ✅ ±0  5 💤 ±0  0 ❌ ±0 
845 runs  ±0  840 ✅ ±0  5 💤 ±0  0 ❌ ±0 

Results for commit 655392e. ± Comparison against base commit 73e7266.

This pull request removes 2 and adds 2 tests. Note that renamed tests count towards both.
Chrome 134.0 ‑ Acceptance | code-submode | field playground: can create new field instance (no preexisting Spec)
Chrome 134.0 ‑ Acceptance | code-submode | field playground: can create new field instance when spec exists but has no examples
Chrome 134.0 ‑ Acceptance | code-submode | field playground: can autogenerate new Spec and field instance (no preexisting Spec)
Chrome 134.0 ‑ Acceptance | code-submode | field playground: can autogenerate new field instance when spec exists but has no examples

♻️ This comment has been updated with latest results.

});

private createNewField = task(async (specCard: Spec) => {
private createNewField = restartableTask(async (specCard: Spec) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is now a restartableTask because fieldInstances getter is called twice and this task starts running if there are no instances

Comment on lines +135 to +137
{{else if this.canGenerateFieldSpec}}
<div {{runFn this.createNew}} />
{{/if}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

a little awkward. using a modifier to kickstart createNew if conditions have been met

Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be conditionally initiated in the constructor instead?

Comment on lines +204 to +232
private get specQuery(): Query {
return {
filter: {
on: specRef,
eq: { ref: this.args.codeRef },
},
};
}

private searchFieldSpec = getSearch(
this,
() => this.specQuery,
() => this.realmServer.availableRealmURLs,
{ isLive: true, isAutoSaved: true },
);

private get canGenerateFieldSpec() {
if (
!this.args.isFieldDef ||
!this.canWriteRealm ||
this.createNewCard.isRunning
) {
return false;
}
return (
!this.searchFieldSpec.isLoading &&
this.searchFieldSpec.instances?.length === 0
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this checks if there's a preexisting spec as well as other conditions for running createNew to autogenerate a new spec

@burieberry burieberry marked this pull request as ready for review March 24, 2025 19:44
@burieberry burieberry requested a review from a team March 24, 2025 19:54
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.

2 participants