Clean up and simplify some code
This commit is contained in:
parent
71ed5931c7
commit
37af5c0412
|
|
@ -24,19 +24,11 @@
|
|||
"slug": "geld-und-kauf",
|
||||
"__typename": "TopicNode"
|
||||
},
|
||||
"schoolClasses": {
|
||||
"edges": [
|
||||
{
|
||||
"node": {
|
||||
"id": "U2Nob29sQ2xhc3NOb2RlOjE=",
|
||||
"name": "FLID2018a",
|
||||
"__typename": "SchoolClassNode"
|
||||
},
|
||||
"__typename": "SchoolClassNodeEdge"
|
||||
}
|
||||
],
|
||||
"__typename": "SchoolClassNodeConnection"
|
||||
},
|
||||
"schoolClasses": [{
|
||||
"id": "U2Nob29sQ2xhc3NOb2RlOjE=",
|
||||
"name": "FLID2018a",
|
||||
"__typename": "SchoolClassNode"
|
||||
}],
|
||||
"__typename": "UserNode",
|
||||
"onboardingVisited": true,
|
||||
"permissions": []
|
||||
|
|
|
|||
|
|
@ -62,11 +62,7 @@ export default {
|
|||
readOnly: false,
|
||||
onboardingVisited: true,
|
||||
selectedClass,
|
||||
schoolClasses: {
|
||||
edges: [
|
||||
{node: selectedClass},
|
||||
],
|
||||
},
|
||||
schoolClasses: [selectedClass],
|
||||
recentModules: {
|
||||
edges: [],
|
||||
},
|
||||
|
|
|
|||
|
|
@ -15,9 +15,7 @@ describe('Apply module visibility', () => {
|
|||
const {me: minimalMe} = getMinimalMe({});
|
||||
const me = {
|
||||
...minimalMe,
|
||||
schoolClasses: {
|
||||
edges: schoolClasses.map(scn => ({node: scn}))
|
||||
}
|
||||
schoolClasses
|
||||
};
|
||||
// name: '[\'FLID2018a\', \'Andere Klasse\']'
|
||||
const operations = {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ describe('New student', () => {
|
|||
return {
|
||||
...me,
|
||||
onboardingVisited,
|
||||
schoolClasses: {edges: schoolClasses},
|
||||
schoolClasses,
|
||||
selectedClass: getSelectedClass(),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ const getOperations = ({readOnly, classReadOnly = false}) => ({
|
|||
...minimalModule,
|
||||
},
|
||||
},
|
||||
UpdateLastModule: {}
|
||||
});
|
||||
|
||||
const moduleNavigationTest = ({readOnly, classReadOnly = false, displayMenu}) => {
|
||||
|
|
|
|||
|
|
@ -243,23 +243,18 @@ describe('The Room Page', () => {
|
|||
cy.getByDataCy('add-room-entry-modal').should('exist');
|
||||
});
|
||||
|
||||
it('changes class while on room page', () => {
|
||||
it.only('changes class while on room page', () => {
|
||||
const {me} = MeQuery;
|
||||
const otherClass = {
|
||||
id: btoa('SchoolClassNode:34'),
|
||||
name: 'Other Class',
|
||||
readOnly: false
|
||||
};
|
||||
const operations = {
|
||||
MeQuery: {
|
||||
me: {
|
||||
...me,
|
||||
schoolClasses: {
|
||||
edges: [
|
||||
...me.schoolClasses.edges,
|
||||
{
|
||||
node: {
|
||||
id: btoa('SchoolClassNode:other-class'),
|
||||
name: 'Other Class'
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
schoolClasses: [...me.schoolClasses, otherClass],
|
||||
},
|
||||
},
|
||||
RoomEntriesQuery,
|
||||
|
|
@ -267,6 +262,15 @@ describe('The Room Page', () => {
|
|||
updateSettings: {
|
||||
success: true
|
||||
}
|
||||
},
|
||||
ModuleDetailsQuery: {
|
||||
me: {
|
||||
selectedClass: otherClass
|
||||
}
|
||||
},
|
||||
MySchoolClassQuery: {},
|
||||
RoomsQuery: {
|
||||
rooms: []
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -277,5 +281,6 @@ describe('The Room Page', () => {
|
|||
cy.getByDataCy('room-title').should('contain', 'A Room');
|
||||
cy.selectClass('Other Class');
|
||||
cy.url().should('include', 'rooms');
|
||||
cy.getByDataCy('selected-class-name').should('contain', 'Other Class');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -254,17 +254,13 @@ describe('Teacher Class Management', () => {
|
|||
let selectedClass = teacher.selectedClass;
|
||||
|
||||
const schoolClasses = [
|
||||
{
|
||||
node: teacher.selectedClass
|
||||
}
|
||||
teacher.selectedClass
|
||||
];
|
||||
|
||||
const me = () => ({
|
||||
...teacher,
|
||||
selectedClass,
|
||||
schoolClasses: {
|
||||
edges: schoolClasses
|
||||
}
|
||||
schoolClasses
|
||||
});
|
||||
|
||||
cy.mockGraphqlOps({
|
||||
|
|
@ -278,9 +274,7 @@ describe('Teacher Class Management', () => {
|
|||
name,
|
||||
readOnly: false
|
||||
};
|
||||
schoolClasses.push({
|
||||
node: schoolClass
|
||||
});
|
||||
schoolClasses.push(schoolClass);
|
||||
selectedClass = schoolClass;
|
||||
return {
|
||||
createSchoolClass: {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,7 @@ describe('Sidebar', () => {
|
|||
MeQuery: {
|
||||
me: {
|
||||
...me,
|
||||
schoolClasses: {
|
||||
edges: [
|
||||
...me.schoolClasses.edges,
|
||||
{node: {}},
|
||||
],
|
||||
},
|
||||
schoolClasses: [...me.schoolClasses, {}],
|
||||
},
|
||||
},
|
||||
ProjectsQuery: {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
export const getMinimalMe = ({readOnly = false, classReadOnly = false, isTeacher = true} = {}) => {
|
||||
const selectedClass = {
|
||||
name: 'Selected Class',
|
||||
id: btoa('SchoolClassNode:selectedClassId'),
|
||||
id: btoa('SchoolClassNode:987'),
|
||||
readOnly: classReadOnly,
|
||||
};
|
||||
return {
|
||||
|
|
@ -12,11 +12,7 @@ export const getMinimalMe = ({readOnly = false, classReadOnly = false, isTeacher
|
|||
readOnly,
|
||||
isTeacher,
|
||||
selectedClass,
|
||||
schoolClasses: {
|
||||
edges: [
|
||||
{node: selectedClass},
|
||||
],
|
||||
},
|
||||
schoolClasses: [selectedClass],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
@ -69,13 +65,7 @@ export const getMe = ({schoolClasses, teacher}) => {
|
|||
'slug': 'geld-und-kauf',
|
||||
'__typename': 'TopicNode',
|
||||
},
|
||||
'schoolClasses': {
|
||||
'edges': schoolClassNodes.map(scn => ({
|
||||
node: scn,
|
||||
'__typename': 'SchoolClassNodeEdge',
|
||||
})),
|
||||
'__typename': 'SchoolClassNodeConnection',
|
||||
},
|
||||
'schoolClasses': schoolClassNodes,
|
||||
'__typename': 'UserNode',
|
||||
'onboardingVisited': true,
|
||||
'permissions': teacher ? ['users.can_manage_school_class_content'] : [],
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@
|
|||
if (this.currentFilter.id === '') {
|
||||
return true;
|
||||
}
|
||||
return submission.student.schoolClasses.edges.some(edge => edge.node.id === this.currentFilter.id);
|
||||
return submission.student.schoolClasses.some(schoolClass => schoolClass .id === this.currentFilter.id);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -61,11 +61,13 @@
|
|||
if (success) {
|
||||
const {rooms} = store.readQuery({query: ROOMS_QUERY});
|
||||
if (rooms) {
|
||||
const index = rooms.findIndex(edge => edge.node.id === this.id);
|
||||
const index = rooms.findIndex(room => room.id === this.id);
|
||||
console.log(`found room index ${index} - rooms length ${rooms.length}`);
|
||||
const slicedRooms = [
|
||||
rooms.slice(0, index),
|
||||
rooms.slice(index+1)
|
||||
...rooms.slice(0, index),
|
||||
...rooms.slice(index+1)
|
||||
];
|
||||
console.log(`slicedRooms length ${slicedRooms.length}`);
|
||||
const data = {
|
||||
rooms: slicedRooms
|
||||
};
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ fragment UserParts on PrivateUserNode {
|
|||
}
|
||||
}
|
||||
schoolClasses {
|
||||
edges {
|
||||
node {
|
||||
...SchoolClassParts
|
||||
}
|
||||
}
|
||||
...SchoolClassParts
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,7 @@ query AssignmentWithSubmissions($id: ID!) {
|
|||
firstName
|
||||
lastName
|
||||
schoolClasses {
|
||||
edges {
|
||||
node {
|
||||
...SchoolClassParts
|
||||
}
|
||||
}
|
||||
...SchoolClassParts
|
||||
}
|
||||
}
|
||||
submissionFeedback {
|
||||
|
|
|
|||
|
|
@ -3,17 +3,13 @@ query RoomEntryQuery($slug: String!) {
|
|||
roomEntry(slug: $slug) {
|
||||
...RoomEntryParts
|
||||
comments {
|
||||
edges {
|
||||
node {
|
||||
text
|
||||
owner {
|
||||
firstName
|
||||
lastName
|
||||
avatarUrl
|
||||
}
|
||||
created
|
||||
}
|
||||
text
|
||||
owner {
|
||||
firstName
|
||||
lastName
|
||||
avatarUrl
|
||||
}
|
||||
created
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ function redirectUsersWithoutValidLicense() {
|
|||
function redirectStudentsWithoutClass() {
|
||||
return privateApolloClient.query({
|
||||
query: ME_QUERY,
|
||||
}).then(({data}) => data.me.schoolClasses.edges.length === 0 && !data.me.isTeacher);
|
||||
}).then(({data}) => data.me.schoolClasses.length === 0 && !data.me.isTeacher);
|
||||
}
|
||||
|
||||
function redirectUsersToOnboarding() {
|
||||
|
|
|
|||
|
|
@ -8,12 +8,9 @@ export default {
|
|||
this.$log.debug('updating school class', schoolClass);
|
||||
const {me} = store.readQuery({query});
|
||||
if (me) {
|
||||
let edges = [
|
||||
...me.schoolClasses.edges,
|
||||
{
|
||||
node: schoolClass,
|
||||
__typename: 'SchoolClassNodeEdge'
|
||||
}
|
||||
let schoolClasses = [
|
||||
...me.schoolClasses,
|
||||
schoolClass
|
||||
];
|
||||
// me.schoolClasses.edges
|
||||
const selectedClass = {
|
||||
|
|
@ -24,10 +21,7 @@ export default {
|
|||
const data = {
|
||||
me: {
|
||||
...me,
|
||||
schoolClasses: {
|
||||
...me.schoolClasses,
|
||||
edges
|
||||
},
|
||||
schoolClasses,
|
||||
selectedClass
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ export default {
|
|||
me: {
|
||||
query: ME_QUERY,
|
||||
update(data) {
|
||||
// todo: refactor
|
||||
return this.$getRidOfEdges(data).me;
|
||||
},
|
||||
fetchPolicy: 'cache-first'
|
||||
|
|
|
|||
|
|
@ -12,16 +12,21 @@ export default {
|
|||
shared,
|
||||
},
|
||||
},
|
||||
update(store, {data: {updateProjectSharedState: {shared, errors}}}) {
|
||||
update(store, {data: {updateProjectSharedState: {shared: final, errors}}}) {
|
||||
if (!errors) {
|
||||
const query = PROJECT_QUERY;
|
||||
const variables = {
|
||||
id: id,
|
||||
};
|
||||
const data = store.readQuery({query, variables});
|
||||
const {project} = store.readQuery({query, variables});
|
||||
|
||||
if (data) {
|
||||
data.project.final = shared;
|
||||
if (project) {
|
||||
const data = {
|
||||
project: {
|
||||
...project,
|
||||
final
|
||||
}
|
||||
};
|
||||
store.writeQuery({query, variables, data});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,11 +16,21 @@ export default {
|
|||
}
|
||||
},
|
||||
update(store) {
|
||||
let meData = store.readQuery({query: ME_QUERY});
|
||||
let {me} = store.readQuery({query: ME_QUERY});
|
||||
|
||||
meData.me.selectedClass = selectedClass;
|
||||
console.log(`storing in cache: ${selectedClass.name}`);
|
||||
const data = {
|
||||
me: {
|
||||
...me,
|
||||
selectedClass: {
|
||||
readOnly: false, // assume this, it will be reloaded later anyway
|
||||
...selectedClass
|
||||
}
|
||||
}
|
||||
};
|
||||
console.log(`writing data`, data);
|
||||
|
||||
store.writeQuery({query: ME_QUERY, data: meData});
|
||||
store.writeQuery({query: ME_QUERY, data});
|
||||
|
||||
innerApollo.mutate({
|
||||
mutation: DELETE_MODULE_NODES
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@
|
|||
|
||||
computed: {
|
||||
comments() {
|
||||
return (this.roomEntry && this.roomEntry.comments) ? this.roomEntry.comments.edges.map(edge => edge.node) : [];
|
||||
console.log(this.roomEntry);
|
||||
return (this.roomEntry && this.roomEntry.comments) ? this.roomEntry.comments : [];
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -88,15 +89,21 @@
|
|||
const variables = {
|
||||
slug: this.roomEntry.slug,
|
||||
};
|
||||
const data = store.readQuery({
|
||||
const {roomEntry} = store.readQuery({
|
||||
query,
|
||||
variables,
|
||||
});
|
||||
if (data) {
|
||||
data.roomEntry.comments.edges.unshift({
|
||||
node: comment,
|
||||
__typename: 'CommentNodeEdge'
|
||||
});
|
||||
if (roomEntry) {
|
||||
const comments = [
|
||||
comment,
|
||||
...roomEntry.comments
|
||||
];
|
||||
const data = {
|
||||
roomEntry: {
|
||||
...roomEntry,
|
||||
comments
|
||||
}
|
||||
};
|
||||
store.writeQuery({query, variables, data});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,10 +159,15 @@
|
|||
update: (store, {data: {updateAnswer: {answer}}}) => {
|
||||
const query = SURVEY_QUERY;
|
||||
const variables = {id: this.id};
|
||||
const queryData = store.readQuery({query, variables});
|
||||
if (queryData.survey) {
|
||||
queryData.survey.answer = answer;
|
||||
store.writeQuery({query, variables, data: queryData});
|
||||
const {survey} = store.readQuery({query, variables});
|
||||
if (survey) {
|
||||
const newData = { // data is already in use in parent scope
|
||||
survey: {
|
||||
...survey,
|
||||
answer
|
||||
}
|
||||
};
|
||||
store.writeQuery({query, variables, data: newData});
|
||||
}
|
||||
},
|
||||
}).then(() => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
const getRidOfEdges = (collection) => {
|
||||
// todo: get rid of this, this probably doesn't work too well with immutable objects
|
||||
// todo: don't use edges if they're not necessary
|
||||
if (typeof collection === 'object' && collection && !Array.isArray(collection)) {
|
||||
let newObj = {};
|
||||
for (const k in collection) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class CommentNode(DjangoObjectType):
|
|||
class RoomEntryNode(DjangoObjectType):
|
||||
pk = graphene.Int()
|
||||
author = graphene.Field('users.schema.PublicUserNode')
|
||||
comments = DjangoFilterConnectionField(CommentNode)
|
||||
comments = graphene.List(CommentNode)
|
||||
|
||||
class Meta:
|
||||
model = RoomEntry
|
||||
|
|
@ -36,6 +36,10 @@ class RoomEntryNode(DjangoObjectType):
|
|||
def resolve_pk(self, *args, **kwargs):
|
||||
return self.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_comments(parent: RoomEntry, *args, **kwargs):
|
||||
return parent.comments.all()
|
||||
|
||||
|
||||
class RoomNode(DjangoObjectType):
|
||||
pk = graphene.Int()
|
||||
|
|
|
|||
|
|
@ -47,11 +47,7 @@ mutation AddComment($input: AddCommentInput!) {
|
|||
query CommentsQuery($id: ID!) {
|
||||
roomEntry(id: $id) {
|
||||
comments {
|
||||
edges {
|
||||
node {
|
||||
text
|
||||
}
|
||||
}
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -266,16 +266,6 @@ type CommentNode implements Node {
|
|||
id: ID!
|
||||
}
|
||||
|
||||
type CommentNodeConnection {
|
||||
pageInfo: PageInfo!
|
||||
edges: [CommentNodeEdge]!
|
||||
}
|
||||
|
||||
type CommentNodeEdge {
|
||||
node: CommentNode
|
||||
cursor: String!
|
||||
}
|
||||
|
||||
type ContentBlockBookmarkNode implements Node {
|
||||
id: ID!
|
||||
user: PrivateUserNode!
|
||||
|
|
@ -842,7 +832,7 @@ type PrivateUserNode implements Node {
|
|||
email: String!
|
||||
onboardingVisited: Boolean!
|
||||
team: TeamNode
|
||||
schoolClasses(offset: Int, before: String, after: String, first: Int, last: Int, name: String): SchoolClassNodeConnection!
|
||||
schoolClasses: [SchoolClassNode]
|
||||
id: ID!
|
||||
pk: Int
|
||||
permissions: [String]
|
||||
|
|
@ -905,7 +895,7 @@ type RoomEntryNode implements Node {
|
|||
room: RoomNode!
|
||||
author: PublicUserNode
|
||||
contents: GenericStreamFieldType
|
||||
comments(offset: Int, before: String, after: String, first: Int, last: Int, owner: ID): CommentNodeConnection
|
||||
comments: [CommentNode]
|
||||
pk: Int
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ class PrivateUserNode(DjangoObjectType):
|
|||
expiry_date = graphene.String()
|
||||
is_teacher = graphene.Boolean()
|
||||
old_classes = DjangoFilterConnectionField(SchoolClassNode)
|
||||
school_classes =graphene.List(SchoolClassNode)
|
||||
recent_modules = DjangoFilterConnectionField(ModuleNode, filterset_class=RecentModuleFilter)
|
||||
team = graphene.Field(TeamNode)
|
||||
read_only = graphene.Boolean()
|
||||
|
|
|
|||
Loading…
Reference in New Issue