-
Notifications
You must be signed in to change notification settings - Fork 1
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
Validation #2
Validation #2
Conversation
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.
Hey @tasbi03, thank you for the PR 😊 A couple of changes required, let me know if you need further clarifications!
src/App.tsx
Outdated
console.log("validateTextInput called with userInput:", userInput); | ||
|
||
if (userInput && userInput.trim().length > 0) { | ||
// Optionally, validate if the input is a valid URL | ||
// For simplicity, we'll accept any non-empty text | ||
return { success: true }; | ||
} | ||
|
||
return { | ||
success: false, | ||
promptContent: | ||
"Please provide a valid URL or upload a file.", | ||
promptDuration: 3000, | ||
promptType: "error", | ||
}; | ||
}, |
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.
No need for validateTextInput
here, since chatDisabled
is already set to true.
src/App.tsx
Outdated
const validationResult = validateFile(files[0]); | ||
if (!validationResult.success) { | ||
console.error(validationResult.promptContent); | ||
// Return early to prevent success | ||
return { success: false }; | ||
} | ||
console.log("File uploaded successfully:", files[0]); | ||
} else { | ||
console.error("No file provided."); | ||
} |
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.
The validation for files were already performed in validateFileInput
, so we don't have to repeat any checks here. Sufficient to just log the files received.
"Thank you! Your input has been received. You passed the validation!", |
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 can go in a single line.
src/core/useRcbPlugin.ts
Outdated
@@ -17,7 +18,7 @@ import { getValidator } from "../utils/getValidator"; | |||
/** | |||
* Plugin hook that handles all the core logic. | |||
* | |||
* @param pluginConfig configurations for the plugin | |||
* @param pluginConfig Configurations for the plugin. |
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.
Unnecessary comment changes, there're some other ones in the rest of the code, can revert these changes :3
src/types/InputValidatorBlock.ts
Outdated
validateInput: (userInput?: string) => ValidationResult; | ||
|
||
export type InputValidatorBlock = Omit<Block, "file"> & { | ||
file?: (params: { files?: FileList }) => void | Promise<void>; |
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.
The file
attribute is already present in the original Block
type, not needed here.
src/types/InputValidatorBlock.ts
Outdated
export type InputValidatorBlock = Omit<Block, "file"> & { | ||
file?: (params: { files?: FileList }) => void | Promise<void>; | ||
validateTextInput?: (userInput?: string) => ValidationResult; | ||
validateFileInput?: (file?: File) => ValidationResult; |
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.
It's actually possible that users may submit multiple files, so we have to cater to that possibility.
} | ||
|
||
if (!event.detail.currPath) { |
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.
Hmm any reason this was removed in favour of splitting into 2 separate checks?
src/core/useRcbPlugin.ts
Outdated
console.error("No file uploaded."); | ||
event.preventDefault(); | ||
return; |
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.
Missing indentations, same for the code below.
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.
LGTM! There'll likely be some minor touch ups required, along with the adding of test cases but this can be tackled separately. Thanks for the PR again!
Description
This PR introduces comprehensive file upload handling to the
input-validator
plugin, including validation for uploaded files and improved control over input types. It separates the validation logic for text and file inputs, adds real-time feedback for validation errors, and ensures backward compatibility with existing text-only behavior. Additionally, it provides a newchatDisabled
property to control whether text input is allowed during specific flow blocks.Closes #1
What Change Does This PR Introduce?
Please select the relevant option(s):
Updated Implementation
File Upload Handling:
validateFileInput
to handle file-specific validation, ensuring:file
function to process file uploads asynchronously and validate uploaded files.Input Type Control:
chatDisabled
property to control whether text input is allowed during a particular flow block.chatDisabled: true
, only file uploads are permitted.Enhanced Validation Feedback:
Separation of Validation Logic:
validateTextInput
applies exclusively to text inputs.validateFileInput
applies exclusively to file uploads.Backward Compatibility:
Restored Original Styles:
Checklist
Testing
Verified the following scenarios:
chatDisabled: false
.chatDisabled: true
: Confirms that text input is disabled, allowing only file uploads.chatDisabled
is not set.Additional Notes
This PR enhances the plugin significantly by adding robust support for file uploads, improved feedback mechanisms, and flexible input control. It maintains backward compatibility while aligning with the plugin's design philosophy.
Let me know if any further adjustments or additional documentation are required!