Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: search result highlight (#422)
STEVENaaf1503ed25c
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.tsindex 8573b09868..0d3f469e27 100644--- a/frontend/src/store/modules/sqlEditor.ts+++ b/frontend/src/store/modules/sqlEditor.ts@@ -349,6 +349,14 @@ const actions = {await axios.delete(`/api/savedquery/${id}`);dispatch("fetchSavedQueryList");},+ async checkSavedQueryExistById({ state }: any, id: number) {+ for (const savedQuery of state.savedQueryList) {+ if (savedQuery.id === id) {+ return true;+ }+ }+ return false;+ },};export default {diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.tsindex a435769180..da5c408860 100644--- a/frontend/src/utils/util.ts+++ b/frontend/src/utils/util.ts@@ -45,7 +45,7 @@ export function bytesToString(size: number): string {export function nanosecondsToString(nanoseconds: number): string {// dayjs.duration() takes the length of time in milliseconds.- return dayjs.duration(nanoseconds/1000000).humanize();+ return dayjs.duration(nanoseconds / 1000000).humanize();}export function timezoneString(zoneName: string, offset: number): string {@@ -150,3 +150,7 @@ export function getStringCookie(name: string): string {return "";}++export function getHighlightHTMLByKeyWords(s: string, k: string) {+ return s.replaceAll(k, `<b class="text-accent">${k}</b>`);+}diff --git a/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryView.vue b/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryView.vueindex 385866bb00..a58fc36f87 100644--- a/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryView.vue+++ b/frontend/src/views/SqlEditor/AsidePanel/QueryHistoryView.vue@@ -38,9 +38,8 @@</div><pclass="max-w-full mt-2 mb-1 text-sm break-words font-mono line-clamp-3"- >- {{ history.statement }}- </p>+ v-html="history.formatedStatement"+ ></p></div></div>@@ -85,6 +84,7 @@ import {SqlEditorActions,SqlEditorState,} from "../../../types";+import { getHighlightHTMLByKeyWords } from "../../../utils";import DeleteHint from "./DeleteHint.vue";interface State {@@ -116,7 +116,7 @@ const state = reactive<State>({});const data = computed(() => {- const temp =+ const tempData =queryHistoryList.value && queryHistoryList.value.length > 0? queryHistoryList.value.filter((history) => {let t = false;@@ -128,7 +128,15 @@ const data = computed(() => {return t;}): [];- return temp;++ return tempData.map((history) => {+ return {+ ...history,+ formatedStatement: state.search+ ? getHighlightHTMLByKeyWords(history.statement, state.search)+ : history.statement,+ };+ });});const notifyMessage = computed(() => {diff --git a/frontend/src/views/SqlEditor/AsidePanel/SavedQueryView.vue b/frontend/src/views/SqlEditor/AsidePanel/SavedQueryView.vueindex d82306ea4d..41bb07f027 100644--- a/frontend/src/views/SqlEditor/AsidePanel/SavedQueryView.vue+++ b/frontend/src/views/SqlEditor/AsidePanel/SavedQueryView.vue@@ -39,7 +39,7 @@@keyup.enter="handleSavedQueryNameChanged"@keyup.esc="handleCancelEdit"/>- <span v-else class="text-sm">{{ query.name }}</span>+ <span v-else class="text-sm" v-html="query.formatedName"></span></div><NDropdowntrigger="click"@@ -59,9 +59,8 @@<pclass="max-w-full text-gray-400 break-words font-mono truncate"style="font-size: 10px"- >- {{ query.statement }}- </p>+ v-html="query.formatedStatement"+ ></p></div></div>@@ -109,6 +108,7 @@ import {SqlEditorActions,SqlEditorState,} from "../../../types";+import { getHighlightHTMLByKeyWords } from "../../../utils";import DeleteHint from "./DeleteHint.vue";interface State {@@ -157,11 +157,14 @@ const state = reactive<State>({const queryNameInputerRef = ref<HTMLInputElement>();const data = computed(() => {- const temp =+ const tempData =savedQueryList.value && savedQueryList.value.length > 0? savedQueryList.value.filter((savedQuery) => {let t = false;+ if (savedQuery.name.includes(state.search)) {+ t = true;+ }if (savedQuery.statement.includes(state.search)) {t = true;}@@ -169,7 +172,18 @@ const data = computed(() => {return t;}): [];- return temp;++ return tempData.map((savedQuery) => {+ return {+ ...savedQuery,+ formatedName: state.search+ ? getHighlightHTMLByKeyWords(savedQuery.name, state.search)+ : savedQuery.name,+ formatedStatement: state.search+ ? getHighlightHTMLByKeyWords(savedQuery.statement, state.search)+ : savedQuery.statement,+ };+ });});const notifyMessage = computed(() => {diff --git a/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue b/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vueindex 1b9344eab2..235bb05bc2 100644--- a/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue+++ b/frontend/src/views/SqlEditor/EditorPanel/EditorAction.vue@@ -66,12 +66,17 @@ const { currentTab } = useNamespacedGetters<EditorSelectorGetters>("editorSelector",["currentTab"]);-const { createSavedQuery, setConnectionContext, patchSavedQuery } =- useNamespacedActions<SqlEditorActions>("sqlEditor", [- "createSavedQuery",- "setConnectionContext",- "patchSavedQuery",- ]);+const {+ createSavedQuery,+ setConnectionContext,+ patchSavedQuery,+ checkSavedQueryExistById,+} = useNamespacedActions<SqlEditorActions>("sqlEditor", [+ "createSavedQuery",+ "setConnectionContext",+ "patchSavedQuery",+ "checkSavedQueryExistById",+]);const { updateActiveTab } = useNamespacedActions<EditorSelectorActions>("editorSelector",["updateActiveTab"]@@ -138,10 +143,12 @@ const handleConnectionChange = (const handleSaveQueryBtnClick = async () => {const { queryStatement, label, currentQueryId } = currentTab.value;+ const isQueryExist = await checkSavedQueryExistById(currentQueryId || -1);- if (currentQueryId) {+ if (isQueryExist && currentQueryId) {patchSavedQuery({id: currentQueryId,+ name: label,statement: queryStatement,});} else {@@ -153,6 +160,7 @@ const handleSaveQueryBtnClick = async () => {currentQueryId: newSavedQuery.id,});}+updateActiveTab({isSaved: true,});diff --git a/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue b/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vueindex 5a26940bb0..3bd7ba82ac 100644--- a/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue+++ b/frontend/src/views/SqlEditor/EditorPanel/QueryEditor.vue@@ -31,10 +31,11 @@ const { updateActiveTab } = useNamespacedActions<EditorSelectorActions>("editorSelector",["updateActiveTab"]);-const { createSavedQuery, patchSavedQuery } =+const { createSavedQuery, patchSavedQuery, checkSavedQueryExistById } =useNamespacedActions<SqlEditorActions>("sqlEditor", ["createSavedQuery","patchSavedQuery",+ "checkSavedQueryExistById",]);const { execute } = useExecuteSQL();@@ -56,10 +57,12 @@ const handleChangeSelection = debounce((value: string) => {const handleSave = async (statement: string) => {const { label, currentQueryId } = currentTab.value;+ const isQueryExist = await checkSavedQueryExistById(currentQueryId || -1);- if (currentQueryId) {+ if (isQueryExist && currentQueryId) {patchSavedQuery({id: currentQueryId,+ name: label,statement,});} else {@@ -71,6 +74,7 @@ const handleSave = async (statement: string) => {currentQueryId: newSavedQuery.id,});}+updateActiveTab({isSaved: true,});diff --git a/frontend/src/views/SqlEditor/QuerySelector.vue b/frontend/src/views/SqlEditor/QuerySelector.vueindex 3d6dab80f3..f21d60c9c0 100644--- a/frontend/src/views/SqlEditor/QuerySelector.vue+++ b/frontend/src/views/SqlEditor/QuerySelector.vue@@ -147,10 +147,11 @@ const { addTab, removeTab, setActiveTabId, updateActiveTab } ="setActiveTabId","updateActiveTab",]);-const { patchSavedQuery } = useNamespacedActions<SqlEditorActions>(- "sqlEditor",- ["patchSavedQuery"]-);+const { patchSavedQuery, checkSavedQueryExistById } =+ useNamespacedActions<SqlEditorActions>("sqlEditor", [+ "patchSavedQuery",+ "checkSavedQueryExistById",+ ]);const store = useStore();const { t } = useI18n();@@ -240,8 +241,19 @@ const handleCancelInput = () => {});};-const handleSelectTab = (tab: TabInfo) => {+const handleSelectTab = async (tab: TabInfo) => {setActiveTabId(tab.id);++ if (currentTab.value.currentQueryId) {+ const exist = await checkSavedQueryExistById(+ currentTab.value.currentQueryId+ );+ if (!exist) {+ updateActiveTab({+ currentQueryId: undefined,+ });+ }+ }};const handleAddTab = (tab: AnyTabInfo) => {addTab(tab);