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

Update-bundle-component #3139

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion inlang/source-code/bundle-component/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@types/chroma-js": "^2.4.4",
"@vitest/coverage-v8": "^0.33.0",
"lit": "^3.1.2",
"npm": "^10.8.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup": "3.29.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("patternToString", () => {
{
type: "expression",
arg: {
type: "variable",
type: "variable-reference",
name: "name",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("stringToPattern", () => {
{
type: "expression",
arg: {
type: "variable",
type: "variable-reference",
name: "name",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const stringToPattern = (props: { text: string }): Pattern => {
pattern.push({
type: "expression",
arg: {
type: "variable",
type: "variable-reference",
name: match[1],
},
})
Expand Down
50 changes: 26 additions & 24 deletions inlang/source-code/bundle-component/src/mock/messageBundle.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
import type { BundleNested } from "@inlang/sdk2"
import type { Bundle, Message, Variant } from "@inlang/sdk2"

export const bundleWithoutSelectors: BundleNested = {
id: "message-bundle-id",
export const exampleWithoutSelectors: {
bundles: Bundle[]
messages: Message[]
variants: Variant[]
} = {
bundles: [
{
id: "message-bundle-id",
declarations: [],
},
],
messages: [
{
bundleId: "message-bundle-id",
id: "message-id-en",
locale: "en",
selectors: [],
declarations: [],
variants: [
{
messageId: "message-id-en",
id: "variant-id-en-*",
match: {},
pattern: [{ type: "text", value: "{count} new messages" }],
},
],
},
{
bundleId: "message-bundle-id",
id: "message-id-de",
locale: "de",
selectors: [],
declarations: [],
variants: [
{
messageId: "message-id-de",
id: "variant-id-de-*",
match: {},
pattern: [{ type: "text", value: "{count} neue Nachrichten" }],
},
],
},
],
// default: "frontend_button_text",
// ios: "frontendButtonText",
// },
variants: [
{
messageId: "message-id-en",
id: "variant-id-en-*",
match: {},
pattern: [{ type: "text", value: "{count} new messages" }],
},
{
messageId: "message-id-de",
id: "variant-id-de-*",
match: {},
pattern: [{ type: "text", value: "{count} neue Nachrichten" }],
},
],
}
149 changes: 149 additions & 0 deletions inlang/source-code/bundle-component/src/mock/pluralBundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import type { Bundle, Message, Variant } from "@inlang/sdk2"

export const examplePlural: {
bundles: Bundle[]
messages: Message[]
variants: Variant[]
} = {
bundles: [
{
id: "mock_bundle_human_id",
declarations: [
{
type: "input-variable",
name: "numProducts",
},
{
type: "input-variable",
name: "count",
},
{
type: "input-variable",
name: "projectCount",
},
],
},
],
messages: [
{
bundleId: "mock_bundle_human_id",
id: "mock_message_id_de",
locale: "de",
selectors: [
{
type: "expression",
arg: {
type: "variable-reference",
name: "numProducts",
},
annotation: {
type: "function-reference",
name: "plural",
options: [],
},
},
],
},
{
bundleId: "mock_bundle_human_id",
id: "mock_message_id_en",
locale: "en",
selectors: [
{
type: "expression",
arg: {
type: "variable-reference",
name: "numProducts",
},
annotation: {
type: "function-reference",
name: "plural",
options: [],
},
},
],
},
],
variants: [
{
messageId: "mock_message_id_de",
id: "mock_variant_id_de_zero",
match: { numProducts: "zero" },
pattern: [
{
type: "text",
value: "Keine Produkte",
},
],
},
{
messageId: "mock_message_id_de",
id: "mock_variant_id_de_one",
match: { numProducts: "one" },
pattern: [
{
type: "text",
value: "Ein Produkt",
},
],
},
{
messageId: "mock_message_id_de",
id: "mock_variant_id_de_other",
match: { numProducts: "other" },
pattern: [
{
type: "expression",
arg: {
type: "variable-reference",
name: "numProducts",
},
},
{
type: "text",
value: " Produkte",
},
],
},
{
messageId: "mock_message_id_en",
id: "mock_variant_id_en_zero",
match: { numProducts: "zero" },
pattern: [
{
type: "text",
value: "No Products",
},
],
},
{
messageId: "mock_message_id_en",
id: "mock_variant_id_en_one",
match: { numProducts: "one" },
pattern: [
{
type: "text",
value: "A product",
},
],
},
{
messageId: "mock_message_id_en",
id: "mock_variant_id_en_other",
match: { numProducts: "other" },
pattern: [
{
type: "expression",
arg: {
type: "variable-reference",
name: "numProducts",
},
},
{
type: "text",
value: " products",
},
],
},
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The component is currently only used inside of the bundle. That means that it ca
<Canvas of={InlangAddInput.Example} />

#### Props:
- `messages`: The messages as Message[] to get inputs
- `bundle`: The bundle

#### Event:
- `change`: The component dispatches a change event that contains all necessary information.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { pluralBundle } from "@inlang/sdk2"
import "./inlang-add-input.ts"
import "./../../inlang-bundle.ts"
import type { Meta, StoryObj } from "@storybook/web-components"
import { html } from "lit"
import { examplePlural } from "../../../mock/pluralBundle.ts"

const meta: Meta = {
component: "inlang-add-input",
Expand All @@ -22,7 +22,7 @@ export const Example: StoryObj = {
}
</style>
<div class="container">
<inlang-add-input messages=${pluralBundle.messages}>Press me</inlang-add-input>
<inlang-add-input bundle=${examplePlural.bundles[0]}>Press me</inlang-add-input>
</div>`
},
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LitElement, css, html } from "lit"
import { customElement, property, state } from "lit/decorators.js"
import { createChangeEvent } from "../../../helper/event.js"
import type { Message } from "@inlang/sdk2"
import type { Bundle } from "@inlang/sdk2"
import { baseStyling } from "../../../styling/base.js"

import SlDropdown from "@shoelace-style/shoelace/dist/components/dropdown/dropdown.component.js"
Expand Down Expand Up @@ -69,8 +69,8 @@ export default class InlangAddInput extends LitElement {
`,
]

@property({ type: Array })
messages: Message[] | undefined
@property({ type: Object })
bundle: Bundle

//state
@state()
Expand Down Expand Up @@ -114,29 +114,22 @@ export default class InlangAddInput extends LitElement {
@keydown=${(e: KeyboardEvent) => {
if (e.key === "Enter") {
if (this._newInput && this._newInput.trim() !== "") {
for (const message of this.messages ?? []) {
const newMessage = structuredClone(message)

newMessage.declarations.push({
type: "input",
name: this._newInput!,
// value: {
// type: "expression",
// arg: {
// type: "variable",
// name: this._newInput!,
// },
// },
this.dispatchEvent(
createChangeEvent({
type: "Bundle",
operation: "update",
newData: {
...this.bundle,
declarations: [
...this.bundle.declarations,
{
name: this._newInput,
type: "input-variable",
},
],
},
})

this.dispatchEvent(
createChangeEvent({
type: "Message",
operation: "update",
newData: newMessage,
})
)
}
)
}

this._newInput = ""
Expand Down
Loading
Loading