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

[ui-storagebrowser] adds file preview and save for files #3869

Merged
merged 6 commits into from
Oct 29, 2024

Conversation

ramprasadagarwal
Copy link
Collaborator

What changes were proposed in this pull request?

  • This PR adds the preview of different files types in the file browser

How was this patch tested?

  • Added unit tests for each file type

};

const handleSave = () =>
save({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now if we are establishing a pattern it is reasonable be a bit more picky than usual :-)

I thought about this during the other PR review. Doesn't it make more sense to handle the save success and failure here instead of at the top where we get the save function from the hook? That way the logic is grouped together.

save({...}).then(()=>{do stuff}).catch(...)

or if the error handling is done by the hook like in this example

const success = await save({...});
if (success ) {...}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Based on our conversation earlier, I researched a bit and found that the best flexible/scalable design pattern for this hook would be to have onSuccess and onError hook be placed on both the places, one in the hook initialisation and other while making the save function call.
I have changed the implemented for the hook as well.

Let me know your thoughts on this.


const StorageFilePage = ({ fileData }: { fileData: PathAndFileData }): JSX.Element => {
const { t } = i18nReact.useTranslation();
const [isEditing, setIsEditing] = React.useState(false);
const [fileContent, setFileContent] = React.useState(fileData.view?.contents);
const fileMetaData = useMemo(() => getFileMetaData(t, fileData), [t, fileData]);

const { loading: isSaving, save } = useSaveData(SAVE_FILE_API_URL, {
onSuccess: () => {
setIsEditing(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would disable editing as soon as the save button was clicked, not when successful. If save failed I would enable the editing again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Make sense. Noted and fixed.

@ramprasadagarwal ramprasadagarwal enabled auto-merge (squash) October 28, 2024 07:02
Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

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

Nice work!

@ramprasadagarwal ramprasadagarwal merged commit 0e94376 into master Oct 29, 2024
6 checks passed
@ramprasadagarwal ramprasadagarwal deleted the feat/preview-file-browser-1 branch October 29, 2024 07:51
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