Skip to content

Commit

Permalink
🗃️ replace TagLabel with Subject in db
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudbrault authored and Thibaud Brault committed Jun 8, 2023
1 parent c046b39 commit 556043c
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 387 deletions.
4 changes: 2 additions & 2 deletions client/src/scenes/Home/components/Searchbar/Searchbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Searchbar = ({ text, tags, loading, onTextChange, onTagsChange }) => {
const intl = getIntl(Searchbar)
const conf = useConfiguration()

const tagLabels = tags
const subjects = tags
.map(tag =>
conf.tagCategories
.reduce((acc, cat) => acc.concat(cat.labels), [])
Expand Down Expand Up @@ -45,7 +45,7 @@ const Searchbar = ({ text, tags, loading, onTextChange, onTagsChange }) => {
<TagPicker
label={intl('filter.tags')}
icon="local_offer"
tags={tagLabels}
tags={subjects}
onChange={onTagsChange}
/>
</div>
Expand Down
4 changes: 2 additions & 2 deletions e2e/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const upsertConfigMutation = async apiContext => {

const tagsId = /* GraphQL */ `
query GetAllTags {
tagLabels {
subjects {
id
name
}
Expand All @@ -153,7 +153,7 @@ const tagsQuery = async apiContext => {
}
})
const jsonRes = await res.json()
const results = await jsonRes.data.tagLabels
const results = await jsonRes.data.subjects
const tag = results[0]
const tagEdit = results[1]
return { tag, tagEdit }
Expand Down
12 changes: 6 additions & 6 deletions server/prisma/datamodel.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type Flag {
type Tag {
id: ID! @unique @id

label: TagLabel @relation(name: "TagsLabel", link: TABLE)
label: Subject @relation(name: "Tags", link: TABLE)

node: ZNode! @relation(name: "NodeTags")
user: User! @relation(name: "UserTags", link: TABLE)
Expand All @@ -77,15 +77,15 @@ type Tag {
updatedAt: DateTime! @updatedAt
}

type TagLabel {
type Subject {
id: ID! @unique @id

name: String!
tags: [Tag!]! @relation(name: "TagsLabel", onDelete: CASCADE)
tags: [Tag!]! @relation(name: "Tags", onDelete: CASCADE)
specialists: [User!]! @relation(name: "UserSpecialties", link: TABLE)

order: Int!
category: TagCategory! @relation(name: "TagLabelsCategory", link: TABLE)
category: TagCategory! @relation(name: "SubjectsCategory", link: TABLE)

createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
Expand All @@ -95,7 +95,7 @@ type TagCategory {
id: ID! @unique @id

name: String!
labels: [TagLabel!]! @relation(name: "TagLabelsCategory", onDelete: CASCADE)
labels: [Subject!]! @relation(name: "SubjectsCategory", onDelete: CASCADE)

order: Int!
configuration: Configuration! @relation(name: "ConfigurationTags", link: TABLE)
Expand Down Expand Up @@ -136,7 +136,7 @@ type User {

flags: [Flag!]! @relation(name: "UserFlags")
tags: [Tag!]! @relation(name: "UserTags")
specialties: [TagLabel!]! @relation(name: "UserSpecialties")
specialties: [Subject!]! @relation(name: "UserSpecialties")

history: [HistoryAction!]! @relation(name: "UserHistoryActions")

Expand Down
8 changes: 4 additions & 4 deletions server/scripts/tmp_tag_resync/part1.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const resync = async (name, stage) => {
)
)

const tagLabels = tagsCategories.reduce((acc, cat) => acc.concat(cat.labels), [])
const subjects = tagsCategories.reduce((acc, cat) => acc.concat(cat.labels), [])

const tags = await prisma.query.tags(
null,
Expand All @@ -64,16 +64,16 @@ const resync = async (name, stage) => {

return Promise.all(
tags.map(tag => {
const tagLabel = tagLabels.find(label => label.name === tag.label)
if (!tagLabel) {
const subject = subjects.find(label => label.name === tag.label)
if (!subject) {
console.log(`Unknown tag "${tag.label}" on "${tag.id}"`)
return
}
return prisma.mutation.updateTag({
where: { id: tag.id },
data: {
// label: null, // I'll manually remove label. This is a security in case something goes wrong
tagLabel: { connect: { id: tagLabel.id } }
subject: { connect: { id: subject.id } }
}
})
})
Expand Down
Loading

0 comments on commit 556043c

Please sign in to comment.