Skip to content

Commit

Permalink
refactor: use new match array
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelstroschein committed Sep 23, 2024
1 parent 88a8295 commit 43c3fb3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ describe("editMessageCommand", () => {
variants: [
{
id: "testVariant",
match: { locale: "en" },
matches: [
{
type: "match",
name: "locale",
value: { type: "literal", value: "en" },
},
],
pattern: "mock-pattern",
},
],
Expand Down Expand Up @@ -175,7 +181,7 @@ describe("editMessageCommand", () => {
value: "Current content",
},
],
match: [],
matches: [],
},
],
},
Expand Down Expand Up @@ -230,7 +236,7 @@ describe("editMessageCommand", () => {
variants: [
{
id: "testVariant",
match: [],
matches: [],
pattern: "mock-pattern",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const editMessageCommand = {
return msg(`Message with locale ${locale} not found.`)
}

const variant = message?.variants.find((v) => Object.keys(v.match).length === 0)
const variant = message?.variants.find((v) => v.matches.length === 0)

if (!variant) {
return msg(`Variant with locale ${locale} not found.`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const mockBundle: BundleNested = {
{
id: "variantId",
messageId: "messageId",
match: {},
matches: [],
pattern: [
{
type: "text",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export async function contextTooltip(
const message = bundle.messages.find((m) => m.locale === locale)

// Get the variant from the message
const variant = message?.variants.find((v) => v.match.locale === locale)
const variant = message?.variants.find((v) =>
v.matches.find(
(m) => m.name === "locale" && m.value.type === "literal" && m.value?.value === locale
)
)

let m = MISSING_TRANSLATION_MESSAGE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export async function messagePreview(args: { context: vscode.ExtensionContext })
// Get the message from the bundle
const message = _bundle?.messages.find((m) => m.locale === baseLocale)

const variant = message?.variants.find((v) => Object.keys(v.match).length === 0)
const variant = message?.variants.find((v) => v.matches.length === 0)

const previewLocale = await getPreviewLocale()
const translationLocale = previewLocale.length ? previewLocale : baseLocale
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe("Message Webview Provider Tests", () => {
variants: [
{
id: "variant-id",
match: {},
matches: [],
messageId: "message-id",
pattern: [{ type: "text", value: "Hello" }],
},
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("Message Webview Provider Tests", () => {
variants: [
{
id: "variant-id",
match: {},
matches: [],
messageId: "message-id",
pattern: [{ type: "text", value: "Hello" }],
},
Expand Down

0 comments on commit 43c3fb3

Please sign in to comment.