Geo Replicable List - Utilize backend replicator_class as SSoT
What/Why
Follow up for conversation found here: !33425 (comment 353165477)
@mkozono suggested we should align the frontend and backend replicable variables.
In legacy geo we utilized the replicable-type
property to:
- Build the RESTful API query (this is replaced by
graphql-field-name
in SSF) - Build the human-readable replicable title in the UI: https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/assets/javascripts/geo_replicable/store/getters.js#L1
In SSF geo we have more functionality provided to us in the backend from the @replicator_class
that we can utilize as a SSoT that already builds human readable names. Namely replicable_title
and replicable_title_plural
Proposal
Remove custom replicableTypeName
getter and usage. Create a helper that exposes all the relevant @repliactor_class
properties to the frontend and pass them up through HAML. This will allow us to pro-actively provide any current and potentially relevant information to the frontend and utilize the backend as the SSoT.
Implementation plan
- Extract the data map from
replicable_types
into a useable method and add the graphql fields.
# geo_helper.rb
def replicable_types
enabled_replicator_classes.map do |replicator_class|
replicable_class_data(replicator_class)
end
end
def replicable_class_data(replicator_class)
{
data_type: replicator_class.data_type,
data_type_title: replicator_class.data_type_title,
data_type_sort_order: replicator_class.data_type_sort_order,
title: replicator_class.replicable_title,
title_plural: replicator_class.replicable_title_plural,
name: replicator_class.replicable_name,
name_plural: replicator_class.replicable_name_plural,
graphql_field_name: replicator_class.graphql_field_name,
graphql_mutation_registry_class: replicator_class.graphql_mutation_registry_class,
verification_enabled: replicator_class.verification_enabled?
}
end
- Update usage in the
replicables/index.html.haml
to utilize the new helper.
#js-geo-replicable{ data: { "geo-replicable-empty-svg-path" => image_path("illustrations/empty-state/empty-geo-md.svg"),
"replicator-class-data" => replicable_class_data(@replicator_class).to_json,
"geo-target-site-id" => @target_node&.id,
"geo-current-site-id" => @current_node&.id } }
-
Update Vue app initialization with new data pattern in https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/assets/javascripts/geo_replicable/index.js
-
Remove
replicableTypeName
getter and replace usages with data provided from the replicator class
note: It may be worth flattening some of the data from replicatorClassData
in the Vuex store to avoid the need to make numerous rename changes.