-
Notifications
You must be signed in to change notification settings - Fork 72
770 organize large projects #832
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
Open
Yabtse
wants to merge
4
commits into
wordplaydev:main
Choose a base branch
from
Yabtse:770-organize-large-projects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Console Testing Script for Search Functionality | ||
| * | ||
| * This script allows you to test the search functionality from the command line | ||
| * without needing to run the full application. | ||
| */ | ||
|
|
||
| import Fuse from 'fuse.js'; | ||
|
|
||
| // Mock project data for testing | ||
| const mockProjects = [ | ||
| { | ||
| project: { getName: () => 'Object Oriented Programming', getSources: () => [] }, | ||
| name: 'Object Oriented Programming', | ||
| files: [] | ||
| }, | ||
| { | ||
| project: { getName: () => 'Data Structures & Algorithms', getSources: () => [] }, | ||
| name: 'Data Structures & Algorithms', | ||
| files: [] | ||
| }, | ||
| { | ||
| project: { getName: () => 'Test Project', getSources: () => [] }, | ||
| name: 'Test Project', | ||
| files: [] | ||
| }, | ||
| { | ||
| project: { | ||
| getName: () => 'Main Project', | ||
| getSources: () => [ | ||
| { getPreferredName: () => 'main.wp' }, | ||
| { getPreferredName: () => 'utils.js' } | ||
| ] | ||
| }, | ||
| name: 'Main Project', | ||
| files: [ | ||
| { name: 'main.wp' }, | ||
| { name: 'utils.js' } | ||
| ] | ||
| }, | ||
| { | ||
| project: { getName: () => 'React Tutorial', getSources: () => [] }, | ||
| name: 'React Tutorial', | ||
| files: [] | ||
| }, | ||
| { | ||
| project: { getName: () => 'JavaScript Basics', getSources: () => [] }, | ||
| name: 'JavaScript Basics', | ||
| files: [] | ||
| }, | ||
| // Add archived projects for testing | ||
| { | ||
| project: { getName: () => 'Archived Math Project', getSources: () => [] }, | ||
| name: 'Archived Math Project', | ||
| files: [] | ||
| }, | ||
| { | ||
| project: { getName: () => 'Old Science Experiment', getSources: () => [] }, | ||
| name: 'Old Science Experiment', | ||
| files: [] | ||
| } | ||
| ]; | ||
|
|
||
| // Fuse.js configuration (same as in the app) | ||
| const fuseOptions = { | ||
| includeScore: true, | ||
| threshold: 0.4, | ||
| ignoreLocation: true, | ||
| keys: ['name', 'files.name'] | ||
| }; | ||
|
|
||
| const fuse = new Fuse(mockProjects, fuseOptions); | ||
|
|
||
| // Test cases | ||
| const testCases = [ | ||
| // Exact matches | ||
| 'Object Oriented Programming', | ||
| 'Test Project', | ||
| 'main.wp', | ||
|
|
||
| // Fuzzy matches with typos | ||
| 'Objct', | ||
| 'algoritm', | ||
| 'projct', | ||
| 'Testt', | ||
|
|
||
| // Partial matches | ||
| 'Object', | ||
| 'Test', | ||
| 'main', | ||
| 'React', | ||
|
|
||
| // Case insensitive | ||
| 'object', | ||
| 'TEST', | ||
| 'MAIN', | ||
|
|
||
| // Archived project searches | ||
| 'Archived', | ||
| 'Math', | ||
| 'Science', | ||
| 'Experiment', | ||
|
|
||
| // No matches | ||
| 'nonexistent', | ||
| 'xyz123', | ||
| '', | ||
|
|
||
| // Special characters | ||
| 'test@', | ||
| 'test#', | ||
| 'test$' | ||
| ]; | ||
|
|
||
| function testSearch(searchTerm) { | ||
| console.log(`\n🔍 Testing: "${searchTerm}"`); | ||
| console.log('─'.repeat(50)); | ||
|
|
||
| const results = fuse.search(searchTerm); | ||
|
|
||
| if (results.length === 0) { | ||
| console.log('❌ No results found'); | ||
| return; | ||
| } | ||
|
|
||
| console.log(`✅ Found ${results.length} result(s):`); | ||
|
|
||
| results.forEach((result, index) => { | ||
| const score = result.score ? result.score.toFixed(3) : 'N/A'; | ||
| console.log(` ${index + 1}. ${result.item.name} (score: ${score})`); | ||
|
|
||
| if (result.item.files.length > 0) { | ||
| console.log(` Files: ${result.item.files.map(f => f.name).join(', ')}`); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function runAllTests() { | ||
| console.log('🧪 Search Functionality Test Suite'); | ||
| console.log('='.repeat(50)); | ||
| console.log(`Testing ${testCases.length} search terms...`); | ||
|
|
||
| testCases.forEach(testSearch); | ||
|
|
||
| console.log('\n🎉 All tests completed!'); | ||
| } | ||
|
|
||
| function interactiveMode() { | ||
| console.log('🎮 Interactive Search Testing Mode'); | ||
| console.log('Type search terms to test (or "quit" to exit)'); | ||
| console.log('─'.repeat(50)); | ||
|
|
||
| const readline = require('readline'); | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
| const askQuestion = () => { | ||
| rl.question('🔍 Enter search term: ', (searchTerm) => { | ||
| if (searchTerm.toLowerCase() === 'quit') { | ||
| console.log('👋 Goodbye!'); | ||
| rl.close(); | ||
| return; | ||
| } | ||
|
|
||
| testSearch(searchTerm); | ||
| askQuestion(); | ||
| }); | ||
| }; | ||
|
|
||
| askQuestion(); | ||
| } | ||
|
|
||
| // Main execution | ||
| const args = process.argv.slice(2); | ||
|
|
||
| if (args.includes('--interactive') || args.includes('-i')) { | ||
| interactiveMode(); | ||
| } else if (args.includes('--help') || args.includes('-h')) { | ||
| console.log(` | ||
| Search Testing Script | ||
| Usage: | ||
| node test-search.js # Run all test cases | ||
| node test-search.js -i # Interactive mode | ||
| node test-search.js --help # Show this help | ||
| Options: | ||
| -i, --interactive Run in interactive mode | ||
| -h, --help Show this help message | ||
| `); | ||
| } else { | ||
| runAllTests(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,8 @@ | |
| children?: import('svelte').Snippet; | ||
| anonymize?: boolean; | ||
| showCollaborators?: boolean; | ||
| /** Search term for highlighting matches in project names */ | ||
| searchTerm?: string; | ||
| } | ||
|
|
||
| function findCharacterName(value: Value): string | null { | ||
|
|
@@ -71,6 +73,7 @@ | |
| children, | ||
| anonymize = true, | ||
| showCollaborators = false, | ||
| searchTerm = '', | ||
| }: Props = $props(); | ||
|
|
||
| // Clone the project and get its initial value, then stop the project's evaluator. | ||
|
|
@@ -166,6 +169,26 @@ | |
| const user = getUser(); | ||
|
|
||
| let path = $derived(link ?? project.getLink(true)); | ||
|
|
||
| // Highlight matching text in search results | ||
| function highlightText(text: string, searchTerm: string): string { | ||
| if (!searchTerm.trim()) return text; | ||
|
|
||
| const searchLower = searchTerm.toLowerCase(); | ||
| const textLower = text.toLowerCase(); | ||
|
|
||
| // First try exact substring match for highlighting | ||
| const index = textLower.indexOf(searchLower); | ||
| if (index !== -1) { | ||
| const before = text.substring(0, index); | ||
| const match = text.substring(index, index + searchTerm.length); | ||
| const after = text.substring(index + searchTerm.length); | ||
| return `${before}<mark class="search-highlight">${match}</mark>${after}`; | ||
| } | ||
|
|
||
| // If no exact match, don't highlight (fuzzy matches are found but not highlighted) | ||
| return text; | ||
| } | ||
| /** See if this is a public project being viewed by someone who isn't a creator or collaborator */ | ||
| let audience = $derived(isAudience($user, project)); | ||
|
|
||
|
|
@@ -223,14 +246,14 @@ | |
| {#if name} | ||
| <div class="name"> | ||
| {#if action} | ||
| {project.getName()} | ||
| {@html highlightText(project.getName(), searchTerm)} | ||
| {:else} | ||
| <Link to={path}> | ||
| {#if project.getName().length === 0}<em class="untitled" | ||
| >—</em | ||
| > | ||
| {:else} | ||
| {project.getName()}{/if}</Link | ||
| {@html highlightText(project.getName(), searchTerm)}{/if}</Link | ||
| > | ||
| {#if navigating && `${navigating.to?.url.pathname}${navigating.to?.url.search}` === path} | ||
| <Spinning />{:else}{@render children?.()} | ||
|
|
@@ -353,4 +376,12 @@ | |
| gap: var(--wordplay-spacing); | ||
| row-gap: var(--wordplay-spacing); | ||
| } | ||
|
|
||
| :global(.search-highlight) { | ||
|
||
| background-color: #ffffff; | ||
| color: #1f2937; | ||
| padding: 0 2px; | ||
| border-radius: 2px; | ||
| font-weight: 600; | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test should be integrated into the
vitestinfrastructure we have, rather than creating a standalone script. Write this using the test APIs so it's included in the standard test suite.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that there is a vitest test. What is this for then? Is this redundant? If so, remove it.