Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintaining the Currency of Recently Added and Updated Samples #1727

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Zakariathr22
Copy link
Contributor

@Zakariathr22 Zakariathr22 commented Jan 14, 2025

Description

This PR addresses the issue of outdated samples in the "Recently Added" and "Recently Updated" sections of the homepage, the only change is set the recently updated and added samples in ControlInfoData.json

Motivation and Context

  • It proposes a process for regularly verifying and updating these sections to reflect the latest changes made to the gallery.
  • By ensuring that only the most current and relevant samples are displayed, this update will improve user experience, highlight community contributions, and provide better visibility for recent additions and improvements.
  • Closes Keeping Recently Added and Updated Samples Up to Date #1726

How Has This Been Tested?

Manually Tested

How Were the Samples Selected?

I hope this approach will be adopted and implemented with every new release.

For Latest Updated Samples:

To determine the latest updated samples, I created a PowerShell script that identifies files that have been modified based on their latest commit status. The script works by retrieving the last commit date and the status of each file, filtering out only those that have been modified. The resulting list is then sorted by the commit date to ensure the most recent updates are displayed.

# Replace "ControlPages" with your target directory
$currentFolder = "ControlPages"

$filesWithDetails = git ls-tree -r HEAD --name-only $currentFolder | ForEach-Object { 
    $file = $_

    # Check if the file is directly in the current folder (no further slashes after $currentFolder/)
    if ($file -match "^$currentFolder/[^/]+$") {
        # Get the last commit date in ISO format (yyyy-MM-dd HH:mm:ss)
        $lastCommitDate = git log -1 --format="%ai" -- $file

        # Get the status of the file (Modified only)
        $commitStatus = git log -1 --name-status -- $file | Select-String -Pattern "^M" | ForEach-Object { $_.Line.Split()[0] }

        # Only include files with a "Modified" status
        if ($commitStatus -eq "M") {
            [PSCustomObject]@{
                File = $file.Substring($currentFolder.Length + 1) # Remove the ControlPages/ part
                LastCommitDate = $lastCommitDate
            }
        }
    }
}

# Sort by LastCommitDate (ISO format ensures proper sorting) in descending order
$sortedFiles = $filesWithDetails | Sort-Object LastCommitDate -Descending

# To track which base names have already been displayed
$displayedBaseNames = @{}

# Variable to hold the final string output
$outputString = ""

$sortedFiles | ForEach-Object {
    # Remove .xaml.cs and .xaml extensions
    $fileName = $_.File -replace '\.xaml\.cs$', '' -replace '\.xaml$', ''

    # Remove "Page" from the file name
    $fileName = $fileName -replace 'Page$', ''

    # Check if this base name has been displayed already
    if (-not $displayedBaseNames.Contains($fileName)) {
        # Mark this base name as displayed
        $displayedBaseNames[$fileName] = $true
        
        # Append the file name to the output string
        $outputString += $fileName + "`n"
    }
}

# Display the final result
Write-Output $outputString

Based on the results of this script, the latest 15 updated samples are:
TreeView, ListView, TeachingTip, TitleBar, ScrollView, FilePicker, CompactSizing, ScratchPad, CaptureElementPreview, SplitView, NumberBox, TabView, MenuFlyout, XamlUICommand, AutoSuggestBox.

For Latest Added Samples:

To identify the latest added samples, I created a PowerShell script that looks for the first commit where a file was added. The script checks for files that were added to the repository and sorts them by their addition date. This provides a list of the most recently introduced samples.

# Replace "ControlPages" with your target directory
$currentFolder = "ControlPages"

$filesWithDetails = git ls-tree -r HEAD --name-only $currentFolder | ForEach-Object { 
    $file = $_

    # Check if the file is directly in the current folder (no further slashes after $currentFolder/)
    if ($file -match "^$currentFolder/[^/]+$") {
        # Get the first "add" commit for the file
        $firstAddCommit = git log --diff-filter=A --reverse --format="%ai" -- $file | Select-Object -First 1

        # Only include files with an "add" commit
        if ($firstAddCommit) {
            [PSCustomObject]@{
                File = $file.Substring($currentFolder.Length + 1) # Remove the ControlPages/ part
                FirstAddCommitDate = $firstAddCommit
            }
        }
    }
}

# Sort by FirstAddCommitDate (ISO format ensures proper sorting) in descending order
$sortedFiles = $filesWithDetails | Sort-Object FirstAddCommitDate -Descending

# To track which base names have already been displayed
$displayedBaseNames = @{}

# Variable to hold the final string output
$outputString = ""

$sortedFiles | ForEach-Object {
    # Remove .xaml.cs and .xaml extensions
    $fileName = $_.File -replace '\.xaml\.cs$', '' -replace '\.xaml$', ''

    # Remove "Page" from the file name
    $fileName = $fileName -replace 'Page$', ''

    # Check if this base name has been displayed already
    if (-not $displayedBaseNames.Contains($fileName)) {
        # Mark this base name as displayed
        $displayedBaseNames[$fileName] = $true
        
        # Append the file name to the output string
        $outputString += $fileName + "`n"
    }
}

# Display the final result
Write-Output $outputString

Based on the results of this script, the latest 10 added samples are:
Popup, ScratchPad, MapControl, SelectorBar, CaptureElementPreview, AnnotatedScrollBar, ItemsView, ScrollView, InfoBadge, Viewbox.

Screenshots:

Home page
image

Scripts results

  • First script
    image
  • Second script
    image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@Zakariathr22
Copy link
Contributor Author

@marcelwgn @niels9001 Could you please provide a quick review of this?

@karkarl
Copy link
Collaborator

karkarl commented Jan 15, 2025

Thanks for the contribution @Zakariathr22, this is fantastic!

Instead of setting IsUpdated to false, can you update the script to simply remove the entire line? Also if you can check in the script too under some ./tools/ directory, that'll be great!

@Zakariathr22
Copy link
Contributor Author

@karkarl
Sorry, I didn't mention that depending on the results of these two scripts I changed in the ControlInfoData.json file manually; they are just displaying the latest added and updated samples.

Also if you can check in the script too under some ./tools/ directory, that'll be great!

I've set the scripts codes in the PR. Feel free to go ahead with it if you think it would improve things (as I may not be available in these few days 😊)

Thanks again for your feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keeping Recently Added and Updated Samples Up to Date
2 participants