mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-12-24 12:29:05 +01:00
Adapt TagManagement to new urql version
This commit is contained in:
parent
1ac16516fe
commit
4bd1d30aa5
@ -15,33 +15,36 @@
|
|||||||
let pendingChange = false
|
let pendingChange = false
|
||||||
let isOpen = false
|
let isOpen = false
|
||||||
|
|
||||||
|
const client = getContextClient();
|
||||||
|
|
||||||
const createTagMutation = ({ type, name }) => {
|
const createTagMutation = ({ type, name }) => {
|
||||||
result = mutationStore({
|
return mutationStore({
|
||||||
client: getContextClient(),
|
client: client,
|
||||||
query: gql`mutation($type: String!, $name: String!) {
|
query: gql`mutation($type: String!, $name: String!) {
|
||||||
createTag(type: $type, name: $name) { id, type, name }
|
createTag(type: $type, name: $name) { id, type, name }
|
||||||
}`,
|
}`,
|
||||||
variables: { type, name}
|
variables: { type, name}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const addTagsToJobMutation = ({ job, tagIds }) => {
|
const addTagsToJobMutation = ({ job, tagIds }) => {
|
||||||
result = mutationStore({
|
return mutationStore({
|
||||||
client: getContextClient(),
|
client: client,
|
||||||
query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
|
query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
|
||||||
addTagsToJob(job: $job, tagIds: $tagIds) { id, type, name }
|
addTagsToJob(job: $job, tagIds: $tagIds) { id, type, name }
|
||||||
}`,
|
}`,
|
||||||
variables: {job, tagIds}
|
variables: {job, tagIds}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeTagsFromJobMutation = ({ job, tagIds }) => {
|
const removeTagsFromJobMutation = ({ job, tagIds }) => {
|
||||||
result = mutationStore({
|
return mutationStore({
|
||||||
client: getContextClient(),
|
client: client,
|
||||||
query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
|
query: gql`mutation($job: ID!, $tagIds: [ID!]!) {
|
||||||
removeTagsFromJob(job: $job, tagIds: $tagIds) { id, type, name }
|
removeTagsFromJob(job: $job, tagIds: $tagIds) { id, type, name }
|
||||||
}`
|
}`,
|
||||||
})
|
variables: {job, tagIds}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
let allTagsFiltered // $initialized is in there because when it becomes true, allTags is initailzed.
|
let allTagsFiltered // $initialized is in there because when it becomes true, allTags is initailzed.
|
||||||
@ -66,43 +69,47 @@
|
|||||||
|
|
||||||
function createTag(type, name) {
|
function createTag(type, name) {
|
||||||
pendingChange = true
|
pendingChange = true
|
||||||
return createTagMutation({ type: type, name: name })
|
createTagMutation({ type: type, name: name })
|
||||||
.then(res => {
|
.subscribe(res => {
|
||||||
if (res.error)
|
if (res.fetching === false && !res.error) {
|
||||||
throw res.error
|
|
||||||
|
|
||||||
pendingChange = false
|
pendingChange = false
|
||||||
allTags = [...allTags, res.data.createTag]
|
allTags = [...allTags, res.data.createTag]
|
||||||
newTagType = ''
|
newTagType = ''
|
||||||
newTagName = ''
|
newTagName = ''
|
||||||
return res.data.createTag
|
addTagToJob(res.data.createTag)
|
||||||
}, err => console.error(err))
|
} else if (res.fetching === false && res.error) {
|
||||||
|
throw res.error
|
||||||
|
// console.log('Error on subscription: ' + res.error)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function addTagToJob(tag) {
|
function addTagToJob(tag) {
|
||||||
pendingChange = tag.id
|
pendingChange = tag.id
|
||||||
addTagsToJobMutation({ job: job.id, tagIds: [tag.id] })
|
addTagsToJobMutation({ job: job.id, tagIds: [tag.id] })
|
||||||
.then(res => {
|
.subscribe(res => {
|
||||||
if (res.error)
|
if (res.fetching === false && !res.error) {
|
||||||
throw res.error
|
|
||||||
|
|
||||||
jobTags = job.tags = res.data.addTagsToJob;
|
jobTags = job.tags = res.data.addTagsToJob;
|
||||||
pendingChange = false;
|
pendingChange = false;
|
||||||
})
|
} else if (res.fetching === false && res.error) {
|
||||||
.catch(err => console.error(err))
|
throw res.error
|
||||||
|
// console.log('Error on subscription: ' + res.error)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeTagFromJob(tag) {
|
function removeTagFromJob(tag) {
|
||||||
pendingChange = tag.id
|
pendingChange = tag.id
|
||||||
removeTagsFromJobMutation({ job: job.id, tagIds: [tag.id] })
|
removeTagsFromJobMutation({ job: job.id, tagIds: [tag.id] })
|
||||||
.then(res => {
|
.subscribe(res => {
|
||||||
if (res.error)
|
if (res.fetching === false && !res.error) {
|
||||||
throw res.error
|
|
||||||
|
|
||||||
jobTags = job.tags = res.data.removeTagsFromJob
|
jobTags = job.tags = res.data.removeTagsFromJob
|
||||||
pendingChange = false
|
pendingChange = false
|
||||||
})
|
} else if (res.fetching === false && res.error) {
|
||||||
.catch(err => console.error(err))
|
throw res.error
|
||||||
|
// console.log('Error on subscription: ' + res.error)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -165,8 +172,7 @@
|
|||||||
<br/>
|
<br/>
|
||||||
{#if newTagType && newTagName && isNewTag(newTagType, newTagName)}
|
{#if newTagType && newTagName && isNewTag(newTagType, newTagName)}
|
||||||
<Button outline color="success"
|
<Button outline color="success"
|
||||||
on:click={e => (e.preventDefault(), createTag(newTagType, newTagName))
|
on:click={e => (e.preventDefault(), createTag(newTagType, newTagName))}>
|
||||||
.then(tag => addTagToJob(tag))}>
|
|
||||||
Create & Add Tag:
|
Create & Add Tag:
|
||||||
<Tag tag={({ type: newTagType, name: newTagName })} clickable={false}/>
|
<Tag tag={({ type: newTagType, name: newTagName })} clickable={false}/>
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user