Fix snapshot list bug

This commit is contained in:
Ramon Wenger 2022-11-10 23:11:58 +01:00
parent be651c0489
commit 40f0f1cfb8
6 changed files with 1387 additions and 4474 deletions

View File

@ -141,10 +141,12 @@ describe('Snapshot', () => {
CreateSnapshot: { CreateSnapshot: {
createSnapshot: { createSnapshot: {
snapshot: { snapshot: {
id: '', id: 'snapshot-id',
title: '', title: 'Mi Snapshot',
created: '', created: '2022-01-01',
creator: '', creator: 'me',
shared: false,
mine: true
}, },
success: true, success: true,
}, },

5796
client/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,7 @@
import me from '@/mixins/me'; import me from '@/mixins/me';
import CREATE_SNAPSHOT_MUTATION from '@/graphql/gql/mutations/createSnapshot.gql'; import CREATE_SNAPSHOT_MUTATION from '@/graphql/gql/mutations/createSnapshot.gql';
import MODULE_SNAPSHOTS_QUERY from '@/graphql/gql/queries/moduleSnapshots.gql';
export default { export default {
mixins: [me], mixins: [me],
@ -66,10 +67,38 @@
selectedClass: this.me.selectedClass.id, selectedClass: this.me.selectedClass.id,
}, },
}, },
update: (store, {data: {createSnapshot: {snapshot}}}) => {
const slug = this.$route.params.slug;
const query = MODULE_SNAPSHOTS_QUERY;
const variables = {
slug,
};
const cached = store.readQuery({
query,
variables,
});
if (cached) {
const {module} = cached;
const data = {
module: {
...module,
snapshots: [
snapshot,
...module.snapshots,
],
}
};
store.writeQuery({
query,
variables,
data,
});
}
},
}).then(({data: {createSnapshot: {snapshot}}}) => { }).then(({data: {createSnapshot: {snapshot}}}) => {
this.showPopover = false; this.showPopover = false;
this.$modal.open('snapshot-created', { this.$modal.open('snapshot-created', {
snapshot snapshot,
}); });
}); });
}, },

View File

@ -0,0 +1,8 @@
fragment SnapshotParts on SnapshotNode {
id
title
created
mine
shared
creator
}

View File

@ -1,10 +1,8 @@
#import "../fragments/snapshotParts.gql"
mutation CreateSnapshot($input: CreateSnapshotInput!) { mutation CreateSnapshot($input: CreateSnapshotInput!) {
createSnapshot(input: $input) { createSnapshot(input: $input) {
snapshot { snapshot {
id ...SnapshotParts
title
created
creator
} }
success success
} }

View File

@ -1,3 +1,4 @@
#import "../fragments/snapshotParts.gql"
query ModuleSnapshotsQuery($slug: String!) { query ModuleSnapshotsQuery($slug: String!) {
module(slug: $slug) { module(slug: $slug) {
id id
@ -8,12 +9,7 @@ query ModuleSnapshotsQuery($slug: String!) {
title title
} }
snapshots { snapshots {
id ...SnapshotParts
title
created
mine
shared
creator
} }
} }
} }