Migrate DiscoverView.vue to Enhanced Triple Migration Pattern

- Replaced all databaseUtil and direct PlatformServiceFactory usage with PlatformServiceMixin methods
- Removed all raw SQL queries from the component
- Centralized all notification messages in src/constants/notifications.ts
- Replaced direct $notify calls with notification helpers and TIMEOUTS constants
- Streamlined template logic (tab classes via computed properties)
- Updated migration documentation and security audit
- Ran lint-fix; no errors remain

Ready for human testing and validation.
This commit is contained in:
Matthew Raymer
2025-07-08 12:19:09 +00:00
parent 6857cb02b5
commit 0d75dd6262
4 changed files with 263 additions and 55 deletions

View File

@@ -326,16 +326,20 @@ import {
NotificationIface,
DEFAULT_PARTNER_API_SERVER,
} from "../constants/app";
import { logConsoleAndDb } from "../db/index";
import { Contact } from "../db/tables/contacts";
import { BoundingBox } from "../db/tables/settings";
import * as databaseUtil from "../db/databaseUtil";
import { PlanData } from "../interfaces";
import { didInfo, errorStringForLog, getHeaders } from "../libs/endorserServer";
import { OnboardPage, retrieveAccountDids } from "../libs/util";
import { logger } from "../utils/logger";
import { UserProfile } from "@/libs/partnerServer";
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
import { createNotifyHelpers, TIMEOUTS } from "@/utils/notify";
import {
NOTIFY_DISCOVER_SEARCH_ERROR,
NOTIFY_DISCOVER_LOCAL_SEARCH_ERROR,
NOTIFY_DISCOVER_MAP_SEARCH_ERROR,
} from "@/constants/notifications";
interface Tile {
indexLat: number;
indexLon: number;
@@ -356,12 +360,15 @@ interface Tile {
QuickNav,
TopMessage,
},
mixins: [PlatformServiceMixin],
})
export default class DiscoverView extends Vue {
$notify!: (notification: NotificationIface, timeout?: number) => void;
$router!: Router;
$route!: RouteLocationNormalizedLoaded;
notify!: ReturnType<typeof createNotifyHelpers>;
activeDid = "";
allContacts: Array<Contact> = [];
allMyDids: Array<string> = [];
@@ -389,23 +396,23 @@ export default class DiscoverView extends Vue {
// make this function available to the Vue template
didInfo = didInfo;
created() {
this.notify = createNotifyHelpers(this.$notify);
}
async mounted() {
this.searchTerms = this.$route.query["searchText"]?.toString() || "";
const searchPeople = !!this.$route.query["searchPeople"];
const settings = await databaseUtil.retrieveSettingsForActiveAccount();
const settings = await this.$accountSettings();
this.activeDid = (settings.activeDid as string) || "";
this.apiServer = (settings.apiServer as string) || "";
this.partnerApiServer =
(settings.partnerApiServer as string) || this.partnerApiServer;
this.searchBox = settings.searchBoxes?.[0] || null;
const platformService = PlatformServiceFactory.getInstance();
const dbContacts = await platformService.dbQuery("SELECT * FROM contacts");
this.allContacts = databaseUtil.mapQueryResultToValues(
dbContacts,
) as unknown as Contact[];
this.allContacts = await this.$getAllContacts();
this.allMyDids = await retrieveAccountDids();
@@ -450,7 +457,7 @@ export default class DiscoverView extends Vue {
if (this.isLocalActive) {
await this.searchLocal();
} else if (this.isMappedActive) {
const mapRef = this.$refs.projectMap as L.Map;
const mapRef = this.$refs.projectMap as any;
this.requestTiles(mapRef.leafletObject); // not ideal because I found this from experimentation, not documentation
} else {
await this.searchAll();
@@ -513,18 +520,9 @@ export default class DiscoverView extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
logger.error("Error with search all: " + errorStringForLog(e));
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Searching",
text:
e.userMessage ||
"There was a problem retrieving " +
(this.isProjectsActive ? "projects" : "profiles") +
".",
},
5000,
this.notify.error(
e.userMessage || NOTIFY_DISCOVER_SEARCH_ERROR.message,
TIMEOUTS.LONG,
);
} finally {
this.isLoading = false;
@@ -605,18 +603,9 @@ export default class DiscoverView extends Vue {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
logger.error("Error with search local: " + errorStringForLog(e));
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text:
e.userMessage ||
"There was a problem retrieving " +
(this.isProjectsActive ? "projects" : "profiles") +
".",
},
5000,
this.notify.error(
e.userMessage || NOTIFY_DISCOVER_LOCAL_SEARCH_ERROR.message,
TIMEOUTS.LONG,
);
} finally {
this.isLoading = false;
@@ -752,18 +741,12 @@ export default class DiscoverView extends Vue {
};
}
} catch (e) {
logConsoleAndDb(
await this.$logError(
"Error loading projects on the map: " + errorStringForLog(e),
true,
);
this.$notify(
{
group: "alert",
type: "danger",
title: "Map Error",
text: "There was a problem loading projects on the map.",
},
3000,
this.notify.error(
NOTIFY_DISCOVER_MAP_SEARCH_ERROR.message,
TIMEOUTS.STANDARD,
);
}
}