livebud / livebud/bud

new controller: scaffolding nested resources needs improvement

Open
#209 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

improvement needs decision
Dominant language
JavaScript
Stars
5.6k
Forks
175
PR merge metrics
No merged PRs in 30d

Description

The following command doesn't work yet:

bud new controller posts/comments index new

The problems are the following:

  1. Currently the generated view/posts/comments/index.svelte contains a missing comment variable:

    
    <script>
      export let comments = []
    </script>
    
    <h1>Comment Index</h1>
    
    <table border="1" cellpadding="10">
      {#if comments.length > 0}
        <thead>
          {#each Object.keys(comments[0]) as key}
            <th>{key}</th>
          {/each}
        </thead>
      {/if}
      {#each comments as comment}
        <tr>
          {#each Object.keys(comment) as key}
            {#if key.toLowerCase() === "id"}
              <td><a href={`/posts/${comment.post_id || 0}/comments/${comment.id || 0}`}>{comment[key]}</a></td>
            {:else}
              <td>{comment[key]}</td>
            {/if}
          {/each}
        </tr>
      {/each}
    </table>
    
    <br />
    
    <a href={`/posts/${comment.post_id || 0}/comments/new`}>New Comment</a>
    
    <style>
      table {
        border-collapse: collapse;
      }
    </style>
    

    Right now it's not clear how we should pass this through. Also open to other ideas like using the URL path instead.

  2. posts/comments/new.svelte has a similar problem. It generates a file that is missing comment variable. This variable isn't needed when the scaffolding is unnested.

    <h1>New Comment</h1>
    
    <form method="post" action={`/posts/${comment.post_id || 0}/comments`}>
      <!-- Add input fields here -->
      <input type="submit" value="Create Comment" />
    </form>
    
    <br />
    
    <a href={`/posts/${comment.post_id || 0}/comments`}>Back</a>
    

    In this case, just a bit more work needs to be done to conditionally introduce a script tag.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running bud new controller posts/comments index new and inspect the generated view/posts/comments/index.svelte and posts/comments/new.svelte. Compare nested output with unnested scaffolding, then make the generated links and form work without undefined variables and verify that the conditional script handling is correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
cli, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.