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

Redirect component #30

Closed
samuelcolvin opened this issue Dec 1, 2023 · 4 comments
Closed

Redirect component #30

samuelcolvin opened this issue Dec 1, 2023 · 4 comments
Labels

Comments

@samuelcolvin
Copy link
Member

When renders forwards the user to another URL.

@KhaledAchech
Copy link

Hey @samuelcolvin,
I'm new to open-source contribution and I think I can work on this component.
Can I give it a try ?
I see that all of the components are defined as classes in the component folder and sorted by type of the component like the display file that holds all the display components; I was thinking we can put it the redirect component class in a routing file the

redirect component could be something like:

class Redirect(pydantic.BaseModel):
    url: str
    permanent: bool = False
    class_name: _class_name.ClassName = None
    type: typing.Literal['Redirect'] = 'Redirect

I'm not sure if we need a ClassName for a redirect component though.
Use case with fastApi (something similar to the documentation in the readme file):

app = FastAPI()
@app.get("/api/", response_model=FastUI, response_model_exclude_none=True)
def home_page() -> list[AnyComponent]:
    return [
        c.Page(
            components=[
                c.Heading(text='Home', level=2),
                c.Redirect(url='/api/user/1/', permanent=False),  # Redirect to user profile page
            ]
        ),
    ]
# The mentioned get user by id call:
@app.get("/api/user/{user_id}/", response_model=FastUI, response_model_exclude_none=True)
def user_profile(user_id: int) -> list[AnyComponent]:
    return [
       c.Page(
            components=[
                c.Heading(text=user.name, level=2),
                c.Link(components=[c.Text(text='Back')], on_click=BackEvent()),
                c.Details(data=user),
            ]
        )
    ]

I hope I understand everything correctly, let me know if it's still available and if I can work on it.

@samuelcolvin
Copy link
Member Author

Can I give it a try ?

Absolutely! yes please.

What you've said mostly looks right, except:

  • there's no need for permanent - since this "redirect is being done by javascript, theres no possibility to store that redirect in the browser
  • as you say, no need for class_name

Good luck! I'm looking forward to your PR.

@KhaledAchech
Copy link

Awesome! Thank you ^^

@samuelcolvin
Copy link
Member Author

This is fixed as part of #93 via the FireEvent component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants