Skip to content

Commit

Permalink
refactor: remove bundle.alias
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelstroschein committed Sep 19, 2024
1 parent d1de0b8 commit b5cd406
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ vi.mock("../utilities/state", () => ({

vi.mock("@inlang/sdk2", () => ({
selectBundleNested: vi.fn(),
bundleIdOrAliasIs: vi.fn(),
}))

const mockBundle: BundleNested = {
Expand Down
7 changes: 5 additions & 2 deletions inlang/source-code/ide-extension/src/utilities/helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { bundleIdOrAliasIs, selectBundleNested, type IdeExtensionConfig } from "@inlang/sdk2"
import { selectBundleNested, type IdeExtensionConfig } from "@inlang/sdk2"
import { state } from "./state.js"

export const getExtensionApi = async (): Promise<IdeExtensionConfig | undefined> =>
(await state().project.plugins.get()).find((plugin) => plugin?.meta?.["app.inlang.ideExtension"])
?.meta?.["app.inlang.ideExtension"] as IdeExtensionConfig | undefined

/**
* Not needed anymore but left in to reduce refactoring https://github.com/opral/monorepo/pull/3137
*/
export const getSelectedBundleByBundleIdOrAlias = async (bundleIdOrAlias: string) => {
return await selectBundleNested(state().project.db)
.where(bundleIdOrAliasIs(bundleIdOrAlias))
.where("bundle.id", "=", bundleIdOrAlias)
.executeTakeFirst()
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ vi.mock("../state.js", () => ({

vi.mock("@inlang/sdk2", () => ({
selectBundleNested: vi.fn(),
bundleIdOrAliasIs: vi.fn(),
}))

vi.mock("vscode", () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ describe("Message Webview Provider Tests", () => {
const html = await createMessageHtml({
bundle: {
id: "message-id",
alias: { aliasKey: "aliasValue" },
messages: [
{
id: "message-id",
Expand All @@ -91,7 +90,6 @@ describe("Message Webview Provider Tests", () => {

// Validating that the created HTML contains the expected content
expect(html).toContain("message-id")
expect(html).toContain("aliasValue")
expect(html).toContain("Hello")
})

Expand All @@ -113,7 +111,6 @@ describe("Message Webview Provider Tests", () => {
const html = await createMessageHtml({
bundle: {
id: "message-id",
alias: { aliasKey: "aliasValue" },
messages: [],
},
isHighlighted: false,
Expand Down Expand Up @@ -146,7 +143,6 @@ describe("Message Webview Provider Tests", () => {
const html = await getTranslationsTableHtml({
bundle: {
id: "message-id",
alias: {},
messages: [
{
id: "message-id",
Expand Down Expand Up @@ -197,7 +193,6 @@ describe("Message Webview Provider Tests", () => {
const html = await getTranslationsTableHtml({
bundle: {
id: "message-id",
alias: {},
messages: [], // No messages for any locale
},
workspaceFolder: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import { escapeHtml } from "../utils.js"
// TODO: Uncomment when bundle subscribe is implemented
// import { throttle } from "throttle-debounce"
import {
type ProjectSettings,
selectBundleNested,
type Bundle,
type BundleNested,
type IdeExtensionConfig,
type InlangProject,
pollQuery,
} from "@inlang/sdk2"
import { getSelectedBundleByBundleIdOrAlias } from "../helper.js"

export function createMessageWebviewProvider(args: {
context: vscode.ExtensionContext
Expand Down Expand Up @@ -88,7 +85,7 @@ export function createMessageWebviewProvider(args: {
matchedBundles.map(async (bundle) => {
// @ts-ignore TODO: Introduce deprecation message for messageId
bundle.bundleId = bundle.bundleId || bundle.messageId
const bundleData = await getSelectedBundleByBundleIdOrAlias(bundle.bundleId)
const bundleData = await selectBundleNested(state().project.db).where("id", "=", bundle.bundleId).executeTakeFirst()
return bundleData
})
)
Expand Down Expand Up @@ -236,31 +233,6 @@ export async function createMessageHtml(args: {
isHighlighted: boolean
workspaceFolder: vscode.WorkspaceFolder
}): Promise<string> {
// Function to check if the record has any keys
const hasAliases = (aliases: Bundle["alias"]): boolean => {
return Object.keys(aliases).length > 0
}

const isExperimentalAliasesEnabled = ((await state().project.settings.get()) as ProjectSettings)
.experimental?.aliases

const aliasHtml =
isExperimentalAliasesEnabled && hasAliases(args.bundle.alias)
? `<div class="aliases" title="Alias">
<span><strong>@</strong></span>
<div>
${Object.entries(args.bundle.alias)
.map(
([key, value]) =>
`<span data-alias="${escapeHtml(value)}"><i>${escapeHtml(key)}</i>: ${escapeHtml(
value
)}</span>`
)
.join("")}
</div>
</div>`
: ""

const translationsTableHtml = await getTranslationsTableHtml({
bundle: args.bundle,
workspaceFolder: args.workspaceFolder,
Expand Down Expand Up @@ -295,7 +267,6 @@ export async function createMessageHtml(args: {
</div>
<div class="content" style="display: none;">
${translationsTableHtml}
${aliasHtml}
</div>
</div>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { telemetry } from "../../services/telemetry/index.js"
import { setState, state } from "../state.js"
import * as Sherlock from "@inlang/recommend-sherlock"
import { transpileToCjs } from "../import/transpileToCjs.js"
import * as fs from "node:fs/promises"
import * as fs from "node:fs"
import type { FileSystem } from "../fs/createFileSystemMapper.js"
import path from "node:path"

Expand Down
100 changes: 0 additions & 100 deletions inlang/source-code/sdk2/src/query-utilities/bundleIdOrAliasIs.test.ts

This file was deleted.

36 changes: 0 additions & 36 deletions inlang/source-code/sdk2/src/query-utilities/bundleIdOrAliasIs.ts

This file was deleted.

1 change: 0 additions & 1 deletion inlang/source-code/sdk2/src/query-utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ export { selectBundleNested } from "./selectBundleNested.js";
export { insertBundleNested } from "./insertBundleNested.js";
export { updateBundleNested } from "./updateBundleNested.js";
export { upsertBundleNested } from "./upsertBundleNested.js";
export { bundleIdOrAliasIs } from "./bundleIdOrAliasIs.js";
export { pollQuery } from "./pollQuery.js";
24 changes: 9 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5cd406

Please sign in to comment.