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

Add API support for table settings to store record summary template #1391

Merged
merged 36 commits into from
Jul 14, 2022

Conversation

silentninja
Copy link
Contributor

@silentninja silentninja commented May 20, 2022

Related to #944. This PR adds support for using a templated string which can contain referent column ids for summarising a foreign key column. The column ids would then be replaced with equivalent value of the foreign key referent record.

This PR uses the first column value of the referent table as a default summary template.

API schema:

GET /api/db/v0/tables/<id>/settings/

[
  {
    "id": 1287,
    "preview_settings": {
      "template": {278} is {279}, //278 and 279 are column id, if column {278} is a text column referring to a product and column {279} is a availability status of that product, the template would be rendered as "Cheese is in stock" 
      "customized": false
    }
  }
]

GET /api/db/v0/tables/<id>/settings/<id>/

{
  "id": 1287,
  "preview_settings": {
    "template": {278} is {279}, //278 and 279 are column id
    "customized": false
  }
}

PATCH /api/v0/tables/<id>/settings/<id>/

{
  "preview_settings": {
    "template": {278} is not {279}, //278 and 279 are column id, if column {278} is a text column referring to a product and column {279} is a availability status of that product, the template would be rendered as "Cheese is not in stock" 
    "customized": false
  }
}

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@silentninja silentninja changed the base branch from master to default-polymorphic-serializer May 23, 2022 14:49
Base automatically changed from default-polymorphic-serializer to master May 31, 2022 01:54
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2022

Codecov Report

Merging #1391 (05fa6bd) into master (05d7644) will increase coverage by 0.07%.
The diff coverage is 98.61%.

@@            Coverage Diff             @@
##           master    #1391      +/-   ##
==========================================
+ Coverage   92.61%   92.68%   +0.07%     
==========================================
  Files         130      132       +2     
  Lines        5521     5590      +69     
==========================================
+ Hits         5113     5181      +68     
- Misses        408      409       +1     
Flag Coverage Δ
pytest-backend 92.68% <98.61%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mathesar/models/base.py 95.83% <90.90%> (-0.21%) ⬇️
mathesar/api/db/viewsets/__init__.py 100.00% <100.00%> (ø)
mathesar/api/db/viewsets/table_settings.py 100.00% <100.00%> (ø)
mathesar/api/serializers/table_settings.py 100.00% <100.00%> (ø)
mathesar/signals.py 100.00% <100.00%> (ø)
mathesar/urls.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05d7644...05fa6bd. Read the comment docs.

dmos62
dmos62 previously requested changes May 31, 2022
Copy link
Contributor

@dmos62 dmos62 left a comment

Choose a reason for hiding this comment

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

I've only reviewed the tests. And, I only had a few minor notes. Thanks for the good looking tests!

mathesar/tests/api/test_table_settings_api.py Outdated Show resolved Hide resolved
mathesar/tests/api/test_table_settings_api.py Outdated Show resolved Hide resolved
@seancolsen
Copy link
Contributor

@silentninja can we close this PR now that we've decided to go a different direction?

@silentninja
Copy link
Contributor Author

silentninja commented Jun 15, 2022

@seancolsen Don't we need it to show the preview data, we should change the PR to use a preview template instead of the preview columns.

@silentninja silentninja mentioned this pull request Jun 17, 2022
7 tasks
@seancolsen seancolsen changed the title Add API support for record selector settings Add API support for table settings to store record summary expression Jun 24, 2022
@seancolsen seancolsen changed the title Add API support for table settings to store record summary expression Add API support for table settings to store record summary template Jun 24, 2022
@seancolsen
Copy link
Contributor

@silentninja and I chatted about this today and agreed to keep this PR, but we gave it a better title.

Remove `columns` field from table preview settings
@silentninja silentninja requested review from seancolsen and mathemancer and removed request for a team June 27, 2022 15:20
Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

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

Overall, I think it looks good, subject to @dmos62 's request w.r.t. the fixtures.

I'm curious: What would the interpretation of "is not" from the description examples be?

@silentninja silentninja added pr-status: review A PR awaiting review labels Jun 30, 2022
@silentninja silentninja requested a review from dmos62 June 30, 2022 06:19
@dmos62 dmos62 removed their request for review June 30, 2022 09:25
@dmos62
Copy link
Contributor

dmos62 commented Jun 30, 2022

Don't have additional input. I'm not up-to-date with the problem being solved by this PR, so I'll forego review.

@silentninja
Copy link
Contributor Author

silentninja commented Jul 4, 2022

Overall, I think it looks good, subject to @dmos62 's request w.r.t. the fixtures.

I'm curious: What would the interpretation of "is not" from the description examples be?

@mathemancer 278 and 279 are column id, if column {278} is a text column referring to a product and column {279} is a text column referring to availability status of that product, the template would be rendered as "Cheese is not in stock"

@silentninja silentninja assigned seancolsen and unassigned dmos62 Jul 5, 2022
@silentninja silentninja dismissed dmos62’s stale review July 5, 2022 08:48

Fixed the test cases as per the review

Copy link
Contributor

@mathemancer mathemancer left a comment

Choose a reason for hiding this comment

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

I think this looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-status: review A PR awaiting review
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants