Skip to content

Commit

Permalink
Merge branch 'main' into ICU-15186-update-icon-and-text-based-on-stor…
Browse files Browse the repository at this point in the history
…age-bucket-type
  • Loading branch information
DhariniJeeva authored Sep 25, 2024
2 parents a7474d6 + b40c53f commit 76cc843
Show file tree
Hide file tree
Showing 20 changed files with 505 additions and 509 deletions.
21 changes: 12 additions & 9 deletions addons/api/addon-test-support/handlers/cache-daemon-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import sinon from 'sinon';
import { typeOf } from '@ember/utils';
import { resourceNames } from 'api/handlers/cache-daemon-handler';
import { singularize } from 'ember-inflector';
import { underscore } from '@ember/string';

/**
* This test helper can be used to help setup your sinon stubs in your tests.
Expand Down Expand Up @@ -69,16 +70,18 @@ export default function setupStubs(hooks) {
.withArgs('searchCacheDaemon')
.onCall(i)
.returns({
[resourceName]: models.map((model) => {
// Use internal serializer to serialize the model correctly
// according to our mirage serializers
const modelData =
this.server.serializerOrRegistry.serialize(model);
[underscore(resourceNames[singularize(resourceName)])]: models.map(
(model) => {
// Use internal serializer to serialize the model correctly
// according to our mirage serializers
const modelData =
this.server.serializerOrRegistry.serialize(model);

// Serialize the data properly to standard JSON as that is what
// we're expecting from the cache daemon response
return JSON.parse(JSON.stringify(modelData));
}),
// Serialize the data properly to standard JSON as that is what
// we're expecting from the cache daemon response
return JSON.parse(JSON.stringify(modelData));
},
),
});
});
};
Expand Down
23 changes: 16 additions & 7 deletions addons/api/addon/handlers/cache-daemon-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { inject as service } from '@ember/service';
import { getOwner, setOwner } from '@ember/application';
import { generateMQLExpression } from '../utils/mql-query';
import { paginateResults } from '../utils/paginate-results';
import { underscore } from '@ember/string';

/**
* Not all types are yet supported by the cache daemon so we'll
Expand Down Expand Up @@ -94,12 +95,14 @@ export default class CacheDaemonHandler {
const sessionData = this.session.data?.authenticated;
const auth_token_id = sessionData?.id;
const token = sessionData?.token;
const resourceName = resourceNames[type];

remainingQuery = {
...remainingQuery,
query: searchQuery,
auth_token_id,
token,
resource: resourceNames[type],
resource: resourceName,
};

let cacheDaemonResults = {};
Expand Down Expand Up @@ -130,18 +133,15 @@ export default class CacheDaemonHandler {
}
} else {
__electronLog?.error(
'Failed to search cache daemon; falling back to search controller',
`Failed to search cache daemon for ${resourceName}. Error:`,
e.message,
);

return fetchControllerData(context, next);
}
}

// Currently returns with a singular top level field with resource name
// e.g. { targets: [...] } or { sessions: [..] }
// So this just unwraps to the array, or undefined
const [results] = Object.values(cacheDaemonResults);
const results = cacheDaemonResults[underscore(resourceName)];
const payload = { items: paginateResults(results, page, pageSize) };

const schema = store.modelFor(type);
Expand All @@ -167,7 +167,16 @@ export default class CacheDaemonHandler {
// This isn't conventional but is better than returning an ArrayProxy
// or EmberArray since the ember store query method asserts it has to be an array
// so we can't just return an object.
records.meta = { totalItems: results?.length ?? 0 };
// Also include whether the results are incomplete or is still refreshing
// as part of the response
records.meta = {
totalItems: results?.length ?? 0,
isLoadIncomplete: cacheDaemonResults.incomplete ?? false,
// Sometimes the refresh status returns an error status if it takes too long but it's still refreshing
isCacheRefreshing:
cacheDaemonResults.refresh_status !== 'not-refreshing',
};

return records;
}
default:
Expand Down
17 changes: 5 additions & 12 deletions addons/core/addon/components/loading-button/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
SPDX-License-Identifier: BUSL-1.1
}}

<Rose::Button
...attributes
@style='inline-link-action'
@iconLeft={{if
this.isLoading
'flight-icons/svg/loading-16'
'flight-icons/svg/reload-16'
}}
class={{if this.isLoading 'loading-button is-loading' 'loading-button'}}
<Hds::Button
@text={{t 'actions.refresh'}}
@color='secondary'
@icon={{if this.isLoading 'loading' 'reload'}}
@disabled={{this.isLoading}}
{{on 'click' this.toggleRefresh}}
>
{{yield}}
</Rose::Button>
/>
23 changes: 14 additions & 9 deletions addons/core/addon/components/toolbar-refresher/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
SPDX-License-Identifier: BUSL-1.1
}}

{{#if this.lastRefreshed}}
<Rose::Toolbar::Info>
{{relative-datetime-live this.lastRefreshed}}
</Rose::Toolbar::Info>
{{/if}}

<LoadingButton @onClick={{this.onClick}}>
{{t 'actions.refresh'}}
</LoadingButton>
<div class='toolbar-refresher'>
{{#if (has-block)}}
{{yield}}
{{else}}
{{#if this.lastRefreshed}}
<Hds::Text::Body @tag='p' @color='faint'>
{{relative-datetime-live this.lastRefreshed}}
</Hds::Text::Body>
{{/if}}
{{/if}}
<LoadingButton @onClick={{this.onClick}}>
{{t 'actions.refresh'}}
</LoadingButton>
</div>
2 changes: 1 addition & 1 deletion addons/core/addon/components/toolbar-refresher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class ToolbarRefresherComponent extends Component {
// =methods

/**
* Executes the click handler argument and trackes the time it completed.
* Executes the click handler argument and tracks the time it completed.
*/
@action
async onClick() {
Expand Down
33 changes: 15 additions & 18 deletions addons/core/addon/styles/addon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
display: flex;
flex-wrap: wrap;
align-items: center;
margin-bottom: 1rem;
gap: 0.5rem;

.filter-tag {
Expand All @@ -27,33 +26,19 @@
margin-top: 3rem;
}

.hds-segmented-group {
> * {
margin-bottom: 1rem;
}

.hds-segmented-group {
.hds-dropdown-toggle-button__text {
white-space: nowrap;
}
}

.hds-table {
margin-bottom: 1rem;
}

.search-filtering-toolbar {
display: flex;

// TODO: Remove these copied styles by migrating to HDS for the toolbar refresher component.
// The original styles assumed we were using the old toolbar component under a "rose-toolbar" class.
.rose-button-inline-link-action {
font-size: 0.8125rem;
line-height: 1.8461538462;
font-weight: 600;
color: var(--stark);
display: inline-block;
vertical-align: middle;
padding: 0.375rem 1rem;
}

> :last-child {
margin-left: auto;
}
Expand All @@ -67,3 +52,15 @@
color: var(--token-color-foreground-primary);
}
}

.toolbar-refresher {
display: flex;
align-items: center;
padding-left: 1rem;
gap: 1rem;

> .hds-text {
white-space: nowrap;
overflow: hidden;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupIntl } from 'ember-intl/test-support';

module('Integration | Component | loading-button', function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks, 'en-us');

test('it renders', async function (assert) {
await render(hbs`<LoadingButton />`);
assert.ok(find('.loading-button'));
assert.ok(find('.hds-button'));
});

test('it executes a function on refresh button click', async function (assert) {
assert.expect(2);
this.onClick = () => assert.ok(true, 'refresh was clicked');
await render(hbs`<LoadingButton @onClick={{this.onClick}} />`);
assert.ok(find('.loading-button'));
assert.ok(find('.hds-button'));
await click('button');
});
});
5 changes: 5 additions & 0 deletions addons/core/translations/states/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ loading:
title: Loading all items...
description: All of your {resource} are still loading. Please wait while we finish loading everything on screen.
generic-description: All of your resources are still loading. Please wait while we finish loading everything on screen.
incomplete-loading:
limit: Loaded the first {resultCount} results. Please narrow down your search or filters if the result you're looking for is not shown.
refreshing:
description: Updating cache...
tooltip: Some items may not appear until the cache is finished updating
4 changes: 1 addition & 3 deletions ui/admin/app/templates/scopes/scope/sessions/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@
/>
</S.Generic>
</Hds::SegmentedGroup>
<span>
<ToolbarRefresher @onClick={{this.refresh}} />
</span>
<ToolbarRefresher @onClick={{this.refresh}} />
</div>

<FilterTags @filters={{this.filters}} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@ export default class ScopesScopeProjectsSessionsIndexController extends Controll
);
}

/**
* Returns targets that are associated will all sessions the user has access to
* @returns {[TargetModel]}
*/
get availableTargets() {
const uniqueSessionTargetIds = new Set(
this.model.allSessions.map((session) => session.target_id),
);
return this.model.allTargets.filter((target) =>
uniqueSessionTargetIds.has(target.id),
);
}

/**
* Returns all status types for sessions
* @returns {[object]}
Expand Down Expand Up @@ -98,7 +85,7 @@ export default class ScopesScopeProjectsSessionsIndexController extends Controll
get filters() {
return {
allFilters: {
targets: this.availableTargets,
targets: this.model.associatedTargets,
status: this.sessionStatusOptions,
scopes: this.availableScopes,
},
Expand Down
18 changes: 2 additions & 16 deletions ui/desktop/app/controllers/scopes/scope/projects/targets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ export default class ScopesScopeProjectsTargetsIndexController extends Controlle

// =methods

get showFilters() {
return (
this.model.allTargets.length ||
this.types.length ||
this.search ||
this.availableSessions.length
);
}

/**
* Returns true if model is empty but we have a search term or filters
* @returns {boolean}
Expand Down Expand Up @@ -85,13 +76,8 @@ export default class ScopesScopeProjectsTargetsIndexController extends Controlle
* @returns {[ScopeModel]}
*/
get availableScopes() {
const uniqueTargetScopeIds = new Set(
this.model.allTargets.map((target) => target.scope.id),
);

return this.model.projects.filter((project) =>
uniqueTargetScopeIds.has(project.id),
);
// TODO: Make use of implicit scopes or when scopes are added to cache daemon
return this.model.projects;
}

get availableSessionOptions() {
Expand Down
Loading

0 comments on commit 76cc843

Please sign in to comment.