lovasoa / SQLpage

SQL-only webapp builder, empowering data analysts to build websites and applications quickly
https://sql.ophir.dev
MIT License
880 stars 62 forks source link

Parse JSON menu_item for SQLite and skip blank items #432

Closed pchemguy closed 1 week ago

pchemguy commented 1 week ago

Use parse_json helper to enable the use of the object form of "shell" with JSON containing menu items. Also in this pull request is an explicit filter on blank items (for example, generated via NULL AS menu_item or via '' AS menu_item). The latter feature simplifier creation of dynamic menus based on certain conditions, such as whether the user is authenticated or not.

Note, however, '' AS menu_item presently fails due to parse_json and should not be used. '{}' AS menu-item apparently works fine.

pchemguy commented 1 week ago

There was another issue. 'Help' AS menu_item would be passed to parse_json causing an unhandled error. So I had to create a more elaborate check removing the first parse_json and only keeping it in the "with" block where a preliminary check is passed.

lovasoa commented 1 week ago

This is super useful !

Can we add an example to the documentation for these "conditional" menu items ? Otherwise people would never know the possibility even exists.

pchemguy commented 1 week ago

I am working on small demo that shows Login/Signup button to an unauthenticated user and Logout/User Profile after authentication is complete. But this one should probably be included with other examples. For this purpose, I will make a single page demo where you can hide/show some menus via a form.

Actually, I have been using conditional menus without the changes in the present pull request. These patches just simplify conditional menu code, but this ability was there already.

pchemguy commented 1 week ago

I have added a basic example. A more elaborate example will be a part of separate pull request.