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

when calling a child from the parent the self.call method does not work #559

Open
acivitillo opened this issue Aug 6, 2023 · 4 comments

Comments

@acivitillo
Copy link

I have a create_chart() method and it works when I trigger it via unicorn:click from a button HTML element. However, when I trigger the same function from a parent component the js does not get triggered. Everything else works, the elements are correctly created, but the self.call() does not trigger the js.

class PageView(UnicornView):
    status = ""
    updated_status = False
    data = {}

    def get_data(self, reel_code: str = ""):
        signal_name = "ttd"
        con = sqlite3.connect("signals_lamination.sqlite")
        df = pandas.read_sql(
            f"""select * from signals_lamination 
                where signal_name='{signal_name}' 
                      and stack_id <> '#N/D' and reelcode_anode='{reel_code}'
            """,
            con=con,
        )
        self.data = df

        for child in self.children:
            if hasattr(child, "chart_data"):
                child.chart_data = df
                child.create_chart()
class ChartView(UnicornView):
    chart_data = {}
    chart = None
    chart_clicked = False

    def mount(self):
        print("testing chartview")
        if isinstance(self.chart_data, pandas.DataFrame):
            self.create_chart()

    def create_chart(self):
        chart = cpk_chart(
            self.chart_data,
            measurement_name="signal_value",
            lsl=104.45,
            tg=105,
            usl=105.7,
        )
        chart.save("chart.json")

        with open("chart.json", "r") as f:
            chart = json.load(f)
        self.chart_clicked = True
        self.chart = chart
        self.call("createChart", self.chart) #<-- this works if trigger the function with unicorn:click
        return chart
@adamghill
Copy link
Owner

Hmm, I don't think I've ever tried using self.call from within a child component. Can you create a PR with the smallest possible test case to replicate this in the example project? That way I can easily make sure that whatever fix I come up with will work. Thanks!

@acivitillo
Copy link
Author

Thanks for the quick response!

I have refactored the code in one component and it works, but of course we need to check it. I will send you a PR these days, trying to replicate the issue with the simplest code.

@acivitillo
Copy link
Author

Here is it: https://github.com/acivitillo/django_unicorn_call_issue

But now I notice the button call works but the HTTP POST call is sent to http://127.0.0.1:8000/unicorn/message/parent . Could this be the problem? I would expect the HTTP POST request to go to http://127.0.0.1:8000/unicorn/message/child if I am clicking a child button.

@acivitillo
Copy link
Author

any feedback?

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

No branches or pull requests

2 participants