From 4a79536cc6d7c87484e42ee2646aa897289fbe84 Mon Sep 17 00:00:00 2001 From: Khac Vy Date: Thu, 19 Mar 2020 15:02:50 +0700 Subject: [PATCH] feat: #63 Insert, update data into offices table --- .../ui/offices-tab/__mocks__/offices.ts | 77 +- .../__snapshots__/offices-tab.tsx.snap | 9236 ++++++++++++----- .../ui/offices-tab/__tests__/offices-tab.tsx | 124 +- .../ui/offices-tab/offices-tab.graphql | 59 +- .../components/ui/offices-tab/offices-tab.tsx | 268 +- .../__tests__/__snapshots__/index.tsx.snap | 143 +- packages/smb/src/core/index.tsx | 3 + packages/smb/src/graphql/schema.graphql | 11 + .../smb/src/utils/__tests__/validators.ts | 8 + packages/smb/src/utils/validators.ts | 4 + 10 files changed, 7401 insertions(+), 2532 deletions(-) create mode 100644 packages/smb/src/utils/__tests__/validators.ts create mode 100644 packages/smb/src/utils/validators.ts diff --git a/packages/smb/src/components/ui/offices-tab/__mocks__/offices.ts b/packages/smb/src/components/ui/offices-tab/__mocks__/offices.ts index 9819f1c260..3011adc399 100644 --- a/packages/smb/src/components/ui/offices-tab/__mocks__/offices.ts +++ b/packages/smb/src/components/ui/offices-tab/__mocks__/offices.ts @@ -1,4 +1,6 @@ -import { OfficesQueryResponse } from '../offices-tab' +import { OfficeModel } from '@reapit/foundations-ts-definitions' +import { OfficesQueryResponse, CreateOfficeParams, UpdateOfficeParams } from '../offices-tab' +import { ChangedCells } from '@reapit/elements/src/components/Spreadsheet/types' export const offices: OfficesQueryResponse = { GetOffices: { @@ -82,3 +84,76 @@ export const offices: OfficesQueryResponse = { }, }, } + +export const office: OfficeModel = { + id: 'REA', + created: '2020-02-28T10:34:06.0000000Z', + modified: '2020-02-28T10:34:06.0000000Z', + name: 'Reapit', + manager: 'Mr John Smith', + address: { + buildingName: '', + buildingNumber: '15', + line1: 'Example street', + line2: 'Solihull', + line3: 'West Midlands', + line4: '', + postcode: 'B91 2XX', + countryId: 'GB', + }, + workPhone: '01234 567890', + email: 'example@email.com', + metadata: {}, + _eTag: '"104F6D31FAFEB3B1DE6BB9CF8E071094"', + _links: { self: { href: '/offices/REA' }, negotiators: { href: '/negotiators/?officeId=REA' } }, +} + +export const mockCreateOfficeParams: CreateOfficeParams = { + name: 'Reapit', + address: { + line1: 'London road', + postcode: 'HP19 9QL', + }, + workPhone: '0987654321', + email: 'tester@reapit.com', +} + +export const mockUpdateOfficeParams: UpdateOfficeParams = { + id: 'REA', + _eTag: '"104F6D31FAFEB3B1DE6BB9CF8E071094"', + name: 'New Reapit', +} + +export const mockChangeCellsForUpdateCase: ChangedCells = [ + { + oldCell: { + key: 'name', + value: 'Reapit', + isValidated: true, + }, + newCell: { + key: 'name', + value: 'Reapit new name', + isValidated: true, + }, + row: 1, + col: 0, + }, +] + +export const mockChangeCellsForCreateCase: ChangedCells = [ + { + oldCell: { + key: 'name', + value: '', + isValidated: true, + }, + newCell: { + key: 'name', + value: 'Reapit', + isValidated: true, + }, + row: 1, + col: 0, + }, +] diff --git a/packages/smb/src/components/ui/offices-tab/__tests__/__snapshots__/offices-tab.tsx.snap b/packages/smb/src/components/ui/offices-tab/__tests__/__snapshots__/offices-tab.tsx.snap index 614d53e8ae..a45c0d0264 100644 --- a/packages/smb/src/components/ui/offices-tab/__tests__/__snapshots__/offices-tab.tsx.snap +++ b/packages/smb/src/components/ui/offices-tab/__tests__/__snapshots__/offices-tab.tsx.snap @@ -36,7 +36,7 @@ exports[`OfficesTab OfficesTab should match a snapshot 1`] = ` "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -569,18 +569,11 @@ exports[`OfficesTab OfficesTab should match a snapshot 1`] = ` ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -592,6 +585,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -721,636 +764,4618 @@ query OFFICES( }, }, }, - ] - } - > - + Map {}, + }, + "link": MockLink { + "addTypename": false, + "mockedResponsesByKey": Object { + "{\\"query\\":\\"mutation CREATE_OFFICE($name: String, $manager: String, $address: OfficeModelAddressInput, $workPhone: String, $email: String, $metadata: JSON) {\\\\n CreateOffice(name: $name, manager: $manager, address: $address, workPhone: $workPhone, email: $email, metadata: $metadata) {\\\\n ...Office\\\\n }\\\\n}\\\\n\\\\nfragment Office on OfficeModel {\\\\n id\\\\n created\\\\n modified\\\\n name\\\\n manager\\\\n address {\\\\n ...OfficeAddress\\\\n }\\\\n workPhone\\\\n email\\\\n metadata\\\\n _eTag\\\\n _links\\\\n _embedded\\\\n}\\\\n\\\\nfragment OfficeAddress on OfficeModelAddress {\\\\n buildingName\\\\n buildingNumber\\\\n line1\\\\n line2\\\\n line3\\\\n line4\\\\n postcode\\\\n countryId\\\\n}\\\\n\\"}": Array [ Object { - "callback": [Function], - "optimistic": true, - "previousResult": [Function], - "query": Object { - "definitions": Array [ - Object { - "directives": Array [], - "kind": "OperationDefinition", - "name": Object { - "kind": "Name", - "value": "OFFICES", - }, - "operation": "query", - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "arguments": Array [ - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "id", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "id", - }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "name", - }, - "value": Object { - "kind": "Variable", + "request": Object { + "query": Object { + "definitions": Array [ + Object { + "directives": Array [], + "kind": "OperationDefinition", + "name": Object { + "kind": "Name", + "value": "CREATE_OFFICE", + }, + "operation": "mutation", + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "arguments": Array [ + Object { + "kind": "Argument", "name": Object { "kind": "Name", "value": "name", }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "address", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "address", - }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "sortBy", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "sortBy", - }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "pageSize", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageSize", - }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "pageNumber", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageNumber", + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "name", + }, }, }, - }, - ], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "GetOffices", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", + "kind": "Argument", "name": Object { "kind": "Name", - "value": "_embedded", + "value": "manager", }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "directives": Array [], - "kind": "FragmentSpread", - "name": Object { - "kind": "Name", - "value": "Office", - }, - }, - ], + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "manager", + }, }, }, Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", + "kind": "Argument", "name": Object { "kind": "Name", - "value": "pageNumber", + "value": "address", }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "pageSize", + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "address", + }, }, }, Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", + "kind": "Argument", "name": Object { "kind": "Name", - "value": "pageCount", + "value": "workPhone", }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "totalCount", + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, }, }, Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", + "kind": "Argument", "name": Object { "kind": "Name", - "value": "_links", + "value": "email", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "email", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "metadata", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "metadata", + }, }, }, - ], - }, - }, - ], - }, - "variableDefinitions": Array [ - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "ListType", - "type": Object { - "kind": "NonNullType", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, + ], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "CreateOffice", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "directives": Array [], + "kind": "FragmentSpread", + "name": Object { + "kind": "Name", + "value": "Office", + }, + }, + ], }, }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "id", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "name", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "address", - }, - }, + ], }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NonNullType", + "variableDefinitions": Array [ + Object { + "directives": Array [], + "kind": "VariableDefinition", "type": Object { "kind": "NamedType", "name": Object { "kind": "Name", - "value": "Int", + "value": "String", }, }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageSize", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NonNullType", - "type": Object { - "kind": "NamedType", + "variable": Object { + "kind": "Variable", "name": Object { "kind": "Name", - "value": "Int", + "value": "name", }, }, }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageNumber", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "sortBy", - }, - }, - }, - ], - }, - Object { - "directives": Array [], - "kind": "FragmentDefinition", - "name": Object { - "kind": "Name", - "value": "Office", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "id", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "created", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "modified", - }, - }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "name", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "manager", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "manager", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "address", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "directives": Array [], - "kind": "FragmentSpread", - "name": Object { - "kind": "Name", - "value": "OfficeAddress", - }, - }, - ], + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "OfficeModelAddressInput", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "workPhone", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "address", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "email", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "metadata", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_eTag", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_links", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "email", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_embedded", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "JSON", + }, + }, + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "metadata", + }, }, }, ], }, - "typeCondition": Object { - "kind": "NamedType", + Object { + "directives": Array [], + "kind": "FragmentDefinition", "name": Object { "kind": "Name", - "value": "OfficeModel", + "value": "Office", }, - }, - }, - Object { - "directives": Array [], - "kind": "FragmentDefinition", - "name": Object { - "kind": "Name", - "value": "OfficeAddress", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "buildingName", + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "id", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "buildingNumber", + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "created", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "modified", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "name", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "manager", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "address", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "directives": Array [], + "kind": "FragmentSpread", + "name": Object { + "kind": "Name", + "value": "OfficeAddress", + }, + }, + ], + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "email", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "metadata", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "_eTag", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "_links", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "_embedded", + }, }, + ], + }, + "typeCondition": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "OfficeModel", }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line1", + }, + }, + Object { + "directives": Array [], + "kind": "FragmentDefinition", + "name": Object { + "kind": "Name", + "value": "OfficeAddress", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "buildingName", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "buildingNumber", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line1", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line2", + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line2", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line3", + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line3", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line4", + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line4", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "postcode", + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "postcode", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "countryId", + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "countryId", + }, }, + ], + }, + "typeCondition": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "OfficeModelAddress", }, - ], - }, - "typeCondition": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "OfficeModelAddress", }, }, - }, - ], - "kind": "Document", - "loc": Object { - "end": 418, - "source": Object { - "body": "#import \\"../../../graphql/fragments/office.graphql\\" + ], + "kind": "Document", + "loc": Object { + "end": 1239, + "source": Object { + "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -3272,579 +7111,656 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", - "locationOffset": Object { - "column": 1, - "line": 1, + "locationOffset": Object { + "column": 1, + "line": 1, + }, + "name": "GraphQL request", }, - "name": "GraphQL request", + "start": 0, }, - "start": 0, }, - }, - "variables": Object { - "pageNumber": 1, - "pageSize": 12, + "result": Object { + "data": Object { + "_eTag": "\\"104F6D31FAFEB3B1DE6BB9CF8E071094\\"", + "_links": Object { + "negotiators": Object { + "href": "/negotiators/?officeId=REA", + }, + "self": Object { + "href": "/offices/REA", + }, + }, + "address": Object { + "buildingName": "", + "buildingNumber": "15", + "countryId": "GB", + "line1": "Example street", + "line2": "Solihull", + "line3": "West Midlands", + "line4": "", + "postcode": "B91 2XX", + }, + "created": "2020-02-28T10:34:06.0000000Z", + "email": "example@email.com", + "id": "REA", + "manager": "Mr John Smith", + "metadata": Object {}, + "modified": "2020-02-28T10:34:06.0000000Z", + "name": "Reapit", + "workPhone": "01234 567890", + }, + }, + "variables": Object { + "address": Object { + "line1": "London road", + "postcode": "HP19 9QL", + }, + "email": "tester@reapit.com", + "name": "Reapit", + "workPhone": "0987654321", + }, }, }, - }, - }, - }, - "fetchQueryRejectFns": Map {}, - "idCounter": 3, - "inFlightLinkObservables": Map { - Object { - "definitions": Array [ + ], + "{\\"query\\":\\"mutation UPDATE_OFFICE($id: String!, $_eTag: String!, $name: String, $manager: String, $address: OfficeModelAddressInput, $workPhone: String, $email: String, $metadata: JSON) {\\\\n UpdateOffice(id: $id, _eTag: $_eTag, name: $name, manager: $manager, address: $address, workPhone: $workPhone, email: $email, metadata: $metadata) {\\\\n ...Office\\\\n }\\\\n}\\\\n\\\\nfragment Office on OfficeModel {\\\\n id\\\\n created\\\\n modified\\\\n name\\\\n manager\\\\n address {\\\\n ...OfficeAddress\\\\n }\\\\n workPhone\\\\n email\\\\n metadata\\\\n _eTag\\\\n _links\\\\n _embedded\\\\n}\\\\n\\\\nfragment OfficeAddress on OfficeModelAddress {\\\\n buildingName\\\\n buildingNumber\\\\n line1\\\\n line2\\\\n line3\\\\n line4\\\\n postcode\\\\n countryId\\\\n}\\\\n\\"}": Array [ Object { - "directives": Array [], - "kind": "OperationDefinition", - "name": Object { - "kind": "Name", - "value": "OFFICES", - }, - "operation": "query", - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "arguments": Array [ - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "id", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "id", + "request": Object { + "query": Object { + "definitions": Array [ + Object { + "directives": Array [], + "kind": "OperationDefinition", + "name": Object { + "kind": "Name", + "value": "UPDATE_OFFICE", + }, + "operation": "mutation", + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "arguments": Array [ + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "id", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "id", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "_eTag", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "_eTag", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "name", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "name", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "manager", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "manager", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "address", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "address", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "email", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "email", + }, + }, + }, + Object { + "kind": "Argument", + "name": Object { + "kind": "Name", + "value": "metadata", + }, + "value": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "metadata", + }, + }, + }, + ], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "UpdateOffice", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "directives": Array [], + "kind": "FragmentSpread", + "name": Object { + "kind": "Name", + "value": "Office", + }, + }, + ], + }, }, - }, + ], }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "name", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "name", + "variableDefinitions": Array [ + Object { + "directives": Array [], + "kind": "VariableDefinition", + "type": Object { + "kind": "NonNullType", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "address", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "address", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "id", + }, }, }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "sortBy", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "sortBy", + Object { + "directives": Array [], + "kind": "VariableDefinition", + "type": Object { + "kind": "NonNullType", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, }, - }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "pageSize", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageSize", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "_eTag", + }, }, }, - }, - Object { - "kind": "Argument", - "name": Object { - "kind": "Name", - "value": "pageNumber", - }, - "value": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageNumber", + Object { + "directives": Array [], + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "name", + }, }, }, - }, - ], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "GetOffices", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_embedded", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "directives": Array [], - "kind": "FragmentSpread", - "name": Object { - "kind": "Name", - "value": "Office", - }, - }, - ], + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "manager", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "pageNumber", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "OfficeModelAddressInput", + }, + }, + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "address", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "pageSize", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "pageCount", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "totalCount", + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "email", + }, }, }, Object { - "arguments": Array [], "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_links", + "kind": "VariableDefinition", + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "JSON", + }, + }, + "variable": Object { + "kind": "Variable", + "name": Object { + "kind": "Name", + "value": "metadata", + }, }, }, ], }, - }, - ], - }, - "variableDefinitions": Array [ - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "ListType", - "type": Object { - "kind": "NonNullType", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "id", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "name", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "address", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NonNullType", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "Int", - }, - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageSize", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NonNullType", - "type": Object { - "kind": "NamedType", + Object { + "directives": Array [], + "kind": "FragmentDefinition", "name": Object { "kind": "Name", - "value": "Int", + "value": "Office", }, - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "pageNumber", - }, - }, - }, - Object { - "directives": Array [], - "kind": "VariableDefinition", - "type": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "String", - }, - }, - "variable": Object { - "kind": "Variable", - "name": Object { - "kind": "Name", - "value": "sortBy", - }, - }, - }, - ], - }, - Object { - "directives": Array [], - "kind": "FragmentDefinition", - "name": Object { - "kind": "Name", - "value": "Office", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "id", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "created", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "modified", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "name", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "manager", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "address", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "directives": Array [], - "kind": "FragmentSpread", - "name": Object { - "kind": "Name", - "value": "OfficeAddress", + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "id", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "created", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "modified", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "name", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "manager", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "address", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "directives": Array [], + "kind": "FragmentSpread", + "name": Object { + "kind": "Name", + "value": "OfficeAddress", + }, + }, + ], + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "workPhone", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "email", + }, }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "metadata", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "_eTag", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "_links", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "_embedded", + }, + }, + ], + }, + "typeCondition": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "OfficeModel", }, - ], - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "workPhone", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "email", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "metadata", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_eTag", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_links", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "_embedded", - }, - }, - ], - }, - "typeCondition": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "OfficeModel", - }, - }, - }, - Object { - "directives": Array [], - "kind": "FragmentDefinition", - "name": Object { - "kind": "Name", - "value": "OfficeAddress", - }, - "selectionSet": Object { - "kind": "SelectionSet", - "selections": Array [ - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "buildingName", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "buildingNumber", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line1", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line2", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line3", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "line4", - }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "postcode", + }, }, - }, - Object { - "arguments": Array [], - "directives": Array [], - "kind": "Field", - "name": Object { - "kind": "Name", - "value": "countryId", + Object { + "directives": Array [], + "kind": "FragmentDefinition", + "name": Object { + "kind": "Name", + "value": "OfficeAddress", + }, + "selectionSet": Object { + "kind": "SelectionSet", + "selections": Array [ + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "buildingName", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "buildingNumber", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line1", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line2", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line3", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "line4", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "postcode", + }, + }, + Object { + "arguments": Array [], + "directives": Array [], + "kind": "Field", + "name": Object { + "kind": "Name", + "value": "countryId", + }, + }, + ], + }, + "typeCondition": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "OfficeModelAddress", + }, + }, }, - }, - ], - }, - "typeCondition": Object { - "kind": "NamedType", - "name": Object { - "kind": "Name", - "value": "OfficeModelAddress", - }, - }, - }, - ], - "kind": "Document", - "loc": Object { - "end": 418, - "source": Object { - "body": "#import \\"../../../graphql/fragments/office.graphql\\" + ], + "kind": "Document", + "loc": Object { + "end": 1239, + "source": Object { + "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -3856,21 +7772,106 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", - "locationOffset": Object { - "column": 1, - "line": 1, + "locationOffset": Object { + "column": 1, + "line": 1, + }, + "name": "GraphQL request", + }, + "start": 0, + }, + }, + "result": Object { + "data": Object { + "_eTag": "\\"104F6D31FAFEB3B1DE6BB9CF8E071094\\"", + "_links": Object { + "negotiators": Object { + "href": "/negotiators/?officeId=REA", + }, + "self": Object { + "href": "/offices/REA", + }, + }, + "address": Object { + "buildingName": "", + "buildingNumber": "15", + "countryId": "GB", + "line1": "Example street", + "line2": "Solihull", + "line3": "West Midlands", + "line4": "", + "postcode": "B91 2XX", + }, + "created": "2020-02-28T10:34:06.0000000Z", + "email": "example@email.com", + "id": "REA", + "manager": "Mr John Smith", + "metadata": Object {}, + "modified": "2020-02-28T10:34:06.0000000Z", + "name": "Reapit", + "workPhone": "01234 567890", + }, + }, + "variables": Object { + "_eTag": "\\"104F6D31FAFEB3B1DE6BB9CF8E071094\\"", + "id": "REA", + "name": "New Reapit", + }, }, - "name": "GraphQL request", }, - "start": 0, - }, - } => Map {}, - }, - "link": MockLink { - "addTypename": false, - "mockedResponsesByKey": Object { - "{\\"query\\":\\"query OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) {\\\\n GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) {\\\\n _embedded {\\\\n ...Office\\\\n }\\\\n pageNumber\\\\n pageSize\\\\n pageCount\\\\n totalCount\\\\n _links\\\\n }\\\\n}\\\\n\\\\nfragment Office on OfficeModel {\\\\n id\\\\n created\\\\n modified\\\\n name\\\\n manager\\\\n address {\\\\n ...OfficeAddress\\\\n }\\\\n workPhone\\\\n email\\\\n metadata\\\\n _eTag\\\\n _links\\\\n _embedded\\\\n}\\\\n\\\\nfragment OfficeAddress on OfficeModelAddress {\\\\n buildingName\\\\n buildingNumber\\\\n line1\\\\n line2\\\\n line3\\\\n line4\\\\n postcode\\\\n countryId\\\\n}\\\\n\\"}": Array [ + ], + "{\\"query\\":\\"query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) {\\\\n GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) {\\\\n _embedded {\\\\n ...Office\\\\n }\\\\n pageNumber\\\\n pageSize\\\\n pageCount\\\\n totalCount\\\\n _links\\\\n }\\\\n}\\\\n\\\\nfragment Office on OfficeModel {\\\\n id\\\\n created\\\\n modified\\\\n name\\\\n manager\\\\n address {\\\\n ...OfficeAddress\\\\n }\\\\n workPhone\\\\n email\\\\n metadata\\\\n _eTag\\\\n _links\\\\n _embedded\\\\n}\\\\n\\\\nfragment OfficeAddress on OfficeModelAddress {\\\\n buildingName\\\\n buildingNumber\\\\n line1\\\\n line2\\\\n line3\\\\n line4\\\\n postcode\\\\n countryId\\\\n}\\\\n\\"}": Array [ Object { "request": Object { "query": Object { @@ -3880,7 +7881,7 @@ query OFFICES( "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -4413,18 +8414,11 @@ query OFFICES( ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -4436,6 +8430,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -4572,6 +8616,7 @@ query OFFICES( "cache": InMemoryCache { "addTypename": false, "cacheKeyRoot": KeyTrie { + "weak": WeakMap {}, "weakness": true, }, "config": Object { @@ -4611,7 +8656,7 @@ query OFFICES( "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -5144,18 +9189,11 @@ query OFFICES( ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -5167,6 +9205,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -5201,7 +9289,7 @@ query OFFICES( "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -5734,18 +9822,11 @@ query OFFICES( ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -5757,6 +9838,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -5776,18 +9907,6 @@ query OFFICES( "observableQuery": ObservableQuery { "_subscriber": [Function], "isTornDown": false, - "lastResult": Object { - "data": undefined, - "loading": true, - "networkStatus": 1, - "stale": false, - }, - "lastResultSnapshot": Object { - "data": undefined, - "loading": true, - "networkStatus": 1, - "stale": false, - }, "observers": Set { SubscriptionObserver { "_subscription": Subscription { @@ -5796,25 +9915,14 @@ query OFFICES( "error": [Function], "next": [Function], }, - "_queue": Array [ - Object { - "type": "next", - "value": Object { - "data": undefined, - "loading": true, - "networkStatus": 1, - "stale": false, - }, - }, - ], - "_state": "buffering", + "_queue": undefined, + "_state": "ready", }, }, }, "options": Object { "context": undefined, "displayName": "Query", - "fetchPolicy": "network-only", "metadata": Object { "reactComponent": Object { "displayName": "Query", @@ -5828,7 +9936,7 @@ query OFFICES( "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -6361,18 +10469,11 @@ query OFFICES( ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -6384,6 +10485,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -6401,7 +10552,7 @@ query OFFICES( }, "queryId": "1", "queryManager": [Circular], - "queryName": "OFFICES", + "queryName": "GET_OFFICES", "shouldSubscribe": true, "subscriptions": Set {}, "variables": Object { @@ -6423,7 +10574,7 @@ query OFFICES( "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -6956,18 +11107,11 @@ query OFFICES( ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -6979,6 +11123,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -7015,6 +11209,7 @@ query OFFICES( "cache": InMemoryCache { "addTypename": false, "cacheKeyRoot": KeyTrie { + "weak": WeakMap {}, "weakness": true, }, "config": Object { @@ -7054,7 +11249,7 @@ query OFFICES( "kind": "OperationDefinition", "name": Object { "kind": "Name", - "value": "OFFICES", + "value": "GET_OFFICES", }, "operation": "query", "selectionSet": Object { @@ -7587,18 +11782,11 @@ query OFFICES( ], "kind": "Document", "loc": Object { - "end": 418, + "end": 1239, "source": Object { "body": "#import \\"../../../graphql/fragments/office.graphql\\" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -7610,6 +11798,56 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} ", "locationOffset": Object { "column": 1, @@ -7634,47 +11872,7 @@ query OFFICES( } } > - +
+ +
+ +
+
@@ -7713,6 +11936,7 @@ exports[`OfficesTab renderContent should match snapshot 2`] = ` exports[`OfficesTab renderContent should match snapshot 3`] = `
-

- Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. -

-

- } + validate={[Function]} /> { describe('OfficesTab', () => { it('should match a snapshot', () => { - const mockProps: OfficesTabProps = getMockRouterProps({ params: {}, search: '?page=1' }) const wrapper = mount( - - + + , ) @@ -47,6 +71,7 @@ describe('OfficesTab', () => { loading: true, error: undefined, handleChangePage: jest.fn(), + afterCellsChanged: jest.fn(), dataTable: [], } const wrapper = shallow(
{renderContent(mockParams)}
) @@ -58,6 +83,7 @@ describe('OfficesTab', () => { loading: false, error, handleChangePage: jest.fn(), + afterCellsChanged: jest.fn(), dataTable: [], } const wrapper = shallow(
{renderContent(mockParams)}
) @@ -69,6 +95,7 @@ describe('OfficesTab', () => { loading: false, error: undefined, handleChangePage: jest.fn(), + afterCellsChanged: jest.fn(), dataTable: getDataTable(offices), } const wrapper = shallow(
{renderContent(mockParams)}
) @@ -93,4 +120,85 @@ describe('OfficesTab', () => { expect(mockParams.history.push).toBeCalledWith({ search: 'page=2' }) }) }) + + describe('prepareCreateOfficeParams', () => { + it('should run correctly', () => { + const result = { + name: 'Reapit', + address: { + buildingName: '', + buildingNumber: '15', + line1: 'Example street', + line2: 'Solihull', + line3: 'West Midlands', + line4: '', + postcode: 'B91 2XX', + }, + workPhone: '01234 567890', + email: 'example@email.com', + } + const dataTable = getDataTable(offices) + expect(prepareCreateOfficeParams(mockChangeCellsForCreateCase, dataTable)).toEqual(result) + }) + }) + + describe('prepareUpdateOfficeParams', () => { + it('should run correctly', () => { + const result = { + name: 'Reapit new name', + _eTag: '"104F6D31FAFEB3B1DE6BB9CF8E071094"', + id: 'REA', + } + const dataTable = getDataTable(offices) + expect(prepareUpdateOfficeParams(mockChangeCellsForUpdateCase, dataTable)).toEqual(result) + }) + }) + + describe('validate', () => { + it('should run correctly', () => { + const result = [ + [true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true, true, true], + [true, true, true, true, true, true, true, true, true, true, false, true], + [true, true, true, true, true, true, true, true, true, true, false, true], + ] + const dataTable = getDataTable(offices) + expect(validate(dataTable)).toEqual(result) + }) + }) + + describe('handleAfterCellChange', () => { + const createFuntion = jest.fn() + const updateFuntion = jest.fn() + const dataTable = getDataTable(offices) + + it('should run create function', () => { + const preparedRow = [ + { value: '', key: 'id', isValidated: true }, + { value: '', key: '_eTag', isValidated: true }, + { value: '', key: 'name', isValidated: true }, + { value: '', key: 'address.buildingName', isValidated: true }, + { value: '', key: 'address.buildingNumber', isValidated: true }, + { value: 'London road', key: 'address.line1', isValidated: true }, + { value: '', key: 'address.line2', isValidated: true }, + { value: '', key: 'address.line3', isValidated: true }, + { value: '', key: 'address.line4', isValidated: true }, + { value: 'GP GXX', key: 'address.postcode', isValidated: true }, + { value: '0987654321', key: 'workPhone', isValidated: true }, + { value: 'tester@reapit.com', key: 'email', isValidated: true }, + ] + // const newDataTable = [...dataTable, preparedRow] + dataTable.push(preparedRow) + handleAfterCellChange(createFuntion, updateFuntion)( + [{ ...mockChangeCellsForCreateCase[0], row: dataTable.length - 1 }], + dataTable, + ) + expect(createFuntion).toHaveBeenCalled() + }) + + it('should run update function', () => { + handleAfterCellChange(createFuntion, updateFuntion)(mockChangeCellsForUpdateCase, dataTable) + expect(updateFuntion).toHaveBeenCalled() + }) + }) }) diff --git a/packages/smb/src/components/ui/offices-tab/offices-tab.graphql b/packages/smb/src/components/ui/offices-tab/offices-tab.graphql index 25e3687a21..5c82bef55e 100644 --- a/packages/smb/src/components/ui/offices-tab/offices-tab.graphql +++ b/packages/smb/src/components/ui/offices-tab/offices-tab.graphql @@ -1,13 +1,6 @@ #import "../../../graphql/fragments/office.graphql" -query OFFICES( - $id: [String!], - $name: String, - $address: String, - $pageSize: Int!, - $pageNumber: Int!, - $sortBy: String - ) { +query GET_OFFICES($id: [String!], $name: String, $address: String, $pageSize: Int!, $pageNumber: Int!, $sortBy: String) { GetOffices(id: $id, name: $name, address: $address, sortBy: $sortBy, pageSize: $pageSize, pageNumber: $pageNumber) { _embedded { ...Office @@ -19,3 +12,53 @@ query OFFICES( _links } } + +query GetOfficeById($id: String!, $embed: [String!]) { + GetOfficeById(id: $id, embed: $embed) { + ...Office + } +} + +mutation CREATE_OFFICE( + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + CreateOffice( + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} + +mutation UPDATE_OFFICE( + $id: String! + $_eTag: String! + $name: String + $manager: String + $address: OfficeModelAddressInput + $workPhone: String + $email: String + $metadata: JSON +) { + UpdateOffice( + id: $id + _eTag: $_eTag + name: $name + manager: $manager + address: $address + workPhone: $workPhone + email: $email + metadata: $metadata + ) { + ...Office + } +} diff --git a/packages/smb/src/components/ui/offices-tab/offices-tab.tsx b/packages/smb/src/components/ui/offices-tab/offices-tab.tsx index 379d8a1243..ae36eb0a12 100644 --- a/packages/smb/src/components/ui/offices-tab/offices-tab.tsx +++ b/packages/smb/src/components/ui/offices-tab/offices-tab.tsx @@ -2,14 +2,33 @@ import * as React from 'react' import { useLocation, useHistory } from 'react-router-dom' import queryString from 'query-string' import { ApolloError } from 'apollo-boost' -import { useQuery } from '@apollo/react-hooks' +import { useQuery, useMutation } from '@apollo/react-hooks' import { QueryResult } from '@apollo/react-common' -import { Loader, Cell, Alert, Section, Pagination, Spreadsheet } from '@reapit/elements' -import { PagedResultOfficeModel_, OfficeModel } from '@reapit/foundations-ts-definitions' -import { OFFICES } from './offices-tab.graphql' +import { + Loader, + Cell, + AfterCellsChanged, + Alert, + Section, + Pagination, + Spreadsheet, + ChangedCells, + isEmail, + fieldValidateRequire, + Toast, + ErrorData, +} from '@reapit/elements' +import { + PagedResultOfficeModel_, + OfficeModel, + CreateOfficeModel, + UpdateOfficeModel, +} from '@reapit/foundations-ts-definitions' +import { GET_OFFICES, CREATE_OFFICE, UPDATE_OFFICE } from './offices-tab.graphql' import { OFFICES_PER_PAGE } from '@/constants/paginators' +import { isNumber } from '@/utils/validators' -export const tableHeaders: DataTableRow[] = [ +export const tableHeaders: Cell[] = [ { readOnly: true, value: 'Office Name' }, { readOnly: true, value: 'Building Name' }, { readOnly: true, value: 'Building No.' }, @@ -37,9 +56,16 @@ export type OfficesQueryResponse = { GetOffices?: PagedResultOfficeModel_ } -export type DataTableRow = { - value?: string - readOnly?: boolean +export type CreateOfficeParams = CreateOfficeModel + +export type CreateOfficeResponse = { + CreateOffice: OfficeModel +} + +export type UpdateOfficeParams = { id: string; _eTag: string } & UpdateOfficeModel + +export type UpdateOfficeResponse = { + UpdateOffice: OfficeModel } export type RenderContentParams = { @@ -48,8 +74,9 @@ export type RenderContentParams = { pageNumber?: number pageSize?: number totalCount?: number - dataTable: DataTableRow[][] + dataTable: Cell[][] handleChangePage: (page: number) => void + afterCellsChanged: AfterCellsChanged } export const renderContent = ({ @@ -60,6 +87,7 @@ export const renderContent = ({ pageSize = 0, totalCount = 0, handleChangePage, + afterCellsChanged, }: RenderContentParams) => { if (loading) { return @@ -69,18 +97,7 @@ export const renderContent = ({ } return ( - -

- Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the - industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type - and scrambled it to make a type specimen book. -

-

- } - /> +
@@ -97,17 +114,155 @@ export const handleChangePage = ({ history }) => (pageNumber: number) => { }) } +export const handleAfterCellChange = (createOffice, updateOffice) => (changedCells: ChangedCells, data: Cell[][]) => { + const [changes] = changedCells + const { + newCell: { isValidated }, + row, + } = changes + if (!isValidated) return + const rowData = data[row] + const id = rowData[0].value as string + const eTag = rowData[1].value as string + const isEditMode = id && eTag + if (isEditMode) { + const updateOfficeParams = prepareUpdateOfficeParams(changedCells, data) + updateOffice({ + variables: updateOfficeParams, + }) + } else { + const isValidRow = rowData.every(row => row.isValidated) + if (!isValidRow) { + return + } + const createOfficeParams = prepareCreateOfficeParams(changedCells, data) + createOffice({ + variables: createOfficeParams, + }) + } +} + +export const prepareUpdateOfficeParams = (changedCells: ChangedCells, data: Cell[][]): UpdateOfficeParams => { + const [changes] = changedCells + const { + newCell: { key, value }, + row, + } = changes + const rowData = data[row] + const id = rowData[0].value as string + const eTag = rowData[1].value as string + const updateObj: UpdateOfficeModel = {} + if (key?.startsWith('address')) { + const addressNestedKey = key.split('.')[1] + updateObj.address = { [addressNestedKey]: value } + } else { + updateObj[key || ''] = value + } + + return { + id, + _eTag: eTag, + ...updateObj, + } +} + +export const prepareCreateOfficeParams = (changedCells: ChangedCells, data: Cell[][]): CreateOfficeParams => { + const [changes] = changedCells + const { row } = changes + const rowData = data[row] + const name = rowData[2].value as string + const buildingName = rowData[3].value as string + const buildingNumber = rowData[4].value as string + const line1 = rowData[5].value as string + const line2 = rowData[6].value as string + const line3 = rowData[7].value as string + const line4 = rowData[8].value as string + const postcode = rowData[9].value as string + const workPhone = rowData[10].value as string + const email = rowData[11].value as string + + return { + name, + address: { + buildingName, + buildingNumber, + line1, + line2, + line3, + line4, + postcode, + }, + workPhone, + email, + } +} + +export const handleErrorMessageUseEffect = (createOfficeError, updateOfficeError, setErrorServer) => { + return () => { + if (createOfficeError) { + setErrorServer({ + type: 'SERVER', + message: createOfficeError.message, + }) + } + if (updateOfficeError) { + setErrorServer({ + type: 'SERVER', + message: updateOfficeError.message, + }) + } + } +} + export const OfficesTab: React.FC = () => { const location = useLocation() const history = useHistory() const params = queryString.parse(location?.search) const page = Number(params?.page) || 1 - const { loading, error, data } = useQuery(OFFICES, { + const [serverError, setErrorServer] = React.useState(null) + const [componentError, setErrorComponent] = React.useState(null) + const { loading, error, data } = useQuery(GET_OFFICES, { variables: { pageSize: OFFICES_PER_PAGE, pageNumber: page }, - fetchPolicy: 'network-only', }) as QueryResult + const [createOffice, { error: createOfficeError }] = useMutation( + CREATE_OFFICE, + { + update: (proxy, fetchResult) => { + const cacheData = proxy.readQuery({ + query: GET_OFFICES, + variables: { pageSize: OFFICES_PER_PAGE, pageNumber: page }, + }) + proxy.writeQuery({ + query: GET_OFFICES, + variables: { pageSize: OFFICES_PER_PAGE, pageNumber: page }, + data: { + GetOffices: { + ...cacheData?.GetOffices, + _embedded: [...(cacheData?.GetOffices?._embedded || []), fetchResult.data?.CreateOffice], + }, + }, + }) + }, + }, + ) + const [updateOffice, { error: updateOfficeError }] = useMutation( + UPDATE_OFFICE, + ) + + const dataTable = React.useMemo(() => getDataTable(data || { GetOffices: { _embedded: [] } }), [data]) + + React.useEffect(handleErrorMessageUseEffect(createOfficeError, updateOfficeError, setErrorServer), [ + createOfficeError, + updateOfficeError, + ]) + + const errorClearedComponent = () => { + setErrorComponent(null) + } - const dataTable = getDataTable(data || { GetOffices: { _embedded: [] } }) + const errorClearedServer = () => { + setErrorServer(null) + } return (
@@ -119,28 +274,65 @@ export const OfficesTab: React.FC = () => { pageSize: data?.GetOffices?.pageSize, totalCount: data?.GetOffices?.totalCount, handleChangePage: handleChangePage({ history }), + afterCellsChanged: handleAfterCellChange(createOffice, updateOffice), })} +
) } -export function getDataTable(data: OfficesQueryResponse): DataTableRow[][] { - let dataTable: DataTableRow[][] = [tableHeaders] +export function getDataTable(data: OfficesQueryResponse): Cell[][] { + let dataTable: Cell[][] = [tableHeaders] const offices: OfficeModel[] = data.GetOffices?._embedded || [] - const dataRows: DataTableRow[][] = offices.map((office: OfficeModel) => [ - { value: office.name }, - { value: office.address?.buildingName }, - { value: office.address?.buildingNumber }, - { value: office.address?.line1 }, - { value: office.address?.line2 }, - { value: office.address?.line3 }, - { value: office.address?.line4 }, - { value: office.address?.postcode }, - { value: office.workPhone }, - { value: office.email }, - ]) + const dataRows = offices.map((office: OfficeModel) => [ + { value: office.id, key: 'id', readOnly: true, className: 'hidden-cell' }, + { value: office._eTag, key: '_eTag', readOnly: true, className: 'hidden-cell' }, + { value: office.name, key: 'name' }, + { value: office.address?.buildingName, key: 'address.buildingName' }, + { value: office.address?.buildingNumber, key: 'address.buildingNumber' }, + { value: office.address?.line1, key: 'address.line1' }, + { value: office.address?.line2, key: 'address.line2' }, + { value: office.address?.line3, key: 'address.line3' }, + { value: office.address?.line4, key: 'address.line4' }, + { value: office.address?.postcode, key: 'address.postcode' }, + { value: office.workPhone, key: 'workPhone' }, + { value: office.email, key: 'email' }, + ]) as Cell[][] dataTable = [tableHeaders, ...dataRows] return dataTable } +export const validate = (data: Cell[][]) => + data.map((row, rowIndex) => + row.map((cell, cellIndex) => { + if (rowIndex === 0) return true // dont need to validate header row + // cell name is required + if (cellIndex === 2) { + return !fieldValidateRequire(cell.value as string) + } + // cell addess1 is required + if (cellIndex === 5) { + return !fieldValidateRequire(cell.value as string) + } + // cell postalcode is required + if (cellIndex === 9) { + return !fieldValidateRequire(cell.value as string) + } + // cell telephone is required + if (cellIndex === 10) { + return !fieldValidateRequire(cell.value as string) && isNumber(cell.value as string) + } + // cell email is required + if (cellIndex === 11) { + return !fieldValidateRequire(cell.value as string) && isEmail(cell.value as string) + } + return true + }), + ) + export default OfficesTab diff --git a/packages/smb/src/core/__tests__/__snapshots__/index.tsx.snap b/packages/smb/src/core/__tests__/__snapshots__/index.tsx.snap index f24d7b87cf..f251326a35 100644 --- a/packages/smb/src/core/__tests__/__snapshots__/index.tsx.snap +++ b/packages/smb/src/core/__tests__/__snapshots__/index.tsx.snap @@ -1729,10 +1729,140 @@ exports[`App should match a snapshot 1`] = ` "value": "Mutation", }, }, + Object { + "directives": Array [], + "fields": Array [ + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "buildingName", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "buildingNumber", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "line1", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "line2", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "line3", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "line4", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "postcode", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + Object { + "directives": Array [], + "kind": "InputValueDefinition", + "name": Object { + "kind": "Name", + "value": "countryId", + }, + "type": Object { + "kind": "NamedType", + "name": Object { + "kind": "Name", + "value": "String", + }, + }, + }, + ], + "kind": "InputObjectTypeDefinition", + "name": Object { + "kind": "Name", + "value": "OfficeModelAddressInput", + }, + }, ], "kind": "Document", "loc": Object { - "end": 1872, + "end": 2058, "source": Object { "body": "type Query { # contact @@ -1825,6 +1955,17 @@ type Mutation { mode: LoginMode!, ): Token } + +input OfficeModelAddressInput { + buildingName: String + buildingNumber: String + line1: String + line2: String + line3: String + line4: String + postcode: String + countryId: String +} ", "locationOffset": Object { "column": 1, diff --git a/packages/smb/src/core/index.tsx b/packages/smb/src/core/index.tsx index 07f0e840db..49bd266719 100644 --- a/packages/smb/src/core/index.tsx +++ b/packages/smb/src/core/index.tsx @@ -11,6 +11,9 @@ const GlobalStyle = createGlobalStyle` body { background-color: unset; } + td.hidden-cell { + display: none; + } ` const rootElement = document.querySelector('#root') as Element diff --git a/packages/smb/src/graphql/schema.graphql b/packages/smb/src/graphql/schema.graphql index 1bb505c921..4b117c3449 100644 --- a/packages/smb/src/graphql/schema.graphql +++ b/packages/smb/src/graphql/schema.graphql @@ -89,3 +89,14 @@ type Mutation { mode: LoginMode!, ): Token } + +input OfficeModelAddressInput { + buildingName: String + buildingNumber: String + line1: String + line2: String + line3: String + line4: String + postcode: String + countryId: String +} diff --git a/packages/smb/src/utils/__tests__/validators.ts b/packages/smb/src/utils/__tests__/validators.ts new file mode 100644 index 0000000000..58477a7fae --- /dev/null +++ b/packages/smb/src/utils/__tests__/validators.ts @@ -0,0 +1,8 @@ +import { isNumber } from '../validators' + +describe('isNumber', () => { + it('should run correctly', () => { + expect(isNumber('12345')).toBe(true) + expect(isNumber('12345a')).toBe(false) + }) +}) diff --git a/packages/smb/src/utils/validators.ts b/packages/smb/src/utils/validators.ts new file mode 100644 index 0000000000..6b4edeea4f --- /dev/null +++ b/packages/smb/src/utils/validators.ts @@ -0,0 +1,4 @@ +export const isNumber = (value: string) => { + const regex = /^[0-9 ]+$/ + return regex.test(value) +}