Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ dist

# IDEs
.vscode
.idea

# Cypress related files
**/cypress.env.json
Expand All @@ -160,4 +161,4 @@ dist
**/token.json
**/local-dev/**
**/*copy.json
testing/cypress.config copy.ts
testing/cypress.config copy.ts
3 changes: 2 additions & 1 deletion app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
NUXT_SITEMINDER_LOGOUT_URL="https://logontest7.gov.bc.ca/clp-cgi/logoff.cgi"

#vaults API
NUXT_NAMEX_API_URL="https://namex-dev.apps.silver.devops.gov.bc.ca"
NUXT_NAMEX_API_GW_URL="https://test.api.connect.gov.bc.ca/namex-dev"
NUXT_NAMEX_API_KEY=
NUXT_NAMEX_API_VERSION="/api/v1"
NUXT_NAMEX_ADMIN_URL = "https://namex-solr-dev.apps.silver.devops.gov.bc.ca/"

Expand Down
3 changes: 2 additions & 1 deletion app/devops/vaults.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ NUXT_SITEMINDER_LOGOUT_URL="op://web-url/$APP_ENV/siteminder/SITEMINDER_LOGOUT_U
NUXT_NAMEX_ADMIN_URL="op://web-url/$APP_ENV/namex-examination/NAMEX_ADMIN_URL"

#vaults API
NUXT_NAMEX_API_URL="op://API/$APP_ENV/namex-api/NAMEX_API_URL"
NUXT_NAMEX_API_GW_URL="op://API/$APP_ENV/namex-api/NAMEX_API_GW_URL"
NUXT_NAMEX_API_KEY="op://API/$APP_ENV/namex-api/NAMEX_API_KEY"
NUXT_NAMEX_API_VERSION="op://API/$APP_ENV/namex-api/NAMEX_API_VERSION"

#vaults keycloak
Expand Down
4 changes: 2 additions & 2 deletions app/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export default defineNuxtConfig({
'@nuxt/content',
'@nuxtjs/tailwindcss',
'@pinia/nuxt',
'nuxt-vitest',
],
css: ['@/assets/css/main.scss'],
typescript: {
Expand Down Expand Up @@ -50,7 +49,8 @@ export default defineNuxtConfig({
firebaseAuthDomain: process.env.NUXT_AUTH_DOMAIN,
firebaseProjectId: process.env.NUXT_PROJECT_ID,
firebaseAppId: process.env.NUXT_APP_ID,
namexAPIURL: process.env.NUXT_NAMEX_API_URL,
namexAPIURL: process.env.NUXT_NAMEX_API_GW_URL,
namexAPIKey: process.env.NUXT_NAMEX_API_KEY,
namexAPIVersion: process.env.NUXT_NAMEX_API_VERSION,
namexAdminURL: process.env.NUXT_NAMEX_ADMIN_URL,
keycloakAuthUrl: process.env.NUXT_KEYCLOAK_AUTH_URL,
Expand Down
4 changes: 2 additions & 2 deletions app/package-lock.json

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

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "name-examination",
"version": "1.2.47",
"version": "1.2.49",
"private": true,
"scripts": {
"build": "nuxt generate",
Expand Down
56 changes: 35 additions & 21 deletions app/store/examine/conflicts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ConflictListItem } from '~/types'
import { getConflicts } from '~/util/namex-api'
import { highlightWord } from '~/util/html/highlight'


export const useConflicts = defineStore('conflicts', () => {
Expand Down Expand Up @@ -83,31 +84,44 @@ export const useConflicts = defineStore('conflicts', () => {
}

function highlightNameChoices(entry: any): string {
let result = entry.name
if (entry.highlighting) {
if (entry.highlighting.stems) {
entry.highlighting.stems.forEach((stem: string) => {
const re = new RegExp(stem, 'gi')
result = result.replace(re, (match: any) => `<span class="stem-highlight">${match}</span>`)
})
const name: string = entry?.name ?? ''
const highlighting = entry?.highlighting

// If we have nothing to highlight, keep original text intact
if (!name || !highlighting) {
return name
}

// Split into word and whitespace tokens so we preserve spacing exactly
const tokens = name.split(/(\s+)/)

const exactList: string[] = Array.isArray(highlighting.exact) ? highlighting.exact : []
const synonymList: string[] = Array.isArray(highlighting.synonyms) ? highlighting.synonyms : []
const stemList: string[] = Array.isArray(highlighting.stems) ? highlighting.stems : []

const applyFirstMatchingCategory = (word: string): string => {
// exact > synonym > stem
for (const exact of exactList) {
const highlighted = highlightWord(exact, word, 'exact-highlight')
if (highlighted !== word) return highlighted
}

if (entry.highlighting.synonyms) {
entry.highlighting.synonyms.forEach((synonym: string) => {
const re = new RegExp(synonym, 'gi')
result = result.replace(re, (match: any) => `<span class="synonym-highlight">${match}</span>`)
})
for (const synonym of synonymList) {
const highlighted = highlightWord(synonym, word, 'synonym-highlight')
if (highlighted !== word) return highlighted
}

if (entry.highlighting.exact) {
entry.highlighting.exact.forEach((exact: string) => {
const re = new RegExp(exact, 'gi')
result = result.replace(re, (match: any) => `<span class="exact-highlight">${match}</span>`)
})
for (const stem of stemList) {
const highlighted = highlightWord(stem, word, 'stem-highlight')
if (highlighted !== word) return highlighted
}

return word
}

return result
return tokens
.map((token) => (token.trim().length === 0 ? token : applyFirstMatchingCategory(token)))
.join('')
}

async function initialize(searchQuery: string, exactPhrase: string) {
Expand Down Expand Up @@ -163,7 +177,7 @@ export const useConflicts = defineStore('conflicts', () => {
}

/** Reset selectedConflicts and comparedConflicts and save existing data */
function disableAutoAdd () {
function disableAutoAdd() {
if (!autoAdd.value) {
const initialRun = (prevSelectedConflicts.value.length === 0 && prevComparedConflicts.value.length === 0)
for (const conflict of selectedConflicts.value) {
Expand All @@ -180,7 +194,7 @@ export const useConflicts = defineStore('conflicts', () => {
}

/** Reassign selectedConflicts and comparedConflicts */
function enableAutoAdd () {
function enableAutoAdd() {
if (autoAdd.value) {
selectedConflicts.value = prevSelectedConflicts.value
comparedConflicts.value = prevComparedConflicts.value
Expand All @@ -205,6 +219,6 @@ export const useConflicts = defineStore('conflicts', () => {
enableAutoAdd,
autoAdd,
firstConflictItem,
syncSelectedAndComparedConflicts,
syncSelectedAndComparedConflicts
}
})
7 changes: 7 additions & 0 deletions app/util/html/highlight.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const escapeRegExp = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

export const highlightWord = (word: string, text: string, highlightCss: string) => {
if (!word) return text
const re = new RegExp(escapeRegExp(word), 'gi')
return text.replace(re, (match: string) => `<span class="${highlightCss}">${match}</span>`)
}
6 changes: 4 additions & 2 deletions app/util/namex-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function callNamexApi(url: URL, options?: object, headers?: object) {
headers: {
Authorization: `Bearer ${token}`,
'App-Name': packageInfo.name,
'X-Apikey': useRuntimeConfig().public.namexAPIKey || '',
...headers,
},
...(options ? options : {}),
Expand All @@ -41,9 +42,10 @@ async function callNamexApi(url: URL, options?: object, headers?: object) {
*/
export function getNamexApiUrl(endpoint: string): URL {
const config = useRuntimeConfig().public
const base = config.namexAPIURL
return new URL(
config.namexAPIVersion + endpoint,
config.namexAPIURL as string
config.namexAPIVersion.replace(/^\//, '') + endpoint,
base.endsWith('/') ? base : base + '/' as string
)
}

Expand Down
Loading