feat: 🎸 Add ability to search other resources as well (#3021)

This commit adds the ability to search across multiple tables with joins which unlocks a better search experience in the case of tables that source their data from multiple tables.
This commit is contained in:
Zhihe Li authored and GitHub committed 2025-11-05 17:57:45 -05:00
1 parent d8744e81bc
commit 92f5a65c00
7 files changed
+219 -36

No files matched your search

@@ -5,7 +5,6 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { hash } from 'rsvp';
import { restartableTask, timeout } from 'ember-concurrency';
export default class ScopesScopeAliasesIndexRoute extends Route {
@@ -79,28 +78,68 @@ export default class ScopesScopeAliasesIndexRoute extends Route {
direction: sortDirection,
};
const searchOptions = {
text: search,
relatedSearches: [
{
resource: 'target',
fields: ['name'],
join: {
joinFrom: 'destination_id',
joinOn: 'id',
},
},
],
};
const targetPromise = this.store.query(
'target',
{
scope_id,
recursive: true,
page: 1,
pageSize: 1,
},
{ pushToStore: false },
);
aliases = await this.store.query('alias', {
scope_id,
query: { search, sort },
query: { search: searchOptions, sort },
page,
pageSize,
});
totalItems = aliases.meta?.totalItems;
// since we don't receive target info from aliases list API,
// we query the store to fetch target information based on the destination id
aliases = await Promise.all(
aliases.map((alias) =>
hash({
alias,
target: alias.destination_id
? this.store.findRecord('target', alias.destination_id, {
backgroundReload: false,
})
: null,
}),
await targetPromise;
// All the targets should have been retrieved just before this so we don't need to make another API request
// Check for actual aliases with destinations as an empty array will bring back all targets which we don't want
const associatedTargets = aliases.some((alias) => alias.destination_id)
? await this.store.query(
'target',
{
query: {
filters: {
id: aliases
.filter((alias) => alias.destination_id)
.map((alias) => ({
equals: alias.destination_id,
})),
},
},
},
{ pushToStore: true, peekDb: true },
)
: [];
aliases = aliases.map((alias) => ({
alias,
target: associatedTargets.find(
(target) => target.id === alias.destination_id,
),
);
}));
doAliasesExist = await this.getDoAliasesExist(scope_id, totalItems);
}
@@ -279,6 +279,46 @@ module('Acceptance | aliases | list', function (hooks) {
.includesText(intl.t('titles.no-results-found'));
});
test('user can search for aliases by associated target name', async function (assert) {
setRunOptions({
rules: {
'color-contrast': {
// [ember-a11y-ignore]: axe rule "color-contrast" automatically ignored on 2025-08-01
enabled: false,
},
},
});
// Create a target with a specific name
const targetWithName = this.server.create('target', {
name: 'A real production target',
scope: instances.scopes.project,
});
// Create an alias associated with this target
const aliasWithNamedTarget = this.server.create('alias', {
scope: instances.scopes.global,
destination_id: targetWithName.id,
});
const urlAliasWithNamedTarget = `${urls.aliases}/${aliasWithNamedTarget.id}`;
await visit(urls.globalScope);
await click(commonSelectors.HREF(urls.aliases));
assert.dom(commonSelectors.HREF(urls.alias)).exists();
assert.dom(commonSelectors.HREF(urls.aliasWithTarget)).exists();
assert.dom(commonSelectors.HREF(urlAliasWithNamedTarget)).exists();
await fillIn(commonSelectors.SEARCH_INPUT, 'production target');
await waitFor(commonSelectors.HREF(urls.alias), { count: 0 });
assert.dom(commonSelectors.HREF(urlAliasWithNamedTarget)).exists();
assert.dom(commonSelectors.HREF(urls.alias)).doesNotExist();
assert.dom(commonSelectors.HREF(urls.aliasWithTarget)).doesNotExist();
});
test('aliases are sorted by created_time descending by default', async function (assert) {
setRunOptions({
rules: {
@@ -39,6 +39,10 @@ module('Acceptance | aliases | update', function (hooks) {
type: 'org',
scope: { id: 'global', type: 'global' },
});
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: 'org' },
});
instances.target = this.server.create('target', {
scope: instances.scopes.project,
});