Commit 1864450e authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '257864-order-agent-list' into 'master'

Order Cluster Agents by name

See merge request gitlab-org/gitlab!45165
parents c642c1e9 9e682947
......@@ -8,6 +8,7 @@ module Clusters
has_many :agent_tokens, class_name: 'Clusters::AgentToken'
scope :ordered_by_name, -> { order(:name) }
scope :with_name, -> (name) { where(name: name) }
validates :name,
......
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { sortBy } from 'lodash';
import AgentEmptyState from './agent_empty_state.vue';
import AgentTable from './agent_table.vue';
import getAgentsQuery from '../graphql/queries/get_agents.query.graphql';
......@@ -26,7 +25,7 @@ export default {
});
}
return sortBy(agentList, 'name');
return agentList;
},
},
},
......
......@@ -14,7 +14,7 @@ module Clusters
agents = project.cluster_agents
agents = agents.with_name(params[:name]) if params[:name].present?
agents
agents.ordered_by_name
end
private
......
---
title: Order cluster agents query by name
merge_request: 45165
author:
type: changed
......@@ -13,6 +13,20 @@ RSpec.describe Clusters::Agent do
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
describe 'scopes' do
describe '.ordered_by_name' do
let(:names) { %w(agent-d agent-b agent-a agent-c) }
subject { described_class.ordered_by_name }
before do
names.each do |name|
create(:cluster_agent, name: name)
end
end
it { expect(subject.map(&:name)).to eq(names.sort) }
end
describe '.with_name' do
let!(:matching_name) { create(:cluster_agent, name: 'matching-name') }
let!(:other_name) { create(:cluster_agent, name: 'other-name') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment