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

🎉 Tag Graph #3695

Merged
merged 25 commits into from
Jun 17, 2024
Merged

🎉 Tag Graph #3695

merged 25 commits into from
Jun 17, 2024

Conversation

ikesau
Copy link
Member

@ikesau ikesau commented Jun 6, 2024

Changes

  • Adds a new tag_graph table in the DB
    • Naively prepopulated based on the current parentId structure in the tags table
  • Adds the @dnd-kit/core library to our admin
  • Adds a new admin route /tag-graph to quickly and conveniently structure the tag graph
  • Updates the /tags admin UI to be a flat list of all tags and a simple form to add a new tag

This PR doesn't introduce any breaking changes or migrations to existing interactions with our tags table. Only once we've merged this and the data and research team has created a tag graph they're happy with, we can migrate functionality over to use the graph.

Demo

tag.graph.demo.mov

@ikesau ikesau self-assigned this Jun 6, 2024
@owidbot
Copy link
Contributor

owidbot commented Jun 6, 2024

Quick links (staging server):

Site Admin Wizard

Login: ssh owid@staging-site-tags-graph

SVG tester:

Number of differences (default views): 4530 (e117a3) ❌
Number of differences (all views): 2744 (934a71) ❌

Edited: 2024-06-17 19:57:36 UTC
Execution time: 1.13 seconds

@ikesau ikesau mentioned this pull request Jun 7, 2024
@ikesau ikesau requested a review from danyx23 June 10, 2024 15:36
db/db.ts Outdated
}

await knex("tag_graph").delete()
await knex("tag_graph").insert(tagGraphRows)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an easy way to do the update but then the updatedAt timestamp will not be useful information. I think being able to know which tags have been updated might be worth the slight complication to do a select all and then do the add/update/delete operations accordingly. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

The tag graph doesn't have updatedAt - do you think it should?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it can be really useful - e.g. when something goes wrong and you want to undo some change from yesterday or so it's really nice if that query can identify the three rows that actually changed instead of having to fetch all from a backup.

That said I'm not sure about whether it's worth changing this PR for it.

CREATE TABLE tag_graph (
parentId INT NOT NULL,
childId INT NOT NULL,
weight INT NOT NULL DEFAULT 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we maybe init this to 100 and sort it so that "heavier" items "sink down"? This makes it easier to modify individual elements up or down without quickly running into negative numbers which seem a bit weird. Totally minor thing of course and feel free to ignore

Copy link
Member Author

Choose a reason for hiding this comment

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

I hemmed and hawed on what the metaphor for "weight" should be - density, or weight-as-in-importance.

Ultimately I went with importance because pressing the up arrow should move the object up, and things at the top should be the most important.

I'll increase the default if for no reason other than reducing the risk of shenanigans with the number 0 😁


// create root tag
await queryRunner.query(`-- sql
INSERT INTO tags (name) VALUES ("tag-graph-root")`)
Copy link
Contributor

Choose a reason for hiding this comment

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

This leads to tag-graph-root being a valid tag in various selection dropdowns. Probably not a big deal since our users are not out to sabotage our system but maybe nice to eventually filter it out

Copy link
Contributor

@danyx23 danyx23 left a comment

Choose a reason for hiding this comment

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

Very nice work! I had a few comments/questions but nothing major.

Copy link
Contributor

@danyx23 danyx23 left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the tweaks! I'm a bit on the fence about the updatedAt field - I'll leave it to you to decide if you want to change it :)

@ikesau ikesau merged commit 587a97b into master Jun 17, 2024
21 checks passed
@ikesau ikesau deleted the tags-graph branch June 17, 2024 20:57
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