Skip to content

Commit

Permalink
Fixes #36807 - UX fixes and add update count action
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Oct 19, 2023
1 parent 06cf003 commit a64615b
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 220 deletions.
14 changes: 10 additions & 4 deletions app/models/katello/concerns/smart_proxy_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,11 @@ def update_content_counts!
new_content_counts[:content_view_versions][repo.content_view_version_id] ||= { repositories: {}}
# Store counts on capsule of archived repos which are reused across environment copies
# of the archived repo corresponding to each environment CV version is promoted to.
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.content_view_version.archived_repos.find_by(library_instance_id: repo.library_instance_id)&.id] = translated_counts
if repo.content_view_version.default?
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.id] = translated_counts
else
new_content_counts[:content_view_versions][repo.content_view_version_id][:repositories][repo.content_view_version.archived_repos.find_by(library_instance_id: repo.library_instance_id)&.id] = translated_counts
end
end
update(content_counts: new_content_counts)
end
Expand Down Expand Up @@ -424,10 +428,12 @@ def last_sync_audit
Audited::Audit.where(:auditable_id => self, :auditable_type => SmartProxy.name, action: "sync capsule").order(:created_at).last
end

def last_sync_time
task = sync_tasks.where.not(:ended_at => nil).where(:result => 'success').order(:ended_at).last
def last_sync_task
sync_tasks.where.not(:ended_at => nil).where(:result => 'success').order(:ended_at).last
end

task&.ended_at || last_sync_audit&.created_at&.to_s
def last_sync_time
last_sync_task&.ended_at || last_sync_audit&.created_at&.to_s
end

def environment_syncable?(env)
Expand Down
2 changes: 1 addition & 1 deletion app/services/katello/pulp3/repository_mirror.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def fetch_repository
end

def version_href
fetch_repository.latest_version_href
fetch_repository&.latest_version_href
end

def publication_href
Expand Down
2 changes: 1 addition & 1 deletion app/views/foreman/smart_proxies/_content_tab.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<%= javascript_include_tag *webpack_asset_paths('katello', extension: 'js') %>
<% @smartProxyId= @smart_proxy.id %>
<%= react_component('Content', smartProxyId: @smartProxyId,) %>
<%= react_component('Content', smartProxyId: @smartProxyId, organizationId: Organization.current.id,) %>
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
object @capsule

attribute :last_sync_time
node :last_sync_words do |_object|
@capsule&.last_sync_time ? time_ago_in_words(Time.parse(@capsule&.last_sync_time&.to_s)) : nil
end

attribute :download_policy

Expand All @@ -15,6 +18,10 @@ child :last_failed_sync_tasks => :last_failed_sync_tasks do
extends 'foreman_tasks/api/tasks/show'
end

child :last_sync_task => :last_sync_task do
extends 'foreman_tasks/api/tasks/show'
end

child @lifecycle_environments => :lifecycle_environments do
extends 'katello/api/v2/common/identifier'
extends 'katello/api/v2/common/org_reference'
Expand Down
3 changes: 1 addition & 2 deletions test/models/concerns/smart_proxy_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def test_update_content_counts
python_service.expects(:latest_content_counts).once.returns(python_counts)
repos = [yum_repo, file_repo, ansible_repo, container_repo,
ostree_repo, deb_repo, python_repo]
yum_repo.content_view_version.expects(:archived_repos).returns(::Katello::Repository.where(id: [yum_repo, file_repo, ansible_repo, container_repo,
ostree_repo, deb_repo, python_repo]))
yum_repo.content_view_version.expects(:default?).returns(true)
::Katello::SmartProxyHelper.any_instance.expects(:repositories_available_to_capsule).once.returns(repos)
@proxy.update_content_counts!
counts = @proxy.content_counts
Expand Down
14 changes: 11 additions & 3 deletions webpack/scenes/SmartProxy/Content.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import React from 'react';
import PropTypes from 'prop-types';
import SmartProxyExpandableTable from './SmartProxyExpandableTable';

const Content = ({ smartProxyId }) => (
<SmartProxyExpandableTable smartProxyId={smartProxyId} />
const Content = ({ smartProxyId, organizationId }) => (
<SmartProxyExpandableTable smartProxyId={smartProxyId} organizationId={organizationId} />
);

Content.propTypes = {
smartProxyId: PropTypes.number,
smartProxyId: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string, // The API can sometimes return strings
]),
organizationId: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string, // The API can sometimes return strings
]),
};

Content.defaultProps = {
smartProxyId: null,
organizationId: null,
};

export default Content;
3 changes: 2 additions & 1 deletion webpack/scenes/SmartProxy/ExpandableCvDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ExpandableCvDetails = ({ contentViews, counts }) => {
const columnHeaders = [
__('Content view'),
__('Last published'),
__('Synced to smart proxy'),
__('Synced'),
];
const { content_counts: contentCounts } = counts;
const expandedTableRows = useSet([]);
Expand Down Expand Up @@ -46,6 +46,7 @@ const ExpandableCvDetails = ({ contentViews, counts }) => {
<Tbody key={`${id} + ${version}`}isExpanded={isExpanded}>
<Tr key={version} ouiaId={cv.name}>
<Td
style={{ paddingTop: 0 }}
expand={{
rowIndex,
isExpanded,
Expand Down
12 changes: 7 additions & 5 deletions webpack/scenes/SmartProxy/ExpandedSmartProxyRepositories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import { translate as __ } from 'foremanReact/common/I18n';
import { DataList, DataListItem, DataListItemRow, DataListItemCells, DataListCell } from '@patternfly/react-core';
import AdditionalCapsuleContent from './AdditionalCapsuleContent';
import InactiveText from '../ContentViews/components/InactiveText';

const ExpandedSmartProxyRepositories = ({ contentCounts, repositories }) => {
const getRepositoryNameById = id => (repositories.find(repo =>
Expand All @@ -24,21 +25,22 @@ const ExpandedSmartProxyRepositories = ({ contentCounts, repositories }) => {
<DataListItemRow>
<DataListItemCells dataListCells={[
<DataListCell key="primary content">
<b>{__('Repositories')}</b>
<b>{__('Repository')}</b>
</DataListCell>,
<DataListCell key="Packages"><b>{__('Packages')}</b></DataListCell>,
<DataListCell key="Additional Content"><b>{__('Additional Content')}</b></DataListCell>,
<DataListCell key="Package count"><b>{__('Packages')}</b></DataListCell>,
<DataListCell key="Additional content"><b>{__('Additional content')}</b></DataListCell>,
]}
/>
</DataListItemRow>
</DataListItem>
{Object.keys(contentCounts).map((repo, index) => (
{Object.keys(contentCounts).length ? Object.keys(contentCounts).map((repo, index) => (
<DataListItem key={`${repo.id}-${index}`}>
<DataListItemRow>
<DataListItemCells dataListCells={dataListCellLists(repo)} />
</DataListItemRow>
</DataListItem>
))}
)) : <InactiveText text={__('No content available')} />
}
</DataList>
);
};
Expand Down
21 changes: 17 additions & 4 deletions webpack/scenes/SmartProxy/SmartProxyContentActions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { API_OPERATIONS, get } from 'foremanReact/redux/API';
import { API_OPERATIONS, get, post } from 'foremanReact/redux/API';
import { translate as __ } from 'foremanReact/common/I18n';
import api, { foremanApi, orgId } from '../../services/api';
import SMART_PROXY_CONTENT_KEY, { SMART_PROXY_KEY } from './SmartProxyContentConstants';
import SMART_PROXY_CONTENT_KEY, { SMART_PROXY_COUNTS_UPDATE_KEY, SMART_PROXY_KEY } from './SmartProxyContentConstants';
import { renderTaskStartedToast } from '../Tasks/helpers';
import { getResponseErrorMsgs } from '../../utils/helpers';

const getSmartProxyContent = ({ smartProxyId }) => get({
const getSmartProxyContent = ({ smartProxyId, organizationId }) => get({
type: API_OPERATIONS.GET,
key: SMART_PROXY_CONTENT_KEY,
url: api.getApiUrl(`/capsules/${smartProxyId}/content/sync?${orgId()}`),
url: api.getApiUrl(`/capsules/${smartProxyId}/content/sync?organization_id=${organizationId}`),
});

export const getSmartProxies = () => get({
Expand All @@ -15,4 +18,14 @@ export const getSmartProxies = () => get({
params: { organization_id: orgId(), per_page: 'all' },
});

export const updateSmartProxyContentCounts = smartProxyId => post({
type: API_OPERATIONS.POST,
key: SMART_PROXY_COUNTS_UPDATE_KEY,
url: api.getApiUrl(`/capsules/${smartProxyId}/content/update_counts`),
handleSuccess: (response) => {
renderTaskStartedToast(response?.data, __('Smart proxy content count refresh has started in the background'));
},
errorToast: error => __(`Something went wrong while refreshing content counts: ${getResponseErrorMsgs(error.response)}`),
});

export default getSmartProxyContent;
1 change: 1 addition & 0 deletions webpack/scenes/SmartProxy/SmartProxyContentConstants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const SMART_PROXY_CONTENT_KEY = 'SMART_PROXY_CONTENT';
export const SMART_PROXY_KEY = 'SMART_PROXY';
export const SMART_PROXY_COUNTS_UPDATE_KEY = 'SMART_PROXY_COUNTS_UPDATE_KEY';
export default SMART_PROXY_CONTENT_KEY;
164 changes: 0 additions & 164 deletions webpack/scenes/SmartProxy/SmartProxyContentTable.js

This file was deleted.

Loading

0 comments on commit a64615b

Please sign in to comment.