Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsEditor/Extensions.cpp (C++)

Code before:

        _extensionPackageIdentifierTemplateSelector = Resources().Lookup(box_value(L"ExtensionPackageIdentifierTemplateSelector")).as<Editor::ExtensionPackageTemplateSelector>();

        Automation::AutomationProperties::SetName(ActiveExtensionsList(), RS_(L"Extensions_ActiveExtensionsHeader/Text"));
        Automation::AutomationProperties::SetName(ModifiedProfilesList(), RS_(L"Extensions_ModifiedProfilesHeader/Text"));
        Automation::AutomationProperties::SetName(AddedProfilesList(), RS_(L"Extensions_AddedProfilesHeader/Text"));
        Automation::AutomationProperties::SetName(AddedColorSchemesList(), RS_(L"Extensions_AddedColorSchemesHeader/Text"));
    }

    void Extensions::OnNavigatedTo(const NavigationEventArgs& e)
    {
        _ViewModel = e.Parameter().as<Editor::ExtensionsViewModel>();
        auto vmImpl = get_self<ExtensionsViewModel>(_ViewModel);
        vmImpl->ExtensionPackageIdentifierTemplateSelector(_extensionPackageIdentifierTemplateSelector);
        vmImpl->LazyLoadExtensions();
        vmImpl->MarkAsVisited();

        if (_ViewModel.IsExtensionView())
        {
            const auto& currentPkgVM = _ViewModel.CurrentExtensionPackage();
            const auto& currentPkg = currentPkgVM.Package();
            TraceLoggingWrite(
                g_hTerminalSettingsEditorProvider,
                "NavigatedToPage",
                TraceLoggingDescription("Event emitted when the user navigates to a page in the settings UI"),
                TraceLoggingValue(ExtensionPageId.data(), "PageId", "The identifier of the page that was navigated to"),
                TraceLoggingValue(true, "IsExtensionView", "If the page is representing a view of an extension. Otherwise, it represents a view of the root, which lists all extensions."),
                TraceLoggingValue(currentPkg.Source().c_str(), "FragmentSource", "The source of the fragment included in this extension package"),
                TraceLoggingValue(currentPkgVM.FragmentExtensions().Size(), "FragmentCount", "The number of fragments included in this extension package"),
                TraceLoggingValue(currentPkgVM.Enabled(), "Enabled", "The enabled status of the extension"),
                TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
        }
        else
        {
            TraceLoggingWrite(
                g_hTerminalSettingsEditorProvider,
                "NavigatedToPage",
                TraceLoggingDescription("Event emitted when the user navigates to a page in the settings UI"),
                TraceLoggingValue(ExtensionPageId.data(), "PageId", "The identifier of the page that was navigated to"),
                TraceLoggingValue(false, "IsExtensionView", "If the page is representing a view of an extension. Otherwise, it represents a view of the root, which lists all extensions."),
                TraceLoggingValue(_ViewModel.ExtensionPackages().Size(), "ExtensionPackageCount", "The number of extension packages displayed"),
                TraceLoggingValue(_ViewModel.ProfilesModified().Size(), "ProfilesModifiedCount", "The number of profiles modified by enabled extensions"),
                TraceLoggingValue(_ViewModel.ProfilesAdded().Size(), "ProfilesAddedCount", "The number of profiles added by enabled extensions"),
                TraceLoggingValue(_ViewModel.ColorSchemesAdded().Size(), "ColorSchemesAddedCount", "The number of color schemes added by enabled extensions"),
                TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
        }
    }

    void Extensions::ExtensionNavigator_Click(const IInspectable& sender, const RoutedEventArgs& /*args*/)

Review comment (refactor):
Thinking of changing the PageId here to `page.extensions.extensionView`. Better to abstract the subpage as an actual subpage. The fact that we reuse the UI for added/modified profiles and color schemes is an implementation detail.

Code after:

        Automation::AutomationProperties::SetName(ActiveExtensionsList(), RS_(L"Extensions_ActiveExtensionsHeader/Text"));
        Automation::AutomationProperties::SetName(ModifiedProfilesList(), RS_(L"Extensions_ModifiedProfilesHeader/Text"));
        Automation::AutomationProperties::SetName(AddedProfilesList(), RS_(L"Extensions_AddedProfilesHeader/Text"));
        Automation::AutomationProperties::SetName(AddedColorSchemesList(), RS_(L"Extensions_AddedColorSchemesHeader/Text"));
    }

    void Extensions::OnNavigatedTo(const NavigationEventArgs& e)
    {
        _ViewModel = e.Parameter().as<Editor::ExtensionsViewModel>();
        auto vmImpl = get_self<ExtensionsViewModel>(_ViewModel);
        vmImpl->ExtensionPackageIdentifierTemplateSelector(_extensionPackageIdentifierTemplateSelector);
        vmImpl->LazyLoadExtensions();
        vmImpl->MarkAsVisited();

        if (vmImpl->IsExtensionView())
        {
            const auto currentPkgVM = vmImpl->CurrentExtensionPackage();
            const auto currentPkg = currentPkgVM.Package();
            TraceLoggingWrite(
                g_hTerminalSettingsEditorProvider,
                "NavigatedToPage",
                TraceLoggingDescription("Event emitted when the user navigates to a page in the settings UI"),
                TraceLoggingValue("extensions.extensionView", "PageId", "The identifier of the page that was navigated to"),
                TraceLoggingValue(currentPkg.Source().c_str(), "FragmentSource", "The source of the fragment included in this extension package"),
                TraceLoggingValue(currentPkgVM.FragmentExtensions().Size(), "FragmentCount", "The number of fragments included in this extension package"),
                TraceLoggingValue(currentPkgVM.Enabled(), "Enabled", "The enabled status of the extension"),
                TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
        }
        else
        {
            TraceLoggingWrite(
                g_hTerminalSettingsEditorProvider,
                "NavigatedToPage",
                TraceLoggingDescription("Event emitted when the user navigates to a page in the settings UI"),
                TraceLoggingValue("extensions", "PageId", "The identifier of the page that was navigated to"),
                TraceLoggingValue(vmImpl->ExtensionPackages().Size(), "ExtensionPackageCount", "The number of extension packages displayed"),
                TraceLoggingValue(vmImpl->ProfilesModified().Size(), "ProfilesModifiedCount", "The number of profiles modified by enabled extensions"),
                TraceLoggingValue(vmImpl->ProfilesAdded().Size(), "ProfilesAddedCount", "The number of profiles added by enabled extensions"),
                TraceLoggingValue(vmImpl->ColorSchemesAdded().Size(), "ColorSchemesAddedCount", "The number of color schemes added by enabled extensions"),
                TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
                TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
        }
    }

    void Extensions::ExtensionNavigator_Click(const IInspectable& sender, const RoutedEventArgs& /*args*/)
    {
        const auto extPkgVM = sender.as<Controls::Button>().Tag().as<Editor::ExtensionPackageViewModel>();
        _ViewModel.CurrentExtensionPackage(extPkgVM);
    }