From 69065c308f0679b9692aef85f728ad6382059178 Mon Sep 17 00:00:00 2001 From: Anna Vovchenko Date: Thu, 21 Aug 2025 23:23:49 +0300 Subject: [PATCH] Fix feature flags list The list should still load when the data structure is not as expected Changelog: fixed --- .../feature_flags/store/helpers.js | 2 +- app/assets/javascripts/feature_flags/utils.js | 2 +- .../components/feature_flags_table_spec.js | 20 ++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/feature_flags/store/helpers.js b/app/assets/javascripts/feature_flags/store/helpers.js index 300709f2771403..a7231f90be52ed 100644 --- a/app/assets/javascripts/feature_flags/store/helpers.js +++ b/app/assets/javascripts/feature_flags/store/helpers.js @@ -52,7 +52,7 @@ const mapStrategyToRails = (strategy) => { }; if (strategy.name === ROLLOUT_STRATEGY_GITLAB_USER_LIST) { - mappedStrategy.user_list_id = strategy.userList.id; + mappedStrategy.user_list_id = strategy.userList?.id; } return mappedStrategy; }; diff --git a/app/assets/javascripts/feature_flags/utils.js b/app/assets/javascripts/feature_flags/utils.js index 47deeab05714cf..f2eff68c638837 100644 --- a/app/assets/javascripts/feature_flags/utils.js +++ b/app/assets/javascripts/feature_flags/utils.js @@ -41,7 +41,7 @@ const badgeTextByType = { }, [ROLLOUT_STRATEGY_GITLAB_USER_LIST]: { name: s__('FeatureFlags|User List'), - parameters: ({ user_list: { name } }) => name, + parameters: (data) => data?.user_list?.name || '', }, }; diff --git a/spec/frontend/feature_flags/components/feature_flags_table_spec.js b/spec/frontend/feature_flags/components/feature_flags_table_spec.js index 7f01a510001fa2..688b374f66af2e 100644 --- a/spec/frontend/feature_flags/components/feature_flags_table_spec.js +++ b/spec/frontend/feature_flags/components/feature_flags_table_spec.js @@ -54,6 +54,20 @@ const getDefaultProps = () => ({ name: 'flag without description', description: '', }, + { + id: 3, + iid: 3, + active: true, + name: 'flag with invalid strategy', + scopes: [], + strategies: [ + { + name: ROLLOUT_STRATEGY_GITLAB_USER_LIST, + parameters: {}, + scopes: [{ environment_scope: '*' }], + }, + ], + }, ], }); @@ -220,7 +234,11 @@ describe('Feature flag table', () => { }); it('shows the name of a user list for user list', () => { - expect(labels.at(3).text()).toContain('User List - test list'); + expect(labels.at(3).text()).toBe('User List - test list: All Environments'); + }); + + it('shows the empty name of a user list if it is not provided', () => { + expect(labels.at(4).text()).toBe('User List: All Environments'); }); it('renders a feature flag without an iid', () => { -- GitLab