question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove unifiedDashboard feature flag and unused code

See original GitHub issue

Feature Description

With the Unified Dashboard epic complete, we should remove its feature flag and unused code from the repo.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • All usage of the unifiedDashboard feature flag should be removed, and all code that relies on unifiedDashboard === false should be removed.
  • The individual Module Screen PHP code (eg. /wp-admin/admin.php?page=googlesitekit-module-analytics) and accompanying JS code should be removed as it is no longer in use once Unified Dashboard is the default.
  • All relevant E2E tests should continue to pass, as the tests that are failing with the feature flags enabled are mostly testing functionality that is still relevant for the Unified Dashboard. The failing E2E tests are mostly around the “Post search” input and search functionality on the dashboard, and the date range picker. When the feature flags are always enabled (see this PR/test run: https://github.com/google/site-kit-wp/runs/6086002534?check_suite_focus=true#step:13:426) those tests fail and should be updated.
  • All stories that use “Legacy” or old-style dashboard UIs should be removed with VRTs updated, and new stories should be put in their place or added.

Implementation Brief

Before removing the feature flag from production code, force-enable the flag and fix (or remove) the failing tests. Then, remove the feature flag and related code. Additional tests may be removed as part of this process.

Following this approach should provide a bit more certainty that the removal of the feature flag from production code doesn’t break anything.

Fix / Remove Tests

To force enable the flag, patch the JS function isFeatureEnabled and the PHP method Feature_Flags::enabled, as seen here:

https://github.com/google/site-kit-wp/blob/e5cb521ccb40c18912a16eca46b396ced2612eb6/assets/js/features/index.js#L33-L39

https://github.com/google/site-kit-wp/blob/e5cb521ccb40c18912a16eca46b396ced2612eb6/includes/Core/Util/Feature_Flags.php#L40-L47

At the time of writing the test failures comprise:

E2E tests

8 test failures across the following 4 files (see example run):

tests/e2e/specs/modules/search-console/dashboard-date-range.test.js
tests/e2e/specs/dashboard/search.test.js
tests/e2e/specs/modules/search-console/admin-bar.test.js
tests/e2e/specs/modules/analytics/dashboard-date-range.test.js

6 of these tests (spanning the first two files) are failing because they are trying to reference the old URLSearchWidget component, and will need to be updated to exercise the new search bar. The failing test in admin-bar.test.js expects to navigate to the old Entity Dashboard, and needs updating to look for a DOM element present on the new version instead. The failing test in dashboard-date-range.test.js is trying to exercise the legacy Module Dashboard and can be removed.

PHPUnit

3 failing tests, over 3 files, each in the test_register test (see example run):

tests/phpunit/integration/Modules/AdSenseTest.php
tests/phpunit/integration/Modules/AnalyticsTest.php
tests/phpunit/integration/Modules/Search_ConsoleTest.php

Each of these has the same cause, $this->register_screen_hook(); being no longer invoked once the unifiedDashboard feature flag is removed. They can be fixed by removing the check for the screen in googlesitekit_module_screens.

Ultimately, the googlesitekit_module_screens filter will no longer be used so all references to googlesitekit_module_screens in the test_register tests can in fact be removed, and the test_register_unified_dashboard tests can also be removed.

JS Tests

15 failing across 6 files (see example run):

Of these, four files have tests that specifically test for the case where unifiedDashboard is not enabled. These can be removed; the files also contain tests where unifiedDashboard is enabled and these can be cleaned up a bit to reflect this is now the default/only case. These files are:

assets/js/components/DashboardEntryPoint.test.js
assets/js/modules/adsense/datastore/base.test.js
assets/js/modules/analytics/datastore/base.test.js
assets/js/modules/search-console/datastore/base.test.js

The remaining two files test components which have conditional behaviour relating to the unifiedDashboard flag and the tests should be updated accordingly. These files are:

assets/js/components/UserMenu.test.js
assets/js/googlesitekit/widgets/components/WidgetAreaRenderer.test.js

Remove Feature Flag

  • Remove unifiedDashboard from feature-flags.json.
  • Remove all references to this feature flag, keeping the execution path where the flag is true and removing where false. Remove any unused/unreachable code. Take care to remove components which are no longer in use.

At the time of writing that entails (as entry points):

  • 4 files under includes/
  • 3 files under tests/phpunit/
  • 1 file under tests/e2e
  • 26 files under assets/js (excluding tests and stories: there are no story files that reference this feature flag)
  • 4 test files under assets/js (as mentioned above under Fix Tests)

Remove Module Screens and Legacy Widgets

PHP:

  • Remove the class Module_With_Screen_Trait and all code that is only used by or in conjunction with this class. For example all references to googlesitekit_module_screens, Permissions::VIEW_MODULE_DETAILS and Module::prepare_info_for_js can be removed.

JS:

  • Remove assets/js/googlesitekit-module.js and all components / styles that are only used by this entry point and not shared elsewhere.
  • Remove the googlesitekit-module entry point from webpack.config.js and remove the Script instance for googlesitekit-module from includes/Core/Assets/Assets.php.
  • Remove all use of screenWidgetContext and related code.
  • Remove the following widget contexts. For each of these contexts, examine the widget areas registered to that context via registerWidgetArea. For each of these areas, remove the area and examine the widget components registered to that area via registerWidget. For each of these components, check whether it’s still being used by a non-legacy context/area, and delete the component if it’s no longer in use.
// Legacy dashboard
CONTEXT_DASHBOARD
// Legacy entity dashboard
CONTEXT_PAGE_DASHBOARD
// Legacy module screens
CONTEXT_MODULE_ANALYTICS
CONTEXT_MODULE_ADSENSE
CONTEXT_MODULE_SEARCH_CONSOLE

Storybook

  • Review and update Storybook to ensure there are no out-dated or broken stories.
  • Update the VRT reference images.

QA Brief

  • Setup and configure the plugin on a brand new site or reset the plugin on an existing one.
    • Setup all the modules.
  • Check that the main dashboard, entity dashboard and settings screens work fine.

Changelog entry

  • N/A

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
aaemnnosttvcommented, May 3, 2022

I can’t see where Module::prepare_info_for_js is being used outside of Module_With_Screen_Trait (apart from the tests for Module itself) - am I missing some sort of obscure method call (or indeed, something obvious)?

@techanvil looks like you are correct, I thought this was used by Modules but I was confusing it with prepare_module_data_for_response.

IB ✅

1reaction
aaemnnosttvcommented, Apr 28, 2022

@techanvil that sounds good to me, especially since ZDS is still rolling out – let’s not block the removal of unifiedDashboard because of it. Unless these need to be done together then I would prefer them to happen separately anyways. I’ll create a new issue for ZDS and update the ACs for both.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cleaning Up Unused Flags - DevCycle Docs
Cleaning Up Unused Flags. Overview​. This article outlines practices to help minimize technical debt from feature flags. DevCycle's code ...
Read more >
Feature flags - GitLab Docs
Disable a feature flag for all environments · On the top bar, select Main menu > Projects and find your project. · On...
Read more >
How to Manage Outdated Feature Flags - Optimizely
On Feature Flag Removal Day, developers gather to swarm on removing their feature flags and archiving them in the Optimizely Features dashboard.
Read more >
Reducing feature flag tech debt - Medium
One way to minimize the tedium above is to write code that anticipates the future requirement of removing the feature flag and its...
Read more >
Find potential unused enabled feature flags and prune them ...
In this scenario, the feature flag can be removed for A but not for B. So this can result in a false positive....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found