reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Refactor upload component and add styled upload component

Open Ifechukwu001 opened this issue 1 year ago β€’ 6 comments

Description

These changes add default styling to the upload component - It follows the same pattern as the form component, where the root method call accesses the unstyled component.

Some default styles were commented so as not to break a previous test in the rendering of forms (With permission, I'd like to refactor the test).

Closes #2967

All Submissions:

  • [ βœ… ] Have you followed the guidelines stated in CONTRIBUTING.md file?
  • [ βœ… ] Have you checked to ensure there aren't any other open Pull Requests for the desired change?

Type of change

  • [ βœ… ] New feature (non-breaking change which adds functionality)
  • [ βœ… ] This change requires a documentation update

New Feature Submission:

  • [ βœ… ] Does your submission pass the tests?
  • [ βœ… ] Have you linted your code locally prior to submission?

Changes To Core Features:

  • [ βœ… ] Have you added an explanation of what your changes do and why you'd like us to include them?
  • [ βœ… ] Have you written new tests for your core changes, as applicable?
  • [ βœ… ] Have you successfully ran tests with your changes locally?

Ifechukwu001 avatar Apr 08 '24 02:04 Ifechukwu001

I'll work on that as well

Ifechukwu001 avatar Apr 08 '24 13:04 Ifechukwu001

This is currently how the styled upload works.

image

image

image

image

Ifechukwu001 avatar Apr 09 '24 13:04 Ifechukwu001

I thought that calling the super() class method would set the variable, is there any need to set the is_used variable again?

Ifechukwu001 avatar Apr 22 '24 10:04 Ifechukwu001

I thought that calling the super() class method would set the variable, is there any need to set the is_used variable again?

This will only set the is_used in StyledUpload, but the framework enable the upload features when Upload.is_used is true, so it need to be set.

image

Simply adding the line Upload.is_used = True inside the StyledUpload.create is enough to make it work.

Lendemor avatar Apr 22 '24 11:04 Lendemor

I'm curious, I don't understand how the react component works as I haven't used React before, but If we decide to do super().is_used = True is that the same as Upload.is_used = True?

Ifechukwu001 avatar Apr 23 '24 16:04 Ifechukwu001

I'm curious, I don't understand how the react component works as I haven't used React before, but If we decide to do super().is_used = True is that the same as Upload.is_used = True?

In that case it has nothing to do with React, it's purely a python situation, if you try super().is_used = True it will throw an error saying super doesn't have an is_used attribute.

Test with the following example :

class Foo:
    is_used = False

    @classmethod
    def create(cls):
        cls.is_used = True
        return cls()

class Bar:
    is_used = False

    @classmethod
    def create(cls):
        cls.is_used = True
        return super()

Bar.create()

print(Foo.is_used, Bar.is_used)

Lendemor avatar Apr 23 '24 17:04 Lendemor