diff --git a/src/components/Dashboard/context/SpotlightContext.jsx b/src/components/Dashboard/context/SpotlightContext.jsx index 4f5194e..3833630 100644 --- a/src/components/Dashboard/context/SpotlightContext.jsx +++ b/src/components/Dashboard/context/SpotlightContext.jsx @@ -30,9 +30,11 @@ import IdDisplay from '../common/IdDisplay' import config from '../../../config' import { getModelByName, - getModelByPrefix + getModelByPrefix, + searchModelsByLabel } from '../../../database/ObjectModels' import InfoCircleIcon from '../../Icons/InfoCircleIcon' +import MenuIcon from '../../Icons/MenuIcon' import { ApiServerContext } from './ApiServerContext' import { AuthContext } from './AuthContext' import { ElectronContext } from './ElectronContext' @@ -128,6 +130,22 @@ const SpotlightContent = ({ } setLoading(false) + + const models = searchModelsByLabel(searchQuery.trim()).map((model) => ({ + type: model.name, + name: model.labelPlural, + icon: model.icon, + actions: [ + { + default: true, + row: true, + icon: MenuIcon, + url: () => { + return model.url + } + } + ] + })) // If the query contains a prefix mode character, and the response is an object, wrap it in an array if ( /[:?^]/.test(searchQuery) && @@ -135,9 +153,9 @@ const SpotlightContent = ({ !Array.isArray(data) && typeof data === 'object' ) { - setListData([data]) + setListData([...models, data]) } else { - setListData(data) + setListData([...models, ...data]) } // Check if there's a pending query after this fetch completes @@ -290,7 +308,11 @@ const SpotlightContent = ({ const item = listData[0] let type = item.type || item.objectType || inputPrefix?.type const model = getModelByName(type) - const defaultAction = model ? getDefaultRowAction(model) : null + const defaultAction = item?.type + ? getDefaultRowAction(item) + : model + ? getDefaultRowAction(model) + : null if (defaultAction) { triggerRowAction(defaultAction, item) } @@ -304,7 +326,11 @@ const SpotlightContent = ({ const item = listData[index] let type = item.type || item.objectType || inputPrefix?.type const model = getModelByName(type) - const defaultAction = model ? getDefaultRowAction(model) : null + const defaultAction = item?.type + ? getDefaultRowAction(item) + : model + ? getDefaultRowAction(model) + : null if (defaultAction) { triggerRowAction(defaultAction, item) } @@ -447,10 +473,12 @@ const SpotlightContent = ({ { - let type = item.objectType || inputPrefix?.type + let type = item.objectType || inputPrefix?.type || item?.type const model = getModelByName(type) const Icon = model?.icon - const rowActions = getRowActions(model) + const rowActions = item?.type + ? item.actions + : getRowActions(model) let shortcutText = '' if (index === 0) { shortcutText = 'ENTER' @@ -492,7 +520,9 @@ const SpotlightContent = ({ showId={false} /> ) : null} - + {item?._id ? ( + + ) : null} {rowActions diff --git a/src/database/ObjectModels.js b/src/database/ObjectModels.js index ed4bc9b..15c8663 100644 --- a/src/database/ObjectModels.js +++ b/src/database/ObjectModels.js @@ -213,6 +213,14 @@ export function getModelByPrefix(prefix) { ) } +export function searchModelsByLabel(label) { + return objectModels.filter( + (meta) => + meta.label.toLowerCase().includes(label.toLowerCase()) || + meta.labelPlural.toLowerCase().includes(label.toLowerCase()) + ) +} + // Utility function to get nested object values export const getPropertyValue = (obj, path) => { if (!obj || !path) return undefined