这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@soorajshankar
Copy link
Member

@soorajshankar soorajshankar commented May 18, 2020

Description

Preserve data in local storage to ensure the user-provided data in raw SQL editor. data will preserve even after going to view modify tab.
image

Changelog

  • CHANGELOG.md is updated with user-facing content relevant to this PR.

Affected components

  • Server
  • Console
  • CLI
  • Docs
  • Community Content
  • Build System
  • Tests
  • Other (list it)

Related Issues

close #4798

Solution and Design

Since data/sql is used commonly a URL query string has been implemented. this helps to identify the container is mounted with modify mode or run sql mode.
using this identity, local storage value/redux value is used in the editor.

Steps to test and verify

  1. Go to Run SQL page and type some text.
  2. go to any view under tables section.
  3. click on modify tab.
  4. go back run SQL page

Current Behaviour

  1. Run SQL page shows the data from the lastly viewed view under table.

Expected Behaviour

  1. Run SQL page should show the user entered data from the text editor.

Limitations, known bugs & workarounds

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No
  • Yes
    • Updated docs with SQL for downgrading the catalog

Metadata

Does this PR add a new Metadata feature?

  • No
  • Yes
    • Does run_sql auto manages the new metadata through schema diffing?
      • Yes
      • Not required
    • Does run_sql auto manages the definitions of metadata on renaming?
      • Yes
      • Not required
    • Does export_metadata/replace_metadata supports the new metadata added?
      • Yes
      • Not required

GraphQL

  • No new GraphQL schema is generated
  • New GraphQL schema is being generated:
    • New types and typenames are correlated

Breaking changes

  • No Breaking changes

  • There are breaking changes:

    1. Metadata API

      Existing query types:

      • Modify args payload which is not backward compatible
      • Behavioural change of the API
      • Change in response JSON schema
      • Change in error code
    2. GraphQL API

      Schema Generation:

      • Change in any NamedType
      • Change in table field names

      Schema Resolve:-

      • Change in treatment of null value for any input fields
    3. Logging

      • Log JSON schema has changed
      • Log type names have changed

@hasura-bot
Copy link
Contributor

Review app for commit 38cfb44 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-38cfb448

@wawhal wawhal assigned rikinsk and unassigned beerose and wawhal May 19, 2020
Co-authored-by: Tirumarai Selvan <tirumarai.selvan@gmail.com>
Copy link
Contributor

@tirumaraiselvan tirumaraiselvan left a comment

Choose a reason for hiding this comment

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

changelog

@hasura-bot
Copy link
Contributor

Review app for commit 9651787 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-9651787b

Copy link
Member

@rikinsk rikinsk left a comment

Choose a reason for hiding this comment

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

@soorajshankar as we discussed, lets make modify of view happen in place and decouple it completely from the RawSQL page. We can allow the user to edit the view definition in the modify page itself and if we detect a change a Save button can be enabled.

Actually lets make the behaviour similar to the way we handle custom sql functions. The modify page willl have a code-block with the view definition and modify button which redirects to RawSQL page with the view definition prefilled

@rikinsk rikinsk added the c/console Related to console label May 19, 2020
@netlify
Copy link

netlify bot commented May 19, 2020

Deploy preview for hasura-docs ready!

Built with commit 3c4956e

https://deploy-preview-4810--hasura-docs.netlify.app

@soorajshankar
Copy link
Member Author

@rikinsk
Previous Behaviour
previous

This PR Behaviour
current

@hasura-bot
Copy link
Contributor

Review app for commit 43a1d38 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-43a1d388

@rikinsk rikinsk assigned beerose and unassigned rikinsk May 19, 2020
@rikinsk rikinsk requested a review from beerose May 19, 2020 10:04
Copy link
Member

@rikinsk rikinsk left a comment

Choose a reason for hiding this comment

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

UX approved

@hasura-bot
Copy link
Contributor

Review app for commit 467732e deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-467732e6

Copy link
Contributor

@beerose beerose left a comment

Choose a reason for hiding this comment

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

Left some comments.

> Alert
> NotesSection
@hasura-bot
Copy link
Contributor

Review app for commit 99c4a27 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-99c4a271

Copy link
Contributor

@beerose beerose left a comment

Choose a reason for hiding this comment

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

Instead of adding new state variable, we should implement the same solution as is now for modifying custom functions and work on how data is handled in Modify Actions. Right now when a view table is loaded, fetchViewDefinition function fetches view definition and stores it in RawSql/raw_sql, and this part should be decoupled. Raw SQL state shouldn't be updated on actions in the Modify view as they are two separate parts of the console.

sql: state.rawSQL.viewSql,

This sql value should be taken from the Modify state, thus fetchViewDefinition should dispatch an action that updates Modify state. Then we could use this as previously:

<ViewDefinitions modifyViewOnClick={modifyViewOnClick} sql={sql} />

And set raw_sql only if the user clicks modfiy and is redirected to the Raw SQL page.
For that we could actually use RawSqlButton component that is used for custom functions: https://github.com/hasura/graphql-engine/blob/master/console/src/components/Services/Data/TableModify/ComputedFieldsEditor.js#L305.


Btw, from the user perspective, let's say I have a query that I run very often. As long as it's persisted in local storage, everything is cool. But if I edit a view definition, it's quite a pity that my original query is overwritten in local storage. The same happens if I edit or create a custom function.

I see three possible solutions to this problem:

  1. Don't store SQL string in local storage when it's derived from view definition or custom function.
  2. Decouple modifying custom functions and views from the Raw SQL page and inline it on Modify pages.
  3. (My favorite) Create a history of executed queries in the Raw SQL page in a similar way as it is in the GraphiQL section (with a clear all button). Then we wouldn't need to worry about possible overrides and it would also be an extremely useful feature.

Thoughts @rikinsk?

@hasura-bot
Copy link
Contributor

Review app for commit ae6de04 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-ae6de043

@beerose
Copy link
Contributor

beerose commented May 26, 2020

@soorajshankar Can you take a look at the failing test?

@hasura-bot
Copy link
Contributor

Review app for commit b6298cf deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-b6298cf2

@hasura-bot
Copy link
Contributor

Review app for commit 12a1968 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-12a19689

@rikinsk
Copy link
Member

rikinsk commented May 27, 2020

@beerose

Don't store SQL string in local storage when it's derived from view definition or custom function.

This might be just as confusing as I would lose any edits I make to the edit view SQL on the Raw SQL page if I navigate. Typically I just expect the last content on the RawSQl page to persist so this doesnt seem ideal.

Decouple modifying custom functions and views from the Raw SQL page and inline it on Modify pages.

This would be the best solution but is a little tricky because we let the user execute any SQL and that can allow them to do unexpected things. e.g. if they drop the current view, the current page we are on will become a 404. If we can list all the possible end states and handle them or ensure that the user can only modify the current view (make the "create or replace view as " part of the statement fixed) this can be a good option.

(My favorite) Create a history of executed queries in the Raw SQL page in a similar way as it is in the GraphiQL section (with a clear all button). Then we wouldn't need to worry about possible overrides and it would also be an extremely useful feature.

This seems generally useful even beyond this issue and surprising no one has asked for this yet. Maybe we can create an issue and see the interest it gets and then decide when to pick it up.

@beerose
Copy link
Contributor

beerose commented May 27, 2020

@rikinsk I propose to keep the scope of this PR to only fix #4798, and for those two ideas (decoupling edit and query history) create issues and decide whether to do them or not later depending on the users' interest.

@rikinsk
Copy link
Member

rikinsk commented May 27, 2020

@rikinsk I propose to keep the scope of this PR to only fix #4798, and for those two ideas (decoupling edit and query history) create issues and decide whether to do them or not later depending on the users' interest.

Definitely. I think the current UX is good to go.

@hasura-bot
Copy link
Contributor

Review app for commit a6aad5c deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-a6aad5c3

@hasura-bot
Copy link
Contributor

Review app for commit 3c4956e deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-3c4956e6

@hasura-bot
Copy link
Contributor

Review app for commit 3879e81 deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-3879e81c

@beerose beerose self-requested a review May 29, 2020 07:36
@hasura-bot
Copy link
Contributor

Review app for commit c0cc2fe deployed to Heroku: https://hge-ci-pull-4810.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4810-c0cc2fe6

@rikinsk rikinsk changed the title Raw SQL preserve editor values #4798 console: fix visiting view modify page overwriting raw sql content May 29, 2020
@rikinsk rikinsk merged commit b2fd57a into hasura:master May 29, 2020
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-4810.herokuapp.com is deleted

stevefan1999-personal pushed a commit to stevefan1999-personal/graphql-engine that referenced this pull request Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/console Related to console

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raw sql page content gets overwritten when modify page for a view is visited

6 participants