Skip to content

Feat/re prioritize field (STIT-494) - #174

Open
AlexAxthelm wants to merge 17 commits into
mainfrom
feat/re-prioritize-field
Open

Feat/re prioritize field (STIT-494)#174
AlexAxthelm wants to merge 17 commits into
mainfrom
feat/re-prioritize-field

Conversation

@AlexAxthelm

@AlexAxthelm AlexAxthelm commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

supersedes #164

Lets a resource:write curator reorder sources for each field in a resource, and persist in database (changing ordering for all users).

Builds on sql-only coalescing logic (#170)

  • Updates og_field_resource_source_priority table in DB to include field name (per field reordering rather than overall)
  • introduces a tiered ranking where explicitly ordered sources (have override) rank above sources with no override
  • Adds appropriate endpoints: PUT /oil-gas-fields/{id}/fields/{field}/sources/priority
  • includes draft frontend UI elements

@github-actions

Copy link
Copy Markdown

CD summary 1ead6de

Frontend: https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-174-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net
stitch-llm open pr-174-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_174 stitch-dev.postgres.database.azure.com 5432 pr_174
Jobs (2)
job image postgres_db api_url auth_mode
db-migrations ghcr.io/rmi/stitch-api:pr-174@sha256:9ee1c1a54eb6d503458a65e8d316e7adfeebd0604b65204dd5f474041e108110 pr_174
seed ghcr.io/rmi/stitch-seed:pr-174@sha256:8feea43e61e9dec4048aaca03e8b6e3d2d7862d7b664e131747e07c6d90c0984 https://pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io/api/v1 stitch-client-bearer-token
Images (4)
build_time commit_time git_sha image image_digest
2026-07-20T15:00:49Z 2026-07-20T15:00:31Z 2862088 ghcr.io/rmi/stitch-api:pr-174 ghcr.io/rmi/stitch-api:pr-174@sha256:9ee1c1a54eb6d503458a65e8d316e7adfeebd0604b65204dd5f474041e108110
2026-07-20T15:00:49Z 2026-07-20T15:00:31Z 2862088 ghcr.io/rmi/stitch-entity-linkage:pr-174 ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:c71bd03fa9a113f70d269b440fdc98619955ae2789a01fd21595dd617365608a
2026-07-20T15:00:51Z 2026-07-20T15:00:31Z 2862088 ghcr.io/rmi/stitch-seed:pr-174 ghcr.io/rmi/stitch-seed:pr-174@sha256:8feea43e61e9dec4048aaca03e8b6e3d2d7862d7b664e131747e07c6d90c0984
2026-07-20T15:00:54Z 2026-07-20T15:00:31Z 2862088 ghcr.io/rmi/stitch-stitch-llm:pr-174 ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:f4e98e8a6352452a5d38b67437d3ac9e16182c70641d4cbd5295f8bb63e1ae2c

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces per-field, per-source-record source-priority overrides (“curation”) so a curator can reorder which source wins for a specific field on a specific resource, and exposes that capability through a new API endpoint and a frontend edit/reorder UI.

Changes:

  • Backend: implement tiered, per-field override ranking (curated tier above default tier) and add a PUT endpoint to persist ordered source PKs for a field.
  • Frontend: add permission-gated “Edit/Save” UI to reorder source rows and call the new endpoint; add curated-row badging.
  • Data/model: re-key the override table to (resource_id, source_pk, colname) with audit columns; update shared view models/tests accordingly.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/stitch-ogsi/src/stitch/ogsi/model/init.py Updates OGFieldSourceValueView contract: priority is now rank position; adds is_override.
deployments/stitch-frontend/src/queries/api.js Adds updateFieldSourcePriority client call for the new PUT endpoint.
deployments/stitch-frontend/src/hooks/usePermissions.js New hook to cache /auth/me claims and expose permission checks.
deployments/stitch-frontend/src/components/ResourceFieldCard.test.jsx Expands tests for permission-gated edit controls, reorder/save behavior, and curated badges.
deployments/stitch-frontend/src/components/ResourceFieldCard.jsx Adds reorder UI/logic, permission gating, save flow, and “curated” labeling.
deployments/api/tests/routers/test_route_permissions.py Adds route-permission coverage for the new PUT endpoint.
deployments/api/tests/db/test_resource_actions.py Adds integration coverage for set/reorder behavior, validation, tiering, and new-source-after-curation behavior.
deployments/api/src/stitch/api/routers/oil_gas_fields.py Adds PUT /{id}/fields/{field}/sources/priority endpoint with permission enforcement and error mapping.
deployments/api/src/stitch/api/entities.py Adds SetFieldPriorityRequest request model (ordered_source_pks).
deployments/api/src/stitch/api/db/queries.py Refactors ranking to tiered ordering and adds field_source_candidates sharing ranking logic with coalescing.
deployments/api/src/stitch/api/db/og_field_resource_actions.py Implements set_field_source_priority write path and updates field-source read path to use shared ranked SQL.
deployments/api/src/stitch/api/db/model/resource.py Removes per-resource priority override usage from source listing helper (now default-priority only).
deployments/api/src/stitch/api/db/model/og_field_resource_source_priority.py Re-keys override table to per-field, per-record; adds audit mixins and colname constraint; adds create() helper.
deployments/api/alembic/versions/a3f5c2e9b1d4_per_field_source_record_priority.py Migration dropping/recreating override table with new PK columns, constraints, and audit fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deployments/api/src/stitch/api/db/queries.py
Comment thread deployments/stitch-frontend/src/queries/api.js
@AlexAxthelm AlexAxthelm changed the title Feat/re prioritize field Feat/re prioritize field (STIT-494) Jul 21, 2026
@github-actions

Copy link
Copy Markdown

CD summary 667af9c

Frontend: https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-174-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net
stitch-llm open pr-174-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_174 stitch-dev.postgres.database.azure.com 5432 pr_174
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-174@sha256:7910c4ab6a39b01187cd9c1a4dadbc49bbfba49520deb258d422491cbba9de56 pr_174
Images (4)
build_time commit_time git_sha image image_digest
2026-07-21T15:25:56Z 2026-07-21T15:25:34Z d402290 ghcr.io/rmi/stitch-api:pr-174 ghcr.io/rmi/stitch-api:pr-174@sha256:7910c4ab6a39b01187cd9c1a4dadbc49bbfba49520deb258d422491cbba9de56
2026-07-21T15:25:52Z 2026-07-21T15:25:34Z d402290 ghcr.io/rmi/stitch-entity-linkage:pr-174 ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:1e34571998729ab877f601f3425ae79959d2da8ccbecdd4e0ebeb553df18b329
2026-07-21T15:25:53Z 2026-07-21T15:25:34Z d402290 ghcr.io/rmi/stitch-seed:pr-174 ghcr.io/rmi/stitch-seed:pr-174@sha256:2365a948ff908f7d3848e24c4089d131e9ad9c0043c447bc5a1ed6e53ebd8963
2026-07-21T15:25:53Z 2026-07-21T15:25:34Z d402290 ghcr.io/rmi/stitch-stitch-llm:pr-174 ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:99a3786766e3e978f248cd3b1b9f46645c1d6dea33f4f3a04e443ebd537fe508

@github-actions

Copy link
Copy Markdown

CD summary 0868210

Frontend: https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-174-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net
stitch-llm open pr-174-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_174 stitch-dev.postgres.database.azure.com 5432 pr_174
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-174@sha256:53298f9a0f7125411c5ad7a1d8ac0e1e69162143f022010ec38323aefbc110f7 pr_174
Images (4)
build_time commit_time git_sha image image_digest
2026-07-30T13:13:05Z 2026-07-30T13:12:49Z 28f3cb0 ghcr.io/rmi/stitch-api:pr-174 ghcr.io/rmi/stitch-api:pr-174@sha256:53298f9a0f7125411c5ad7a1d8ac0e1e69162143f022010ec38323aefbc110f7
2026-07-30T13:13:12Z 2026-07-30T13:12:49Z 28f3cb0 ghcr.io/rmi/stitch-entity-linkage:pr-174 ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:0b96ee7f1d39419a8b0b57fa3810fce5ce169ced1d2c2a4556751cae5dff6d2f
2026-07-30T13:13:07Z 2026-07-30T13:12:49Z 28f3cb0 ghcr.io/rmi/stitch-seed:pr-174 ghcr.io/rmi/stitch-seed:pr-174@sha256:50521f32e46a2f76fa093dc32fd56e188e6bbe9c231c4bf0cff22698c3fc8f80
2026-07-30T13:13:05Z 2026-07-30T13:12:49Z 28f3cb0 ghcr.io/rmi/stitch-stitch-llm:pr-174 ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:f3379fd76a21e78ac7c891a85ed28eb86f51af02f2c06f2e89d8001e5dab405f

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

deployments/api/src/stitch/api/db/og_field_resource_actions.py:252

  • set_field_source_priority validates/reorders using licensed_sources, but then deletes all existing overrides for (resource_id, colname) regardless of licensing. A resource:write user who is only licensed to a subset of sources could therefore unintentionally wipe curated ordering for sources they cannot see, affecting other users’ coalescing results. Consider scoping the delete/replace to the eligible source_pks derived from field_source_candidates(...) when licensed_sources is applied (or otherwise ensure the endpoint operates on a complete, non-licensed-filtered snapshot).
    source_by_pk = {row.source_pk: row.source for row in rows}
    await session.execute(
        delete(OGFieldResourceSourcePriority).where(
            OGFieldResourceSourcePriority.resource_id == id,
            OGFieldResourceSourcePriority.colname == field,
        )
    )

@mbarlow12 mbarlow12 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Big one is a sneaky potential for users with differing read permissions to overwrite priorities to all sources on a resource + attribute. See the second comment.

Other notes:

  • do we need/want some kind of "reset to default" that deletes the rows from the overrides table?
  • more integration tests for the endpoint? might be able to test the permissions bug explicitly

Comment thread deployments/api/src/stitch/api/routers/oil_gas_fields.py Outdated
Comment thread deployments/api/src/stitch/api/db/og_field_resource_actions.py
Comment thread deployments/stitch-frontend/src/components/ResourceFieldCard.jsx
Base automatically changed from refactor/coalesce to main August 3, 2026 23:57
@AlexAxthelm AlexAxthelm mentioned this pull request Aug 4, 2026
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

CD summary 7dbe979

Database (1)
db_name postgres_host postgres_port postgres_db
pr_0174 stitch-dev.postgres.database.azure.com 5432 pr_0174
Images (4)
build_time commit_time git_sha image image_digest
2026-08-05T14:23:28Z 2026-08-05T14:23:07Z 3dd166e ghcr.io/rmi/stitch-api:pr-0174 ghcr.io/rmi/stitch-api:pr-0174@sha256:ec13a4c9c75cd5e24e01ac14397b7df4c8d3a39a6230fbbf01dba93d6c5ee6b6
2026-08-05T14:23:33Z 2026-08-05T14:23:07Z 3dd166e ghcr.io/rmi/stitch-entity-linkage:pr-0174 ghcr.io/rmi/stitch-entity-linkage:pr-0174@sha256:781c86bbcd05f9e650706d4479042662e0df550aca9a691be2ca449ff7658063
2026-08-05T14:23:30Z 2026-08-05T14:23:07Z 3dd166e ghcr.io/rmi/stitch-seed:pr-0174 ghcr.io/rmi/stitch-seed:pr-0174@sha256:477f142c3e52cdeb82803ad3323ae07ab4c7d9cd5b5e245b9edc4a0c3013d25c
2026-08-05T14:23:26Z 2026-08-05T14:23:07Z 3dd166e ghcr.io/rmi/stitch-stitch-llm:pr-0174 ghcr.io/rmi/stitch-stitch-llm:pr-0174@sha256:794f439adee32af4e53c9711f816f5d534cd4515a095c398b443cd04fc228584

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

CD summary ac8a23b

Frontend: https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-0174-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net
stitch-llm open pr-0174-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0174 stitch-dev.postgres.database.azure.com 5432 pr_0174
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0174@sha256:9b4e07ee0b452d8d6da9ccfdf79b1055a7f405528be3699a34dd88fca73179f6 pr_0174
Images (4)
build_time commit_time git_sha image image_digest
2026-08-05T16:49:37Z 2026-08-05T16:49:17Z 98bf28c ghcr.io/rmi/stitch-api:pr-0174 ghcr.io/rmi/stitch-api:pr-0174@sha256:9b4e07ee0b452d8d6da9ccfdf79b1055a7f405528be3699a34dd88fca73179f6
2026-08-05T16:49:35Z 2026-08-05T16:49:17Z 98bf28c ghcr.io/rmi/stitch-entity-linkage:pr-0174 ghcr.io/rmi/stitch-entity-linkage:pr-0174@sha256:042ab207da994910d57e539d0ad861b2bc5bd4b930fc01a6f6507363f9fd6480
2026-08-05T16:49:38Z 2026-08-05T16:49:17Z 98bf28c ghcr.io/rmi/stitch-seed:pr-0174 ghcr.io/rmi/stitch-seed:pr-0174@sha256:16570036e3059cef0d8948180fc1eb57f7a077697bd53acda09f33f2ccaa5ea3
2026-08-05T16:49:33Z 2026-08-05T16:49:17Z 98bf28c ghcr.io/rmi/stitch-stitch-llm:pr-0174 ghcr.io/rmi/stitch-stitch-llm:pr-0174@sha256:6d391d91c4cf88036ec01da2653868dc794782d082407fddf9c8b3c6c6811271

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

CD summary f7786fd

Frontend: https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-0174-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net
stitch-llm open pr-0174-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0174 stitch-dev.postgres.database.azure.com 5432 pr_0174
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0174@sha256:374b14127581ec89f81e17d180d2048a12d795f37684c043df7e0268d51f26da pr_0174
Images (4)
build_time commit_time git_sha image image_digest
2026-08-06T10:52:05Z 2026-08-06T10:51:44Z 8a115f3 ghcr.io/rmi/stitch-api:pr-0174 ghcr.io/rmi/stitch-api:pr-0174@sha256:374b14127581ec89f81e17d180d2048a12d795f37684c043df7e0268d51f26da
2026-08-06T10:52:01Z 2026-08-06T10:51:44Z 8a115f3 ghcr.io/rmi/stitch-entity-linkage:pr-0174 ghcr.io/rmi/stitch-entity-linkage:pr-0174@sha256:29f9ec82df17d48f2839feabb869dd14e098769e1cb1c61851402ad7013a6a70
2026-08-06T10:52:03Z 2026-08-06T10:51:44Z 8a115f3 ghcr.io/rmi/stitch-seed:pr-0174 ghcr.io/rmi/stitch-seed:pr-0174@sha256:eb10f7f85f7ea2641e922af5648493badae4504d926c44bfc28da464239febb3
2026-08-06T10:52:08Z 2026-08-06T10:51:44Z 8a115f3 ghcr.io/rmi/stitch-stitch-llm:pr-0174 ghcr.io/rmi/stitch-stitch-llm:pr-0174@sha256:645a574064f5715a3300d7ff844fe16190cf3e9f7c227a31d75be9dac9d5eb25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Comment thread deployments/stitch-frontend/src/components/ResourceFieldCard.jsx

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Suppressed comments (1)

deployments/stitch-frontend/src/components/ResourceFieldCard.jsx:404

  • The move controls remain enabled even when sourcesChanged is true. In that stale state, displayRows is derived from workingOrder.map(...).filter(Boolean), so visible row indices can diverge from workingOrder indices and a Move Up/Down click can swap the wrong ids in workingOrder (even though Save is disabled). Gate the move controls on !sourcesChanged (and/or disable them) to prevent inconsistent in-memory state while the panel is stale.
              editControls={
                isEditing && canReorder ? (
                  <MoveButtons

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

CD summary df652db

Frontend: https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io
entity-linkage open pr-0174-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io
frontend https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net
stitch-llm open pr-0174-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0174 stitch-dev.postgres.database.azure.com 5432 pr_0174
Jobs (2)
job image postgres_db api_url auth_mode
db-migrations ghcr.io/rmi/stitch-api:pr-0174@sha256:5b108875886a35b187b014b9e36fa7cf423c9e33d6964c496d43b81ae20a06ad pr_0174
seed ghcr.io/rmi/stitch-seed:pr-0174@sha256:352477f9471effd1ffe0d39ec4d9b6ccd87264f95fe935252048c7d55a45f0d1 https://pr-0174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io/api/v1 stitch-client-bearer-token
Images (4)
build_time commit_time git_sha image image_digest
2026-08-06T11:19:54Z 2026-08-06T11:19:32Z 9aa3692 ghcr.io/rmi/stitch-api:pr-0174 ghcr.io/rmi/stitch-api:pr-0174@sha256:5b108875886a35b187b014b9e36fa7cf423c9e33d6964c496d43b81ae20a06ad
2026-08-06T11:20:02Z 2026-08-06T11:19:32Z 9aa3692 ghcr.io/rmi/stitch-entity-linkage:pr-0174 ghcr.io/rmi/stitch-entity-linkage:pr-0174@sha256:4926b59186130df38f349eb916ffe9456176466b54a1f854340ee1741cf1b689
2026-08-06T11:19:55Z 2026-08-06T11:19:32Z 9aa3692 ghcr.io/rmi/stitch-seed:pr-0174 ghcr.io/rmi/stitch-seed:pr-0174@sha256:352477f9471effd1ffe0d39ec4d9b6ccd87264f95fe935252048c7d55a45f0d1
2026-08-06T11:19:58Z 2026-08-06T11:19:32Z 9aa3692 ghcr.io/rmi/stitch-stitch-llm:pr-0174 ghcr.io/rmi/stitch-stitch-llm:pr-0174@sha256:ac9d959c2cf8078801f18a598ab333ab97341dae596eb1c47ed902d496d91bf4

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

Successfully merging this pull request may close these issues.

3 participants