-
Notifications
You must be signed in to change notification settings - Fork 303
Fixes #38901 - Refactor sync status page with React #11565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeremylenz
wants to merge
6
commits into
Katello:master
Choose a base branch
from
jeremylenz:38901-sync-status-react
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,019
−15
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a0650e
Fixes #38901 - Redesign sync status page with React
jeremylenz d0459c5
Refs #38901 - Add redirect and improve test coverage
jeremylenz 1eba675
Refs #38901 - Fix test failures by removing unsupported ouiaId props
jeremylenz 4ec2ac3
Refs #38901 - Implement UX review feedback for sync status page
jeremylenz d864fde
Refs #38901 - Update tests for UX review changes
jeremylenz d006f78
Refs #38901 - Address AI code review feedback
jeremylenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| module Katello | ||
| class Api::V2::SyncStatusController < Api::V2::ApiController | ||
| include SyncManagementHelper::RepoMethods | ||
|
|
||
| before_action :find_optional_organization, :only => [:index, :poll, :sync] | ||
| before_action :find_repository, :only => [:destroy] | ||
|
|
||
| api :GET, "/sync_status", N_("Get sync status for all repositories in an organization") | ||
| param :organization_id, :number, :desc => N_("ID of an organization"), :required => false | ||
| def index | ||
| org = @organization || current_organization_object | ||
| fail HttpErrors::NotFound, _("Organization required") if org.nil? | ||
|
|
||
| products = org.library.products.readable | ||
| redhat_products, custom_products = products.partition(&:redhat?) | ||
| redhat_products.sort_by! { |p| p.name.downcase } | ||
| custom_products.sort_by! { |p| p.name.downcase } | ||
|
|
||
| sorted_products = redhat_products + custom_products | ||
|
|
||
| @product_tree = collect_repos(sorted_products, org.library, false) | ||
|
|
||
| # Filter out products and intermediate nodes with no repositories | ||
| @product_tree = filter_empty_nodes(@product_tree) | ||
|
|
||
| @repo_statuses = collect_all_repo_statuses(sorted_products, org.library) | ||
|
|
||
| respond_for_index(:collection => {:products => @product_tree, :repo_statuses => @repo_statuses}) | ||
| end | ||
|
|
||
| api :GET, "/sync_status/poll", N_("Poll sync status for specified repositories") | ||
| param :repository_ids, Array, :desc => N_("List of repository IDs to poll"), :required => true | ||
| param :organization_id, :number, :desc => N_("ID of an organization"), :required => false | ||
| def poll | ||
| repos = Repository.where(:id => params[:repository_ids]).readable | ||
| statuses = repos.map { |repo| format_sync_progress(repo) } | ||
|
|
||
| render :json => statuses | ||
| end | ||
|
|
||
| api :POST, "/sync_status/sync", N_("Synchronize repositories") | ||
| param :repository_ids, Array, :desc => N_("List of repository IDs to sync"), :required => true | ||
| param :organization_id, :number, :desc => N_("ID of an organization"), :required => false | ||
| def sync | ||
| collected = [] | ||
| repos = Repository.where(:id => params[:repository_ids]).syncable | ||
|
|
||
| repos.each do |repo| | ||
| if latest_task(repo).try(:state) != 'running' | ||
| ForemanTasks.async_task(::Actions::Katello::Repository::Sync, repo) | ||
| end | ||
| collected << format_sync_progress(repo) | ||
| end | ||
|
|
||
| render :json => collected | ||
| end | ||
|
|
||
| api :DELETE, "/sync_status/:id", N_("Cancel repository synchronization") | ||
| param :id, :number, :desc => N_("Repository ID"), :required => true | ||
| def destroy | ||
| @repository.cancel_dynflow_sync | ||
| render :json => {:message => _("Sync canceled")} | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def find_repository | ||
| @repository = Repository.where(:id => params[:id]).syncable.first | ||
| fail HttpErrors::NotFound, _("Repository not found or not syncable") if @repository.nil? | ||
| end | ||
|
|
||
| def format_sync_progress(repo) | ||
| ::Katello::SyncStatusPresenter.new(repo, latest_task(repo)).sync_progress | ||
| end | ||
|
|
||
| def latest_task(repo) | ||
| repo.latest_dynflow_sync | ||
| end | ||
|
|
||
| def collect_all_repo_statuses(products, env) | ||
| statuses = {} | ||
| products.each do |product| | ||
| product.repos(env).each do |repo| | ||
| statuses[repo.id] = format_sync_progress(repo) | ||
| end | ||
| end | ||
| statuses | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| object false | ||
|
|
||
| node :products do | ||
| @product_tree | ||
| end | ||
|
|
||
| node :repo_statuses do | ||
| @repo_statuses | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| collection @collection | ||
|
|
||
| attributes :id, :product_id, :progress, :sync_id, :state, :raw_state | ||
| attributes :start_time, :finish_time, :duration, :display_size, :size | ||
| attributes :is_running, :error_details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| collection @collection => :results | ||
|
|
||
| node do |item| | ||
| item | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| require 'katello_test_helper' | ||
|
|
||
| module Katello | ||
| class Api::V2::SyncStatusControllerTest < ActionController::TestCase | ||
| def models | ||
| @organization = get_organization | ||
| @repository = katello_repositories(:fedora_17_x86_64) | ||
| @product = katello_products(:fedora) | ||
| end | ||
|
|
||
| def permissions | ||
| @sync_permission = :sync_products | ||
| end | ||
|
|
||
| def build_task_stub | ||
| task_attrs = [:id, :label, :pending, :execution_plan, :resumable?, | ||
| :username, :started_at, :ended_at, :state, :result, :progress, | ||
| :input, :humanized, :cli_example, :errors].inject({}) { |h, k| h.update k => nil } | ||
| task_attrs[:output] = {} | ||
| stub('task', task_attrs).mimic!(::ForemanTasks::Task) | ||
| end | ||
|
|
||
| def setup | ||
| setup_controller_defaults_api | ||
| login_user(User.find(users(:admin).id)) | ||
| models | ||
| permissions | ||
| ForemanTasks.stubs(:async_task).returns(build_task_stub) | ||
| end | ||
|
|
||
| def test_index | ||
| @controller.expects(:collect_repos).returns([]) | ||
| @controller.expects(:collect_all_repo_statuses).returns({}) | ||
|
|
||
| get :index, params: { :organization_id => @organization.id } | ||
|
|
||
| assert_response :success | ||
| end | ||
|
|
||
| def test_poll | ||
| @controller.expects(:format_sync_progress).returns({}) | ||
|
|
||
| get :poll, params: { :repository_ids => [@repository.id], :organization_id => @organization.id } | ||
|
|
||
| assert_response :success | ||
| end | ||
|
|
||
| def test_sync | ||
| @controller.expects(:latest_task).returns(nil) | ||
| @controller.expects(:format_sync_progress).returns({}) | ||
|
|
||
| post :sync, params: { :repository_ids => [@repository.id], :organization_id => @organization.id } | ||
|
|
||
| assert_response :success | ||
| end | ||
|
|
||
| def test_destroy | ||
| Repository.any_instance.expects(:cancel_dynflow_sync) | ||
|
|
||
| delete :destroy, params: { :id => @repository.id } | ||
|
|
||
| assert_response :success | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Sticky toolbar and table header coordination | ||
| // Target the toolbar by its ouiaId with more specific selector | ||
| .pf-v5-c-toolbar.pf-m-sticky[data-ouia-component-id="sync-status-toolbar"] { | ||
| position: sticky; | ||
| top: 0; | ||
| z-index: 400; | ||
| box-shadow: none; | ||
| } | ||
|
|
||
| // Target the table by its ouiaId and offset the sticky header | ||
| .pf-v5-c-table[data-ouia-component-id="sync-status-table"] { | ||
| thead { | ||
| position: sticky; | ||
| top: 70px; | ||
| z-index: 300; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { API_OPERATIONS, get, post, APIActions } from 'foremanReact/redux/API'; | ||
| import { translate as __ } from 'foremanReact/common/I18n'; | ||
| import api, { orgId } from '../../services/api'; | ||
| import SYNC_STATUS_KEY, { | ||
| SYNC_STATUS_POLL_KEY, | ||
| SYNC_REPOSITORIES_KEY, | ||
| CANCEL_SYNC_KEY, | ||
| } from './SyncStatusConstants'; | ||
| import { getResponseErrorMsgs } from '../../utils/helpers'; | ||
|
|
||
| export const syncStatusErrorToast = error => getResponseErrorMsgs(error.response); | ||
|
|
||
| export const getSyncStatus = (extraParams = {}) => get({ | ||
| type: API_OPERATIONS.GET, | ||
| key: SYNC_STATUS_KEY, | ||
| url: api.getApiUrl('/sync_status'), | ||
| params: { | ||
| organization_id: orgId(), | ||
| ...extraParams, | ||
| }, | ||
| errorToast: error => syncStatusErrorToast(error), | ||
| }); | ||
|
|
||
| export const pollSyncStatus = (repositoryIds, extraParams = {}) => get({ | ||
| type: API_OPERATIONS.GET, | ||
| key: SYNC_STATUS_POLL_KEY, | ||
| url: api.getApiUrl('/sync_status/poll'), | ||
| params: { | ||
| repository_ids: repositoryIds, | ||
| organization_id: orgId(), | ||
| ...extraParams, | ||
| }, | ||
| errorToast: error => syncStatusErrorToast(error), | ||
| }); | ||
|
|
||
| export const syncRepositories = (repositoryIds, handleSuccess, handleError) => post({ | ||
| type: API_OPERATIONS.POST, | ||
| key: SYNC_REPOSITORIES_KEY, | ||
| url: api.getApiUrl('/sync_status/sync'), | ||
| params: { | ||
| repository_ids: repositoryIds, | ||
| organization_id: orgId(), | ||
| }, | ||
| handleSuccess: (response) => { | ||
| if (handleSuccess) { | ||
| handleSuccess(response); | ||
| } | ||
| // The API returns an array of sync status objects | ||
| // Just show a simple success message | ||
| return __('Repository synchronization started'); | ||
| }, | ||
| handleError, | ||
| successToast: () => __('Repository synchronization started'), | ||
| errorToast: (error) => { | ||
| const message = getResponseErrorMsgs(error?.response); | ||
| return message || __('Failed to start repository synchronization'); | ||
| }, | ||
| }); | ||
|
|
||
| export const cancelSync = (repositoryId, handleSuccess) => APIActions.delete({ | ||
| type: API_OPERATIONS.DELETE, | ||
| key: CANCEL_SYNC_KEY, | ||
| url: api.getApiUrl(`/sync_status/${repositoryId}`), | ||
| handleSuccess, | ||
| successToast: () => __('Sync canceled'), | ||
| errorToast: error => syncStatusErrorToast(error), | ||
| }); | ||
|
|
||
| export default getSyncStatus; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.