Skip to content

Commit 556043c

Browse files
thibaudbraultThibaud Brault
authored andcommitted
🗃️ replace TagLabel with Subject in db
1 parent c046b39 commit 556043c

File tree

8 files changed

+384
-387
lines changed

8 files changed

+384
-387
lines changed

client/src/scenes/Home/components/Searchbar/Searchbar.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Searchbar = ({ text, tags, loading, onTextChange, onTagsChange }) => {
1313
const intl = getIntl(Searchbar)
1414
const conf = useConfiguration()
1515

16-
const tagLabels = tags
16+
const subjects = tags
1717
.map(tag =>
1818
conf.tagCategories
1919
.reduce((acc, cat) => acc.concat(cat.labels), [])
@@ -45,7 +45,7 @@ const Searchbar = ({ text, tags, loading, onTextChange, onTagsChange }) => {
4545
<TagPicker
4646
label={intl('filter.tags')}
4747
icon="local_offer"
48-
tags={tagLabels}
48+
tags={subjects}
4949
onChange={onTagsChange}
5050
/>
5151
</div>

e2e/client.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const upsertConfigMutation = async apiContext => {
139139

140140
const tagsId = /* GraphQL */ `
141141
query GetAllTags {
142-
tagLabels {
142+
subjects {
143143
id
144144
name
145145
}
@@ -153,7 +153,7 @@ const tagsQuery = async apiContext => {
153153
}
154154
})
155155
const jsonRes = await res.json()
156-
const results = await jsonRes.data.tagLabels
156+
const results = await jsonRes.data.subjects
157157
const tag = results[0]
158158
const tagEdit = results[1]
159159
return { tag, tagEdit }

server/prisma/datamodel.graphql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type Flag {
6868
type Tag {
6969
id: ID! @unique @id
7070

71-
label: TagLabel @relation(name: "TagsLabel", link: TABLE)
71+
label: Subject @relation(name: "Tags", link: TABLE)
7272

7373
node: ZNode! @relation(name: "NodeTags")
7474
user: User! @relation(name: "UserTags", link: TABLE)
@@ -77,15 +77,15 @@ type Tag {
7777
updatedAt: DateTime! @updatedAt
7878
}
7979

80-
type TagLabel {
80+
type Subject {
8181
id: ID! @unique @id
8282

8383
name: String!
84-
tags: [Tag!]! @relation(name: "TagsLabel", onDelete: CASCADE)
84+
tags: [Tag!]! @relation(name: "Tags", onDelete: CASCADE)
8585
specialists: [User!]! @relation(name: "UserSpecialties", link: TABLE)
8686

8787
order: Int!
88-
category: TagCategory! @relation(name: "TagLabelsCategory", link: TABLE)
88+
category: TagCategory! @relation(name: "SubjectsCategory", link: TABLE)
8989

9090
createdAt: DateTime! @createdAt
9191
updatedAt: DateTime! @updatedAt
@@ -95,7 +95,7 @@ type TagCategory {
9595
id: ID! @unique @id
9696

9797
name: String!
98-
labels: [TagLabel!]! @relation(name: "TagLabelsCategory", onDelete: CASCADE)
98+
labels: [Subject!]! @relation(name: "SubjectsCategory", onDelete: CASCADE)
9999

100100
order: Int!
101101
configuration: Configuration! @relation(name: "ConfigurationTags", link: TABLE)
@@ -136,7 +136,7 @@ type User {
136136

137137
flags: [Flag!]! @relation(name: "UserFlags")
138138
tags: [Tag!]! @relation(name: "UserTags")
139-
specialties: [TagLabel!]! @relation(name: "UserSpecialties")
139+
specialties: [Subject!]! @relation(name: "UserSpecialties")
140140

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

server/scripts/tmp_tag_resync/part1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const resync = async (name, stage) => {
5050
)
5151
)
5252

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

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

6565
return Promise.all(
6666
tags.map(tag => {
67-
const tagLabel = tagLabels.find(label => label.name === tag.label)
68-
if (!tagLabel) {
67+
const subject = subjects.find(label => label.name === tag.label)
68+
if (!subject) {
6969
console.log(`Unknown tag "${tag.label}" on "${tag.id}"`)
7070
return
7171
}
7272
return prisma.mutation.updateTag({
7373
where: { id: tag.id },
7474
data: {
7575
// label: null, // I'll manually remove label. This is a security in case something goes wrong
76-
tagLabel: { connect: { id: tagLabel.id } }
76+
subject: { connect: { id: subject.id } }
7777
}
7878
})
7979
})

0 commit comments

Comments
 (0)