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

fix: File watcher isn't initialized on start-up #398

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

Conversation

going-confetti
Copy link
Collaborator

@going-confetti going-confetti commented Jan 9, 2025

Description

  • Fix for the regression of the file watcher not being initialized and not working until you refresh the app
  • Fix for the file watcher that prevents not supported files from getting into the file trees
  • Groundwork for the test data support

How to Test

  • Check that fs-related stuff works as expected
    • Adding, deleting, renaming files
    • Existing links between generators and recordings
    • External scripts etc.

Fix for file watcher:

  1. While having the app open, open the scripts directory in Finder/Explorer
  2. Paste a non-js file (e.g. an image)
  3. Make sure it doesn't show up in the file tree

Groundwork for data files support:

  1. Restart the app
  2. Verify that the Data folder has been created in the studio workspace folder
  3. Open Sidebar.tsx
  4. Replace line 20 with const { recordings, generators, scripts, data } = useFiles(searchTerm)
  5. Add a new FileTree for data files:
<FileTree
  label="Test data"
  files={data}
  noFilesMessage="No scripts found"
/>
  1. Open the data folder in Finder/Explorer and paste a csv/json file into it
  2. Verify that the file shows up in the file tree
  3. Restart the app to make sure not only watcher, but also the getFiles handler works as expected

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (npm run lint) and all checks pass.
  • I have run tests locally (npm test) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

@going-confetti going-confetti force-pushed the chore/improve-file-watch branch from 8b26276 to 0a67a00 Compare January 9, 2025 14:50
Copy link
Collaborator Author

@going-confetti going-confetti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review

}

function useFolderContent() {
const recordings = useStudioUIStore((s) => orderByFileName(s.recordings))
const generators = useStudioUIStore((s) => orderByFileName(s.generators))
const scripts = useStudioUIStore((s) => orderByFileName(s.scripts))
const data = useStudioUIStore((s) => orderByFileName(s.data))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps data is too vague?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards a yes, maybe we should be explicit and call it testData ?

Comment on lines +796 to +823
const file = getStudioFileFromPath(filePath)

if (!file) {
return
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, you could add an arbitrary file to one of the watched folders and ui:add-file would still be fired

}
}),
removeFile: (path) =>
removeFile: (file) =>
set((state) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now seems to me that it'd better to store all files in a flat map and get recordings, generators, scripts`, etc. using a zustand selector

return fileName.endsWith('.har')
}

export function isGenerator(fileName: string) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the addition of test data, this is no longer accurate. Instead, we get StudioFile objects from the main process, so we can always check the type directly

Comment on lines -34 to -38
export const scriptExists = async (fileName: string) => {
return window.studio.ui
.getFiles()
.then((files) => files.scripts.includes(fileName))
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed, because we always have the current list of files in the ui store

@going-confetti going-confetti marked this pull request as ready for review January 9, 2025 15:16
@going-confetti going-confetti requested a review from a team as a code owner January 9, 2025 15:16
@@ -82,7 +82,7 @@
"@tanstack/react-query": "^5.55.4",
"@vitejs/plugin-react": "^4.3.1",
"allotment": "^1.20.2",
"chokidar": "^3.6.0",
"chokidar": "^4.0.3",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sep 2024 update: v4 is out! It decreases dependency count from 13 to 1, removes support for globs, adds support for ESM / Common.js modules, and bumps minimum node.js version from v8 to v14. Check out upgrading.

Llandy3d
Llandy3d previously approved these changes Jan 9, 2025
Copy link
Member

@Llandy3d Llandy3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

}

function useFolderContent() {
const recordings = useStudioUIStore((s) => orderByFileName(s.recordings))
const generators = useStudioUIStore((s) => orderByFileName(s.generators))
const scripts = useStudioUIStore((s) => orderByFileName(s.scripts))
const data = useStudioUIStore((s) => orderByFileName(s.data))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning towards a yes, maybe we should be explicit and call it testData ?

Copy link
Collaborator

@cristianoventura cristianoventura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I agree with renaming instances of data to test data.

src/components/Layout/Sidebar/Sidebar.tsx Outdated Show resolved Hide resolved
@@ -5,3 +5,4 @@ export const PROJECT_PATH = path.join(app.getPath('documents'), 'k6-studio')
export const RECORDINGS_PATH = path.join(PROJECT_PATH, 'Recordings')
export const GENERATORS_PATH = path.join(PROJECT_PATH, 'Generators')
export const SCRIPTS_PATH = path.join(PROJECT_PATH, 'Scripts')
export const DATA_PATH = path.join(PROJECT_PATH, 'Data')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the directory name should also be Test Data?

@going-confetti
Copy link
Collaborator Author

@Llandy3d @cristianoventura re: data/test data name - I've been meaning to ask product about this, will update the PR after I get an answer

@going-confetti going-confetti changed the title chore: Improve file watcher fix: File watcher isn't initialized on start-up Jan 10, 2025
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.

3 participants