From 6ec1b8d93bddaa06afcd798787498682dc5bcdb1 Mon Sep 17 00:00:00 2001 From: Cindy Halim Date: Mon, 26 May 2025 15:58:55 +0900 Subject: [PATCH 1/3] Pass organization ID to Vue app - Pass organization ID to Vue app - Refactor to use Settings Block Vue component --- .../admin_settings/init_admin_settings_app.js | 13 +++- .../workspaces/admin_settings/pages/app.vue | 75 ++++++++++++------- .../workspaces/_agent_availability.html.haml | 8 +- .../_agent_availability.html.haml_spec.rb | 15 +++- 4 files changed, 75 insertions(+), 36 deletions(-) diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js b/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js index 54e81abaa3c02e..cdae7fe4c93d88 100644 --- a/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js +++ b/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js @@ -1,16 +1,25 @@ import Vue from 'vue'; +import { convertToGraphQLId } from '~/graphql_shared/utils'; +import { TYPE_ORGANIZATION } from '~/graphql_shared/constants'; + import WorkspacesAgentAvailabilityApp from './pages/app.vue'; const initWorkspacesAgentAvailabilityApp = () => { - const el = document.getElementById('js-workspaces-agent-availability-settings-body'); + const el = document.getElementById('js-workspaces-agent-availability-settings'); + + if (!el?.dataset) return null; - if (!el) return null; + const { organizationId, defaultExpanded } = el.dataset; return new Vue({ el, components: { WorkspacesAgentAvailabilityApp, }, + provide: { + organizationId: convertToGraphQLId(TYPE_ORGANIZATION, organizationId), + defaultExpanded: defaultExpanded === 'true', + }, render(createElement) { return createElement(WorkspacesAgentAvailabilityApp); }, diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue b/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue index f50a6239cf206f..bd2922502a0af1 100644 --- a/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue +++ b/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue @@ -1,6 +1,7 @@ diff --git a/ee/app/views/admin/application_settings/workspaces/_agent_availability.html.haml b/ee/app/views/admin/application_settings/workspaces/_agent_availability.html.haml index 3a41cf7eda62b1..7e7d9fd1448d54 100644 --- a/ee/app/views/admin/application_settings/workspaces/_agent_availability.html.haml +++ b/ee/app/views/admin/application_settings/workspaces/_agent_availability.html.haml @@ -1,9 +1,3 @@ - return unless ::License.feature_available?(:remote_development) && ::Feature.enabled?(:workspaces_agents_availability_admin, current_user) -= render ::Layouts::SettingsBlockComponent.new(s_('Workspaces|Workspaces Agent Availability'), - id: 'js-workspaces-agent-availability-settings', - expanded: expanded_by_default?) do |setting| - - setting.with_description do - = s_('Workspaces|Configure which Kubernetes agents are available for new workspaces. These settings do not affect existing workspaces.') - - setting.with_body do - #js-workspaces-agent-availability-settings-body +#js-workspaces-agent-availability-settings{ data: { organization_id: Current.organization.id, default_expanded: expanded_by_default?.to_s } } diff --git a/ee/spec/views/admin/application_settings/workspaces/_agent_availability.html.haml_spec.rb b/ee/spec/views/admin/application_settings/workspaces/_agent_availability.html.haml_spec.rb index 2cf14d3ae22c9e..95c53d52f8041a 100644 --- a/ee/spec/views/admin/application_settings/workspaces/_agent_availability.html.haml_spec.rb +++ b/ee/spec/views/admin/application_settings/workspaces/_agent_availability.html.haml_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' RSpec.describe 'admin/application_settings/_workspaces_agent_availability', feature_category: :workspaces do + let_it_be(:organization) { build_stubbed(:organization) } let_it_be(:user) { build_stubbed(:admin) } let_it_be(:app_settings) { build(:application_setting) } @@ -12,7 +13,11 @@ before do assign(:application_setting, app_settings) - allow(view).to receive(:current_user).and_return(user) + allow(view).to receive_messages( + current_user: user, + expanded_by_default?: true + ) + ::Current.organization = organization end [true, false].each do |license_enabled| @@ -34,4 +39,12 @@ end end end + + it "passes correct data to selector" do + stub_licensed_features(remote_development: true) + stub_feature_flags(workspaces_agents_availability_admin: true) + + expect(rendered).to have_selector("[data-organization-id='#{organization.id}']") + expect(rendered).to have_selector("[data-default-expanded='true']") + end end -- GitLab From 46149cc9ba377983b4f530a6be6584ec13145313 Mon Sep 17 00:00:00 2001 From: Cindy Halim Date: Tue, 27 May 2025 12:46:08 +0900 Subject: [PATCH 2/3] Add missing UI requirements --- .../components/availability_popover.vue | 32 ++++++++++++++ .../admin_settings/init_admin_settings_app.js | 3 +- .../workspaces/admin_settings/pages/app.vue | 26 +++++++++-- .../admin_settings/pages/app_spec.js | 44 +++++++++++++++++++ locale/gitlab.pot | 6 +++ 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 ee/app/assets/javascripts/workspaces/admin_settings/components/availability_popover.vue create mode 100644 ee/spec/frontend/workspaces/admin_settings/pages/app_spec.js diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_popover.vue b/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_popover.vue new file mode 100644 index 00000000000000..90451805acf0ce --- /dev/null +++ b/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_popover.vue @@ -0,0 +1,32 @@ + + diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js b/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js index cdae7fe4c93d88..b340f8711455d3 100644 --- a/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js +++ b/ee/app/assets/javascripts/workspaces/admin_settings/init_admin_settings_app.js @@ -1,6 +1,7 @@ import Vue from 'vue'; import { convertToGraphQLId } from '~/graphql_shared/utils'; import { TYPE_ORGANIZATION } from '~/graphql_shared/constants'; +import { parseBoolean } from '~/lib/utils/common_utils'; import WorkspacesAgentAvailabilityApp from './pages/app.vue'; @@ -18,7 +19,7 @@ const initWorkspacesAgentAvailabilityApp = () => { }, provide: { organizationId: convertToGraphQLId(TYPE_ORGANIZATION, organizationId), - defaultExpanded: defaultExpanded === 'true', + defaultExpanded: parseBoolean(defaultExpanded), }, render(createElement) { return createElement(WorkspacesAgentAvailabilityApp); diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue b/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue index bd2922502a0af1..f20f33f12e718b 100644 --- a/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue +++ b/ee/app/assets/javascripts/workspaces/admin_settings/pages/app.vue @@ -1,17 +1,20 @@