Skip to content

Implement organization cluster agents mapping mutations

Issue: Workspaces Cluster Agents Admin Settings UI (#545241 - closed)

What does this MR do and why?

This is step 4 of the work to add Workspaces Agents Availability in the admin settings UI. The crux of this MR is to implement the create and delete organization cluster agent mapping mutation, which also required several refactors:

  1. Refactored the availability toggle to it's own component, which is also where the mutation gets executed. This allows us to encapsulate all the related mutation logic, such as loading and error handling, within one component.
  2. I opted to update the mappedAgents store in Apollo Cache instead of refetching queries when the mutation is successful because it results in less unnecessary DB calls and better UX (the entire table does not have to be reloaded). In order to satisfy this, I refactored the existing GetOrganizationWorkspacesClusterAgentsQuery component to watch for mappedAgents changes and to update the organization agent data when this occurs.

References

How to set up and validate locally

  1. Go to /rails/features/ in the GDK and enable the workspaces_agents_availability_admin feature flag.
  2. Create some agents with workspaces enabled in their configuration by following steps 11 and 12 from this documentation.
  3. Go to /admin/application_settings/general.
  4. Expand the Workspaces Agent Availability setting.
  5. See next section for more detailed validation steps

Screenshots or screen recordings

Screenshot/Recording Steps

demo.mov

  1. Block the GQL request URL to test out the query's component error handling.
  2. After unblocking the GQL request and refreshing the page, note that the table loads as expected.
  3. Toggle an agent:
    • If the agent is blocked, note that the create mapping mutation is executed. On success, the toggle has the correct state: Available.
    • If the agent is available, note that the delete mapping mutation is executed. On success, the toggle has the correct state: Blocked.
    • Note that there are no extra calls to the mappingAgents and organizationWorkspacesClusterAgents query.
  4. Move across pages, ensure that the agents that you have mapped/unmapped retains the correct state.

generic_error.png

Generic error:

  1. Pul this branch

  2. Update the mutation variable to an incorrect one:

    Patch

    diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue b/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue
    index 6d13d8a3287739..6700372cff7d27 100644
    --- a/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue
    +++ b/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue
    @@ -89,7 +89,6 @@ export default {
               variables: {
                 input: {
                   clusterAgentId: agentId,
    -              organizationId,
                 },
               },
               update(store, result) {
    
  3. Observe generic error message

mutation_error.png

Mutation error:

  1. Apply the following patch

    Patch

    diff --git a/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue b/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue
    index 6d13d8a3287739..ee374d540a2e8e 100644
    --- a/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue
    +++ b/ee/app/assets/javascripts/workspaces/admin_settings/components/availability_toggle.vue
    @@ -82,7 +82,7 @@ export default {
             this.loading = true;
             this.errorMessage = '';
     
    -        let hasMutationError = false;
    +        let hasMutationError = true;
     
             await this.$apollo.mutate({
               mutation,
    
  2. Note the correct error message is displayed:

    • If the toggle state is Available, error message should be: This agent is already blocked.
    • If the toggle state is Blocked, error message should be: This agent is already available.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Cindy Halim

Merge request reports

Loading