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

Make TS TableRecord interface contain the record response instead of extending it #906

Closed
seancolsen opened this issue Dec 20, 2021 · 4 comments · Fixed by #1229
Closed
Assignees
Labels
type: bug Something isn't working work: frontend Related to frontend code in the mathesar_ui directory

Comments

@seancolsen
Copy link
Contributor

Problem

Here we have the following code:

interface TableRecordInResponse {
  [key: string]: unknown,
}

export interface TableRecord extends TableRecordInResponse {
  __identifier: string,
  __isAddPlaceholder?: boolean,
  __isNew?: boolean,
  __isGroupHeader?: boolean,
  __rowIndex?: number,
  __state?: string,
  __groupValues?: Record<string, unknown>,
}

That means that for one table cell, I might have an object like this:

{
  id: 1,
  Common Name: "Coast redwood",
  latin_name: "Sequoia sempervirens",
  height_in_meters: 115.92,
  name: "Hyperion",
  class: "Conifer",
  country: "United States",
  __identifier: "__0_normal_0",
  __rowIndex: 0,
  __state: "done",
}

This design leaves our internal front-end state data intermingled with the user data from postgres. What if I have a column named __state?

Example bug

  1. Go to "New Table" > "Import Data".

  2. Set "Import From" to "Clipboard".

  3. Paste the following:

    task,__state
    Foo,done
    Bar,error
    Baz,loading
    Bat,idle
  4. Click "Continue".

  5. Click "Finish Import".

  6. When the table loads, observe "done" printed for every row in the table.

  7. Expect to see "done", "error", "loading", and "idle" values in the rows respectively.

There's all sorts of other strange behavior when a column shares a name with one of our internal fields.

Solution

Instead of TableRecord extending TableRecordInResponse, I think TableRecord should contain TableRecordInResponse as follows:

interface TableRecordInResponse {
  [key: string]: unknown,
}

export interface TableRecord {
  record: TableRecordInResponse, // <-- new property
  identifier: string,
  isAddPlaceholder?: boolean,
  isNew?: boolean,
  isGroupHeader?: boolean,
  rowIndex?: number,
  state?: string,
  groupValues?: Record<string, unknown>,
}

This design also eliminates the need for the double underscores.

Notes

I'm marking this "draft" until we get an okay from @pavish

@seancolsen seancolsen added type: bug Something isn't working work: frontend Related to frontend code in the mathesar_ui directory status: draft labels Dec 20, 2021
@pavish
Copy link
Member

pavish commented Dec 20, 2021

@seancolsen The solution mentioned sounds good to me. We may also want to restructure the TableRecord interface to better suit our new grouping model.

@seancolsen
Copy link
Contributor Author

Thanks @pavish I'll try to work on this as part of the front end changes for #862

@seancolsen
Copy link
Contributor Author

@pavish I decided not to get into this today because I didn't want to add more complexity than necessary to the range grouping PR. We can take up this refactoring later.

@pavish
Copy link
Member

pavish commented Dec 21, 2021

@seancolsen That's fine. I was specifying the structure changes based on the new grouping model as a potential refactor we can do when this issue is picked up, we don't have to prioritize this right away.

@pavish pavish mentioned this issue Dec 21, 2021
7 tasks
@seancolsen seancolsen self-assigned this Mar 24, 2022
@seancolsen seancolsen removed the ready Ready for implementation label Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working work: frontend Related to frontend code in the mathesar_ui directory
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants