feat(app-widget): show description in widget (#3876)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import SuperJSON from "superjson";
|
||||
|
||||
import { eq } from "../..";
|
||||
import type { Database } from "../..";
|
||||
import { items } from "../../schema";
|
||||
|
||||
/**
|
||||
* To support showing the description in the widget itself we replaced
|
||||
* the tooltip show option with display mode.
|
||||
*/
|
||||
export async function migrateAppWidgetShowDescriptionTooltipToDisplayModeAsync(db: Database) {
|
||||
const existingAppItems = await db.query.items.findMany({
|
||||
where: (table, { eq }) => eq(table.kind, "app"),
|
||||
});
|
||||
|
||||
const itemsToUpdate = existingAppItems
|
||||
.map((item) => ({
|
||||
id: item.id,
|
||||
options: SuperJSON.parse<{ showDescriptionTooltip?: boolean }>(item.options),
|
||||
}))
|
||||
.filter((item) => item.options.showDescriptionTooltip !== undefined);
|
||||
|
||||
console.log(
|
||||
`Migrating app items with showDescriptionTooltip to descriptionDisplayMode count=${itemsToUpdate.length}`,
|
||||
);
|
||||
|
||||
await Promise.all(
|
||||
itemsToUpdate.map(async (item) => {
|
||||
const { showDescriptionTooltip, ...options } = item.options;
|
||||
await db
|
||||
.update(items)
|
||||
.set({
|
||||
options: SuperJSON.stringify({
|
||||
...options,
|
||||
descriptionDisplayMode: showDescriptionTooltip ? "tooltip" : "hidden",
|
||||
}),
|
||||
})
|
||||
.where(eq(items.id, item.id));
|
||||
}),
|
||||
);
|
||||
|
||||
console.log(`Migrated app items with showDescriptionTooltip to descriptionDisplayMode count=${itemsToUpdate.length}`);
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import type { Database } from "../..";
|
||||
import { migrateReleaseWidgetProviderToOptionsAsync } from "./0000_release_widget_provider_to_options";
|
||||
import { migrateOpnsenseCredentialsAsync } from "./0001_opnsense_credentials";
|
||||
import { migrateAppWidgetShowDescriptionTooltipToDisplayModeAsync } from "./0002_app_widget_show_description_tooltip_to_display_mode";
|
||||
|
||||
export const applyCustomMigrationsAsync = async (db: Database) => {
|
||||
await migrateReleaseWidgetProviderToOptionsAsync(db);
|
||||
await migrateOpnsenseCredentialsAsync(db);
|
||||
await migrateAppWidgetShowDescriptionTooltipToDisplayModeAsync(db);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user