opral / inlang-message-ui-components

Issue tracker for UI components
0 stars 0 forks source link

bundle component has redundant complexity due to legacy `BundleNested` #114

Closed samuelstroschein closed 2 weeks ago

samuelstroschein commented 1 month ago

Context

We eventually need unbundled editing components to unblock diffing components, slotting, and more complex application UIs.

A reason against unbundling is the amount of business logic the component does at the moment. I looked into the component and found:

Optimierung der Logik in Unbundled Components

Proposal

Unbundle the components and offer an opinionated wrapper "starter" component for apps.


// opinionated editor with bundle nested (?) for ease of wiring
<inlang-editor .bundleNested={} @change={}></inlang-editor>

// headless building blocks for a custom editor or diff components
<inlang-bundle-editor .bundle={} @change={}></inlang-bundle-editor>
<inlang-message-editor .message={} @change={}></inlang-message-editor>
<inlang-variant-editor .variant={} @change={}></inlang-variant-editor>

Additional information

Here is the API I came up with in the loom.

function handleChange(value, type) {
  if (value === undefined){
    await project.db.delete(type).where({id: value.id}).execute();
  } else {  
    await project.db.insert(type)
      .values(value)
      .onConflict((oc) => oc
        .column('id')
        .doUpdateSet(value))
      .execute();
  }
}
return html`
  <inlang-bundle-editor 
     .bundle=${bundle} 
     @change=${(value) => handleChange(value, "bundle")}>
    ${bundle.messages.map((message) => {
      return html`
        <inlang-message-editor 
          .message=${message} 
          @change=${(value) => handleChange(value, 'message')}
          .settings=${project.settings.get()}
        >
          ${message.variants.map((variant) => {
            return html`
              <inlang-variant-editor 
                .variant=${variant} 
                @change=${(value) => handleChange(value, "variant")}>
                <div class="flex" slot="action">
                  <button >
                    Machine translate
                  </button>
                  <inlang-message-selector-button
                    @change=${(value) => handleChange(value, "message")} 
                    .message=${message}
                  >
                  </inlang-selector-button>
              </div>
              </inlang-variant-editor>
            `;
          })}
        </inlang-message-editor>
      `;
    })}
  </inlang-bundle-editor>
`;
samuelstroschein commented 3 weeks ago

@nils.jacobsen i assigned you to see that this issue wis worked on. i think you duplicated it somewhere else?

NilsJacobsen commented 3 weeks ago

I'm actually not sure if we need the wrapping component, because its super easy to wire the things up. 👍

samuelstroschein commented 3 weeks ago

let's go without a wrapping component then. we can introduce it at a later point in time if it's required