From 65b8c4ddd9b832fb1d2dff4ed0c59f7cc497b8e5 Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Tue, 13 Sep 2022 07:33:41 -0700 Subject: [PATCH] Revert "Semantic domain model/type update (#1718)" (#1732) This reverts commit 991a877291fbc61a7b78bcdccf67383e4859b423. That commit was not compatible with the data in the database. --- .../Controllers/ProjectControllerTests.cs | 17 +- .../SemanticDomainControllerTests.cs | 56 --- Backend.Tests/Models/ProjectTests.cs | 2 +- Backend.Tests/Models/SemanticDomainTest.cs | 131 ----- Backend.Tests/Models/WordTests.cs | 19 + Backend.Tests/Util.cs | 1 + Backend/Controllers/ProjectController.cs | 28 +- .../Controllers/SemanticDomainController.cs | 67 --- Backend/Models/Project.cs | 23 + Backend/Models/SemanticDomain.cs | 189 ------- Backend/Models/Word.cs | 42 ++ Backend/Services/LiftService.cs | 13 +- src/api/.openapi-generator/FILES | 3 - src/api/api.ts | 1 - src/api/api/project-api.ts | 117 +++++ src/api/api/semantic-domain-api.ts | 473 ------------------ src/api/models/index.ts | 2 - src/api/models/semantic-domain-full.ts | 45 -- src/api/models/semantic-domain-tree-node.ts | 53 -- src/api/models/semantic-domain.ts | 6 + .../DataEntry/DataEntryComponent.tsx | 4 +- .../DataEntryHeader/DataEntryHeader.tsx | 2 +- .../tests/DataEntryHeader.test.tsx | 2 +- .../NewEntry/tests/NewEntry.test.tsx | 2 +- .../tests/DataEntryTable.test.tsx | 8 +- .../tests/ExistingDataTable.test.tsx | 2 +- .../tests/DataEntryComponent.test.tsx | 2 +- src/components/TreeView/DomainTile.tsx | 2 +- src/components/TreeView/TreeDepiction.tsx | 4 +- src/components/TreeView/TreeSearch.tsx | 4 +- src/components/TreeView/TreeSemanticDomain.ts | 22 + src/components/TreeView/TreeViewActions.ts | 4 +- src/components/TreeView/TreeViewComponent.tsx | 2 +- src/components/TreeView/TreeViewHeader.tsx | 4 +- src/components/TreeView/TreeViewReducer.ts | 4 +- .../TreeView/tests/MockSemanticDomain.ts | 4 +- .../TreeView/tests/TreeDepiction.test.tsx | 2 +- .../TreeView/tests/TreeViewActions.test.tsx | 4 +- .../TreeView/tests/TreeViewReducer.test.tsx | 2 +- .../CellComponents/DomainCell.tsx | 2 +- .../tests/CellColumns.test.tsx | 8 +- .../ReviewEntriesComponent/tests/MockWords.ts | 9 +- .../tests/ReviewEntriesActions.test.tsx | 3 +- .../tests/ReviewEntriesReducer.test.tsx | 2 +- src/types/semanticDomain.ts | 41 -- src/types/word.ts | 4 + 46 files changed, 341 insertions(+), 1096 deletions(-) delete mode 100644 Backend.Tests/Controllers/SemanticDomainControllerTests.cs delete mode 100644 Backend.Tests/Models/SemanticDomainTest.cs delete mode 100644 Backend/Controllers/SemanticDomainController.cs delete mode 100644 Backend/Models/SemanticDomain.cs delete mode 100644 src/api/api/semantic-domain-api.ts delete mode 100644 src/api/models/semantic-domain-full.ts delete mode 100644 src/api/models/semantic-domain-tree-node.ts create mode 100644 src/components/TreeView/TreeSemanticDomain.ts delete mode 100644 src/types/semanticDomain.ts diff --git a/Backend.Tests/Controllers/ProjectControllerTests.cs b/Backend.Tests/Controllers/ProjectControllerTests.cs index e36982668a..1e2c557523 100644 --- a/Backend.Tests/Controllers/ProjectControllerTests.cs +++ b/Backend.Tests/Controllers/ProjectControllerTests.cs @@ -4,6 +4,7 @@ using BackendFramework.Controllers; using BackendFramework.Interfaces; using BackendFramework.Models; +using BackendFramework.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using NUnit.Framework; @@ -16,6 +17,7 @@ public class ProjectControllerTests private IUserRepository _userRepo = null!; private UserRoleRepositoryMock _userRoleRepo = null!; private IPermissionService _permissionService = null!; + private ISemanticDomainService _semDomService = null!; private ProjectController _projController = null!; private User _jwtAuthenticatedUser = null!; @@ -27,7 +29,9 @@ public void Setup() _userRepo = new UserRepositoryMock(); _userRoleRepo = new UserRoleRepositoryMock(); _permissionService = new PermissionServiceMock(_userRepo); - _projController = new ProjectController(_projRepo, _userRoleRepo, _userRepo, _permissionService) + _semDomService = new SemanticDomainService(); + _projController = new ProjectController(_projRepo, _semDomService, _userRoleRepo, + _userRepo, _permissionService) { // Mock the Http Context because this isn't an actual call avatar controller ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } @@ -111,6 +115,17 @@ public void TestDeleteAllProjects() Assert.That(_projRepo.GetAllProjects().Result, Has.Count.EqualTo(0)); } + [Test] + public void TestParseSemanticDomains() + { + var project = _projRepo.Create(Util.RandomProject()).Result; + var sdList = (List)( + (ObjectResult)_projController.GetSemDoms(project!.Id).Result).Value!; + Assert.That(sdList, Has.Count.EqualTo(3)); + Assert.That(sdList[0].Subdomains, Has.Count.EqualTo(3)); + Assert.That(sdList[0].Subdomains[0].Subdomains, Has.Count.EqualTo(3)); + } + [Test] public void TestProjectDuplicateCheck() { diff --git a/Backend.Tests/Controllers/SemanticDomainControllerTests.cs b/Backend.Tests/Controllers/SemanticDomainControllerTests.cs deleted file mode 100644 index 3b5612d740..0000000000 --- a/Backend.Tests/Controllers/SemanticDomainControllerTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System; -using System.Collections.Generic; -using Backend.Tests.Mocks; -using BackendFramework.Controllers; -using BackendFramework.Interfaces; -using BackendFramework.Models; -using BackendFramework.Services; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using NUnit.Framework; - -namespace Backend.Tests.Controllers -{ - public class SemanticDomainControllerTests - { - private IProjectRepository _projRepo = null!; - private IUserRepository _userRepo = null!; - private IPermissionService _permissionService = null!; - private ISemanticDomainService _semDomService = null!; - private SemanticDomainController _semDomController = null!; - - private User _jwtAuthenticatedUser = null!; - - [SetUp] - public void Setup() - { - _projRepo = new ProjectRepositoryMock(); - _userRepo = new UserRepositoryMock(); - _permissionService = new PermissionServiceMock(_userRepo); - _semDomService = new SemanticDomainService(); - _semDomController = new SemanticDomainController(_projRepo, _semDomService, _permissionService) - { - // Mock the Http Context because this isn't an actual call avatar controller - ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } - }; - - _jwtAuthenticatedUser = new User { Username = "user", Password = "pass" }; - _userRepo.Create(_jwtAuthenticatedUser); - _jwtAuthenticatedUser = _permissionService.Authenticate( - _jwtAuthenticatedUser.Username, _jwtAuthenticatedUser.Password).Result ?? throw new Exception(); - - _semDomController.ControllerContext.HttpContext.Request.Headers["UserId"] = _jwtAuthenticatedUser.Id; - } - - [Test] - public void TestParseSemanticDomains() - { - var project = _projRepo.Create(Util.RandomProject()).Result; - var sdList = (List)( - (ObjectResult)_semDomController.GetSemDoms(project!.Id).Result).Value!; - Assert.That(sdList, Has.Count.EqualTo(3)); - Assert.That(sdList[0].Subdomains, Has.Count.EqualTo(3)); - Assert.That(sdList[0].Subdomains[0].Subdomains, Has.Count.EqualTo(3)); - } - } -} diff --git a/Backend.Tests/Models/ProjectTests.cs b/Backend.Tests/Models/ProjectTests.cs index 3aaf68c73c..47c121f008 100644 --- a/Backend.Tests/Models/ProjectTests.cs +++ b/Backend.Tests/Models/ProjectTests.cs @@ -88,7 +88,7 @@ public void TestClone() { var system = new WritingSystem { Name = "WritingSystemName", Bcp47 = "en", Font = "calibri" }; var project = new Project { Name = "ProjectName", VernacularWritingSystem = system }; - var domain = new SemanticDomain { Name = "SemanticDomainName", Id = "1" }; + var domain = new SemanticDomain { Name = "SemanticDomainName", Id = "1", Description = "text" }; project.SemanticDomains.Add(domain); var customField = new CustomField { Name = "CustomFieldName", Type = "type" }; diff --git a/Backend.Tests/Models/SemanticDomainTest.cs b/Backend.Tests/Models/SemanticDomainTest.cs deleted file mode 100644 index 38a49de082..0000000000 --- a/Backend.Tests/Models/SemanticDomainTest.cs +++ /dev/null @@ -1,131 +0,0 @@ -using System.Collections.Generic; -using BackendFramework.Models; -using NUnit.Framework; - -namespace Backend.Tests.Models -{ - public class SemanticDomainTests - { - private const string Name = "Home"; - - [Test] - public void TestEquals() - { - var domain = new SemanticDomain { Name = Name }; - Assert.That(domain.Equals(new SemanticDomain { Name = Name })); - } - - [Test] - public void TestEqualsNull() - { - var domain = new SemanticDomain { Name = Name }; - Assert.IsFalse(domain.Equals(null)); - } - - [Test] - public void TestHashCode() - { - Assert.AreNotEqual( - new SemanticDomain { Id = "1" }.GetHashCode(), - new SemanticDomain { Id = "2" }.GetHashCode() - ); - - Assert.AreNotEqual( - new SemanticDomain { Name = "1" }.GetHashCode(), - new SemanticDomain { Name = "2" }.GetHashCode() - ); - } - } - - public class SemanticDomainFullTests - { - private const string Name = "Home"; - - [Test] - public void TestEquals() - { - var domain = new SemanticDomainFull { Name = Name }; - Assert.That(domain.Equals(new SemanticDomainFull { Name = Name })); - } - - [Test] - public void TestEqualsNull() - { - var domain = new SemanticDomainFull { Name = Name }; - Assert.IsFalse(domain.Equals(null)); - } - - [Test] - public void TestHashCode() - { - Assert.AreNotEqual( - new SemanticDomainFull { Id = "1" }.GetHashCode(), - new SemanticDomainFull { Id = "2" }.GetHashCode() - ); - - Assert.AreNotEqual( - new SemanticDomainFull { Name = "1" }.GetHashCode(), - new SemanticDomainFull { Name = "2" }.GetHashCode() - ); - - Assert.AreNotEqual( - new SemanticDomainFull { Description = "1" }.GetHashCode(), - new SemanticDomainFull { Description = "2" }.GetHashCode() - ); - - Assert.AreNotEqual( - new SemanticDomainFull { Questions = new List { "1" } }.GetHashCode(), - new SemanticDomainFull { Questions = new List { "2" } }.GetHashCode() - ); - } - } - - public class SemanticDomainTreeNodeTests - { - [Test] - public void TestEquals() - { - var node = new SemanticDomain { Name = "name", Id = "0.0" }; - var treeNode = new SemanticDomainTreeNode { Node = node }; - Assert.That(treeNode.Equals(new SemanticDomainTreeNode { Node = node })); - } - - [Test] - public void TestEqualsNull() - { - var treeNode = new SemanticDomainTreeNode(); - Assert.IsFalse(treeNode.Equals(null)); - } - - [Test] - public void TestHashCode() - { - var node1 = new SemanticDomain { Name = "name1", Id = "0.1" }; - var node2 = new SemanticDomain { Name = "name2", Id = "0.2" }; - - Assert.AreNotEqual( - new SemanticDomainTreeNode { Node = node1 }.GetHashCode(), - new SemanticDomainTreeNode { Node = node2 }.GetHashCode() - ); - Assert.AreNotEqual( - new SemanticDomainTreeNode { Parent = node1 }.GetHashCode(), - new SemanticDomainTreeNode { Parent = node2 }.GetHashCode() - ); - Assert.AreNotEqual( - new SemanticDomainTreeNode { Previous = node1 }.GetHashCode(), - new SemanticDomainTreeNode { Previous = node2 }.GetHashCode() - ); - Assert.AreNotEqual( - new SemanticDomainTreeNode { Next = node1 }.GetHashCode(), - new SemanticDomainTreeNode { Next = node2 }.GetHashCode() - ); - - var children1 = new List { node1 }; - var children2 = new List { node2 }; - Assert.AreNotEqual( - new SemanticDomainTreeNode { Children = children1 }.GetHashCode(), - new SemanticDomainTreeNode { Children = children2 }.GetHashCode() - ); - } - } -} diff --git a/Backend.Tests/Models/WordTests.cs b/Backend.Tests/Models/WordTests.cs index 88027fa2b4..f35b6a3e7f 100644 --- a/Backend.Tests/Models/WordTests.cs +++ b/Backend.Tests/Models/WordTests.cs @@ -433,4 +433,23 @@ public void TestHashCode() ); } } + + public class SemanticDomainTests + { + private const string Name = "Home"; + + [Test] + public void TestEquals() + { + var domain = new SemanticDomain { Name = Name }; + Assert.That(domain.Equals(new SemanticDomain { Name = Name })); + } + + [Test] + public void TestEqualsNull() + { + var domain = new SemanticDomain { Name = Name }; + Assert.IsFalse(domain.Equals(null)); + } + } } diff --git a/Backend.Tests/Util.cs b/Backend.Tests/Util.cs index 2b4e136849..844c3a4fc6 100644 --- a/Backend.Tests/Util.cs +++ b/Backend.Tests/Util.cs @@ -99,6 +99,7 @@ public static SemanticDomain RandomSemanticDomain(string? id = null) { Name = RandString(), Id = id ?? RandString(), + Description = RandString() }; } diff --git a/Backend/Controllers/ProjectController.cs b/Backend/Controllers/ProjectController.cs index 069fd65190..11ad9def4a 100644 --- a/Backend/Controllers/ProjectController.cs +++ b/Backend/Controllers/ProjectController.cs @@ -19,14 +19,16 @@ public class ProjectController : Controller private readonly IUserRepository _userRepo; private readonly IUserRoleRepository _userRoleRepo; private readonly IPermissionService _permissionService; + private readonly ISemanticDomainService _semDomService; - public ProjectController(IProjectRepository projRepo, IUserRoleRepository userRoleRepo, - IUserRepository userRepo, IPermissionService permissionService) + public ProjectController(IProjectRepository projRepo, ISemanticDomainService semDomService, + IUserRoleRepository userRoleRepo, IUserRepository userRepo, IPermissionService permissionService) { _projRepo = projRepo; _userRepo = userRepo; _userRoleRepo = userRoleRepo; _permissionService = permissionService; + _semDomService = semDomService; } /// Returns all s @@ -206,6 +208,28 @@ public async Task DeleteProject(string projectId) return NotFound(); } + /// + /// UNUSED: Returns tree of for specified + /// + [AllowAnonymous] + [HttpGet("{projectId}/semanticdomains", Name = "GetSemDoms")] + [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List))] + public async Task GetSemDoms(string projectId) + { + if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry)) + { + return Forbid(); + } + + var proj = await _projRepo.GetProject(projectId); + if (proj is null) + { + return NotFound(projectId); + } + var result = _semDomService.ParseSemanticDomains(proj); + return Ok(result); + } + [HttpGet("duplicate/{projectName}", Name = "ProjectDuplicateCheck")] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(bool))] public async Task ProjectDuplicateCheck(string projectName) diff --git a/Backend/Controllers/SemanticDomainController.cs b/Backend/Controllers/SemanticDomainController.cs deleted file mode 100644 index 841f516baa..0000000000 --- a/Backend/Controllers/SemanticDomainController.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using BackendFramework.Interfaces; -using BackendFramework.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; - -namespace BackendFramework.Controllers -{ - [Authorize] - [Produces("application/json")] - [Route("v1/semanticdomain")] - public class SemanticDomainController : Controller - { - private readonly IProjectRepository _projRepo; - private readonly IPermissionService _permissionService; - private readonly ISemanticDomainService _semDomService; - - public SemanticDomainController( - IProjectRepository projRepo, ISemanticDomainService semDomService, IPermissionService permissionService) - { - _projRepo = projRepo; - _permissionService = permissionService; - _semDomService = semDomService; - } - - /// Returns with specified id and in specified language - [HttpGet("{lang}/domain/{id}", Name = "GetSemanticDomainFull")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SemanticDomainFull))] - public IActionResult GetSemanticDomainFull(string id, string lang) - { - return Ok(new SemanticDomainFull { Name = "Domain API in development" }); - } - - /// Returns with specified id and in specified language - [HttpGet("{lang}/node/{id}", Name = "GetSemanticDomainTreeNode")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SemanticDomainTreeNode))] - public IActionResult GetSemanticDomainTreeNode(string id, string lang) - { - var node = new SemanticDomain { Name = "Domain API in development" }; - return Ok(new SemanticDomainTreeNode { Node = node }); - } - - /// - /// UNUSED: Returns tree of for specified - /// - [AllowAnonymous] - [HttpGet("{projectId}/semanticdomains", Name = "GetSemDoms")] - [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List))] - public async Task GetSemDoms(string projectId) - { - if (!await _permissionService.HasProjectPermission(HttpContext, Permission.WordEntry)) - { - return Forbid(); - } - - var proj = await _projRepo.GetProject(projectId); - if (proj is null) - { - return NotFound(projectId); - } - var result = _semDomService.ParseSemanticDomains(proj); - return Ok(result); - } - } -} diff --git a/Backend/Models/Project.cs b/Backend/Models/Project.cs index 567cba315a..1f19b8eee1 100644 --- a/Backend/Models/Project.cs +++ b/Backend/Models/Project.cs @@ -321,6 +321,29 @@ public UserCreatedProject() } } + /// + /// This is used in an OpenAPI return value serializer, so its attributes must be defined as properties. + /// + public class SemanticDomainWithSubdomains + { + [Required] + public string Name { get; set; } + [Required] + public string Id { get; set; } + [Required] + public string Description { get; set; } + [Required] + public List Subdomains { get; set; } + + public SemanticDomainWithSubdomains(SemanticDomain sd) + { + Name = sd.Name; + Id = sd.Id; + Description = sd.Description; + Subdomains = new List(); + } + } + public enum AutocompleteSetting { Off, diff --git a/Backend/Models/SemanticDomain.cs b/Backend/Models/SemanticDomain.cs deleted file mode 100644 index 44209a1ad2..0000000000 --- a/Backend/Models/SemanticDomain.cs +++ /dev/null @@ -1,189 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; - -namespace BackendFramework.Models -{ - public class SemanticDomain - { - [Required] - public string Name { get; set; } - [Required] - public string Id { get; set; } - - public SemanticDomain() - { - Name = ""; - Id = ""; - } - - public SemanticDomain Clone() - { - return new SemanticDomain - { - Name = (string)Name.Clone(), - Id = (string)Id.Clone() - }; - } - - public override bool Equals(object? obj) - { - if (obj is not SemanticDomain other || GetType() != obj.GetType()) - { - return false; - } - - return Name.Equals(other.Name) && Id.Equals(other.Id); - } - - public override int GetHashCode() - { - return HashCode.Combine(Name, Id); - } - } - - public class SemanticDomainFull - { - [Required] - public string Name { get; set; } - [Required] - public string Id { get; set; } - [Required] - public string Description { get; set; } - [Required] - public List Questions { get; set; } - - public SemanticDomainFull() - { - Name = ""; - Id = ""; - Description = ""; - Questions = new List(); - } - - public SemanticDomainFull Clone() - { - var clone = new SemanticDomainFull - { - Name = (string)Name.Clone(), - Id = (string)Id.Clone(), - Description = (string)Description.Clone(), - Questions = new List() - }; - - foreach (var question in Questions) - { - clone.Questions.Add((string)question.Clone()); - } - - return clone; - } - - public override bool Equals(object? obj) - { - if (obj is not SemanticDomainFull other || GetType() != obj.GetType()) - { - return false; - } - - return - Name.Equals(other.Name) && - Id.Equals(other.Id) && - Description.Equals(other.Description) && - Questions.Count == other.Questions.Count && - Questions.All(other.Questions.Contains); - } - - public override int GetHashCode() - { - return HashCode.Combine(Name, Id, Description, Questions); - } - } - - public class SemanticDomainTreeNode - { - [Required] - public SemanticDomain Node { get; set; } - [Required] - public SemanticDomain Parent { get; set; } - [Required] - public SemanticDomain Previous { get; set; } - [Required] - public SemanticDomain Next { get; set; } - [Required] - public List Children { get; set; } - - public SemanticDomainTreeNode() - { - Node = new SemanticDomain(); - Parent = new SemanticDomain(); - Previous = new SemanticDomain(); - Next = new SemanticDomain(); - Children = new List(); - } - - public SemanticDomainTreeNode Clone() - { - var clone = new SemanticDomainTreeNode - { - Node = Node.Clone(), - Parent = Parent.Clone(), - Previous = Previous.Clone(), - Next = Next.Clone(), - Children = new List() - }; - - foreach (var child in Children) - { - clone.Children.Add(child.Clone()); - } - - return clone; - } - - public override bool Equals(object? obj) - { - if (obj is not SemanticDomainTreeNode other || GetType() != obj.GetType()) - { - return false; - } - - return - Node.Equals(other.Node) && - Parent.Equals(other.Parent) && - Previous.Equals(other.Previous) && - Next.Equals(other.Next) && - Children.Count == other.Children.Count && - Children.All(other.Children.Contains); - } - - public override int GetHashCode() - { - return HashCode.Combine(Node, Parent, Previous, Next, Children); - } - } - - /// - /// This is used in an OpenAPI return value serializer, so its attributes must be defined as properties. - /// - public class SemanticDomainWithSubdomains - { - [Required] - public string Name { get; set; } - [Required] - public string Id { get; set; } - [Required] - public string Description { get; set; } - [Required] - public List Subdomains { get; set; } - - public SemanticDomainWithSubdomains(SemanticDomain sd) - { - Name = sd.Name; - Id = sd.Id; - Description = ""; - Subdomains = new List(); - } - } -} diff --git a/Backend/Models/Word.cs b/Backend/Models/Word.cs index 6f12871d25..a99ac0da73 100644 --- a/Backend/Models/Word.cs +++ b/Backend/Models/Word.cs @@ -589,6 +589,48 @@ public override int GetHashCode() } } + public class SemanticDomain + { + [Required] + public string Name { get; set; } + [Required] + public string Id { get; set; } + [Required] + public string Description { get; set; } + + public SemanticDomain Clone() + { + return new SemanticDomain + { + Name = (string)Name.Clone(), + Id = (string)Id.Clone(), + Description = (string)Description.Clone() + }; + } + + public SemanticDomain() + { + Name = ""; + Id = ""; + Description = ""; + } + + public override bool Equals(object? obj) + { + if (obj is not SemanticDomain other || GetType() != obj.GetType()) + { + return false; + } + + return Name.Equals(other.Name) && Id.Equals(other.Id) && Description.Equals(other.Description); + } + + public override int GetHashCode() + { + return HashCode.Combine(Name, Id, Description); + } + } + /// Helper object that contains a file along with its name and path public class FileUpload { diff --git a/Backend/Services/LiftService.cs b/Backend/Services/LiftService.cs index bc7e1b72fc..bb22ebe807 100644 --- a/Backend/Services/LiftService.cs +++ b/Backend/Services/LiftService.cs @@ -312,14 +312,14 @@ public async Task LiftExport( if (line != "") { var items = line.Split("`"); - WriteRangeElement(liftRangesWriter, items[0], items[1], items[2]); + WriteRangeElement(liftRangesWriter, items[0], items[1], items[2], items[3]); } } // Pull from new semantic domains in project foreach (var sd in proj.SemanticDomains) { - WriteRangeElement(liftRangesWriter, sd.Id, Guid.NewGuid().ToString(), sd.Name); + WriteRangeElement(liftRangesWriter, sd.Id, Guid.NewGuid().ToString(), sd.Name, sd.Description); } await liftRangesWriter.WriteEndElementAsync(); //end semantic-domain-ddp4 range @@ -499,7 +499,7 @@ public ILiftMerger GetLiftImporterExporter(string projectId, IWordRepository wor } private static void WriteRangeElement( - XmlWriter liftRangesWriter, string id, string guid, string name) + XmlWriter liftRangesWriter, string id, string guid, string name, string description) { liftRangesWriter.WriteStartElement("range-element"); liftRangesWriter.WriteAttributeString("id", $"{id} {name}"); @@ -519,6 +519,13 @@ private static void WriteRangeElement( liftRangesWriter.WriteEndElement(); //end text liftRangesWriter.WriteEndElement(); //end label + liftRangesWriter.WriteStartElement("description"); + liftRangesWriter.WriteAttributeString("lang", "en"); + liftRangesWriter.WriteStartElement("text"); + liftRangesWriter.WriteString(description); + liftRangesWriter.WriteEndElement(); //end text + liftRangesWriter.WriteEndElement(); //end label + liftRangesWriter.WriteEndElement(); //end range element } diff --git a/src/api/.openapi-generator/FILES b/src/api/.openapi-generator/FILES index 2f6741c4aa..108095df45 100644 --- a/src/api/.openapi-generator/FILES +++ b/src/api/.openapi-generator/FILES @@ -9,7 +9,6 @@ api/invite-api.ts api/lift-api.ts api/merge-api.ts api/project-api.ts -api/semantic-domain-api.ts api/user-api.ts api/user-edit-api.ts api/user-role-api.ts @@ -39,8 +38,6 @@ models/password-reset-data.ts models/password-reset-request-data.ts models/permission.ts models/project.ts -models/semantic-domain-full.ts -models/semantic-domain-tree-node.ts models/semantic-domain-with-subdomains.ts models/semantic-domain.ts models/sense.ts diff --git a/src/api/api.ts b/src/api/api.ts index 7cf0072e49..121880d0ec 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -19,7 +19,6 @@ export * from "./api/invite-api"; export * from "./api/lift-api"; export * from "./api/merge-api"; export * from "./api/project-api"; -export * from "./api/semantic-domain-api"; export * from "./api/user-api"; export * from "./api/user-edit-api"; export * from "./api/user-role-api"; diff --git a/src/api/api/project-api.ts b/src/api/api/project-api.ts index 528c40b724..b0b39742ce 100644 --- a/src/api/api/project-api.ts +++ b/src/api/api/project-api.ts @@ -39,6 +39,8 @@ import { // @ts-ignore import { Project } from "../models"; // @ts-ignore +import { SemanticDomainWithSubdomains } from "../models"; +// @ts-ignore import { User } from "../models"; // @ts-ignore import { UserCreatedProject } from "../models"; @@ -306,6 +308,51 @@ export const ProjectApiAxiosParamCreator = function ( options: localVarRequestOptions, }; }, + /** + * + * @param {string} projectId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getSemDoms: async ( + projectId: string, + options: any = {} + ): Promise => { + // verify required parameter 'projectId' is not null or undefined + assertParamExists("getSemDoms", "projectId", projectId); + const localVarPath = `/v1/projects/{projectId}/semanticdomains`.replace( + `{${"projectId"}}`, + encodeURIComponent(String(projectId)) + ); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { + method: "GET", + ...baseOptions, + ...options, + }; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @param {string} projectName @@ -605,6 +652,32 @@ export const ProjectApiFp = function (configuration?: Configuration) { configuration ); }, + /** + * + * @param {string} projectId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getSemDoms( + projectId: string, + options?: any + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise> + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.getSemDoms( + projectId, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, /** * * @param {string} projectName @@ -765,6 +838,20 @@ export const ProjectApiFactory = function ( .getProject(projectId, options) .then((request) => request(axios, basePath)); }, + /** + * + * @param {string} projectId + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getSemDoms( + projectId: string, + options?: any + ): AxiosPromise> { + return localVarFp + .getSemDoms(projectId, options) + .then((request) => request(axios, basePath)); + }, /** * * @param {string} projectName @@ -870,6 +957,20 @@ export interface ProjectApiGetProjectRequest { readonly projectId: string; } +/** + * Request parameters for getSemDoms operation in ProjectApi. + * @export + * @interface ProjectApiGetSemDomsRequest + */ +export interface ProjectApiGetSemDomsRequest { + /** + * + * @type {string} + * @memberof ProjectApiGetSemDoms + */ + readonly projectId: string; +} + /** * Request parameters for projectDuplicateCheck operation in ProjectApi. * @export @@ -1021,6 +1122,22 @@ export class ProjectApi extends BaseAPI { .then((request) => request(this.axios, this.basePath)); } + /** + * + * @param {ProjectApiGetSemDomsRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ProjectApi + */ + public getSemDoms( + requestParameters: ProjectApiGetSemDomsRequest, + options?: any + ) { + return ProjectApiFp(this.configuration) + .getSemDoms(requestParameters.projectId, options) + .then((request) => request(this.axios, this.basePath)); + } + /** * * @param {ProjectApiProjectDuplicateCheckRequest} requestParameters Request parameters. diff --git a/src/api/api/semantic-domain-api.ts b/src/api/api/semantic-domain-api.ts deleted file mode 100644 index 74e2120fbb..0000000000 --- a/src/api/api/semantic-domain-api.ts +++ /dev/null @@ -1,473 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * BackendFramework - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import globalAxios, { AxiosPromise, AxiosInstance } from "axios"; -import { Configuration } from "../configuration"; -// Some imports not used depending on template conditions -// @ts-ignore -import { - DUMMY_BASE_URL, - assertParamExists, - setApiKeyToObject, - setBasicAuthToObject, - setBearerAuthToObject, - setOAuthToObject, - setSearchParams, - serializeDataIfNeeded, - toPathString, - createRequestFunction, -} from "../common"; -// @ts-ignore -import { - BASE_PATH, - COLLECTION_FORMATS, - RequestArgs, - BaseAPI, - RequiredError, -} from "../base"; -// @ts-ignore -import { SemanticDomainFull } from "../models"; -// @ts-ignore -import { SemanticDomainTreeNode } from "../models"; -// @ts-ignore -import { SemanticDomainWithSubdomains } from "../models"; -/** - * SemanticDomainApi - axios parameter creator - * @export - */ -export const SemanticDomainApiAxiosParamCreator = function ( - configuration?: Configuration -) { - return { - /** - * - * @param {string} projectId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getSemDoms: async ( - projectId: string, - options: any = {} - ): Promise => { - // verify required parameter 'projectId' is not null or undefined - assertParamExists("getSemDoms", "projectId", projectId); - const localVarPath = - `/v1/semanticdomain/{projectId}/semanticdomains`.replace( - `{${"projectId"}}`, - encodeURIComponent(String(projectId)) - ); - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - }; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @param {string} id - * @param {string} lang - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getSemanticDomainFull: async ( - id: string, - lang: string, - options: any = {} - ): Promise => { - // verify required parameter 'id' is not null or undefined - assertParamExists("getSemanticDomainFull", "id", id); - // verify required parameter 'lang' is not null or undefined - assertParamExists("getSemanticDomainFull", "lang", lang); - const localVarPath = `/v1/semanticdomain/{lang}/domain/{id}` - .replace(`{${"id"}}`, encodeURIComponent(String(id))) - .replace(`{${"lang"}}`, encodeURIComponent(String(lang))); - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - }; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - /** - * - * @param {string} id - * @param {string} lang - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getSemanticDomainTreeNode: async ( - id: string, - lang: string, - options: any = {} - ): Promise => { - // verify required parameter 'id' is not null or undefined - assertParamExists("getSemanticDomainTreeNode", "id", id); - // verify required parameter 'lang' is not null or undefined - assertParamExists("getSemanticDomainTreeNode", "lang", lang); - const localVarPath = `/v1/semanticdomain/{lang}/node/{id}` - .replace(`{${"id"}}`, encodeURIComponent(String(id))) - .replace(`{${"lang"}}`, encodeURIComponent(String(lang))); - // use dummy base URL string because the URL constructor only accepts absolute URLs. - const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); - let baseOptions; - if (configuration) { - baseOptions = configuration.baseOptions; - } - - const localVarRequestOptions = { - method: "GET", - ...baseOptions, - ...options, - }; - const localVarHeaderParameter = {} as any; - const localVarQueryParameter = {} as any; - - setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); - let headersFromBaseOptions = - baseOptions && baseOptions.headers ? baseOptions.headers : {}; - localVarRequestOptions.headers = { - ...localVarHeaderParameter, - ...headersFromBaseOptions, - ...options.headers, - }; - - return { - url: toPathString(localVarUrlObj), - options: localVarRequestOptions, - }; - }, - }; -}; - -/** - * SemanticDomainApi - functional programming interface - * @export - */ -export const SemanticDomainApiFp = function (configuration?: Configuration) { - const localVarAxiosParamCreator = - SemanticDomainApiAxiosParamCreator(configuration); - return { - /** - * - * @param {string} projectId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getSemDoms( - projectId: string, - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise> - > { - const localVarAxiosArgs = await localVarAxiosParamCreator.getSemDoms( - projectId, - options - ); - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ); - }, - /** - * - * @param {string} id - * @param {string} lang - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getSemanticDomainFull( - id: string, - lang: string, - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise - > { - const localVarAxiosArgs = - await localVarAxiosParamCreator.getSemanticDomainFull( - id, - lang, - options - ); - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ); - }, - /** - * - * @param {string} id - * @param {string} lang - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - async getSemanticDomainTreeNode( - id: string, - lang: string, - options?: any - ): Promise< - ( - axios?: AxiosInstance, - basePath?: string - ) => AxiosPromise - > { - const localVarAxiosArgs = - await localVarAxiosParamCreator.getSemanticDomainTreeNode( - id, - lang, - options - ); - return createRequestFunction( - localVarAxiosArgs, - globalAxios, - BASE_PATH, - configuration - ); - }, - }; -}; - -/** - * SemanticDomainApi - factory interface - * @export - */ -export const SemanticDomainApiFactory = function ( - configuration?: Configuration, - basePath?: string, - axios?: AxiosInstance -) { - const localVarFp = SemanticDomainApiFp(configuration); - return { - /** - * - * @param {string} projectId - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getSemDoms( - projectId: string, - options?: any - ): AxiosPromise> { - return localVarFp - .getSemDoms(projectId, options) - .then((request) => request(axios, basePath)); - }, - /** - * - * @param {string} id - * @param {string} lang - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getSemanticDomainFull( - id: string, - lang: string, - options?: any - ): AxiosPromise { - return localVarFp - .getSemanticDomainFull(id, lang, options) - .then((request) => request(axios, basePath)); - }, - /** - * - * @param {string} id - * @param {string} lang - * @param {*} [options] Override http request option. - * @throws {RequiredError} - */ - getSemanticDomainTreeNode( - id: string, - lang: string, - options?: any - ): AxiosPromise { - return localVarFp - .getSemanticDomainTreeNode(id, lang, options) - .then((request) => request(axios, basePath)); - }, - }; -}; - -/** - * Request parameters for getSemDoms operation in SemanticDomainApi. - * @export - * @interface SemanticDomainApiGetSemDomsRequest - */ -export interface SemanticDomainApiGetSemDomsRequest { - /** - * - * @type {string} - * @memberof SemanticDomainApiGetSemDoms - */ - readonly projectId: string; -} - -/** - * Request parameters for getSemanticDomainFull operation in SemanticDomainApi. - * @export - * @interface SemanticDomainApiGetSemanticDomainFullRequest - */ -export interface SemanticDomainApiGetSemanticDomainFullRequest { - /** - * - * @type {string} - * @memberof SemanticDomainApiGetSemanticDomainFull - */ - readonly id: string; - - /** - * - * @type {string} - * @memberof SemanticDomainApiGetSemanticDomainFull - */ - readonly lang: string; -} - -/** - * Request parameters for getSemanticDomainTreeNode operation in SemanticDomainApi. - * @export - * @interface SemanticDomainApiGetSemanticDomainTreeNodeRequest - */ -export interface SemanticDomainApiGetSemanticDomainTreeNodeRequest { - /** - * - * @type {string} - * @memberof SemanticDomainApiGetSemanticDomainTreeNode - */ - readonly id: string; - - /** - * - * @type {string} - * @memberof SemanticDomainApiGetSemanticDomainTreeNode - */ - readonly lang: string; -} - -/** - * SemanticDomainApi - object-oriented interface - * @export - * @class SemanticDomainApi - * @extends {BaseAPI} - */ -export class SemanticDomainApi extends BaseAPI { - /** - * - * @param {SemanticDomainApiGetSemDomsRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof SemanticDomainApi - */ - public getSemDoms( - requestParameters: SemanticDomainApiGetSemDomsRequest, - options?: any - ) { - return SemanticDomainApiFp(this.configuration) - .getSemDoms(requestParameters.projectId, options) - .then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @param {SemanticDomainApiGetSemanticDomainFullRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof SemanticDomainApi - */ - public getSemanticDomainFull( - requestParameters: SemanticDomainApiGetSemanticDomainFullRequest, - options?: any - ) { - return SemanticDomainApiFp(this.configuration) - .getSemanticDomainFull( - requestParameters.id, - requestParameters.lang, - options - ) - .then((request) => request(this.axios, this.basePath)); - } - - /** - * - * @param {SemanticDomainApiGetSemanticDomainTreeNodeRequest} requestParameters Request parameters. - * @param {*} [options] Override http request option. - * @throws {RequiredError} - * @memberof SemanticDomainApi - */ - public getSemanticDomainTreeNode( - requestParameters: SemanticDomainApiGetSemanticDomainTreeNodeRequest, - options?: any - ) { - return SemanticDomainApiFp(this.configuration) - .getSemanticDomainTreeNode( - requestParameters.id, - requestParameters.lang, - options - ) - .then((request) => request(this.axios, this.basePath)); - } -} diff --git a/src/api/models/index.ts b/src/api/models/index.ts index 59641fdb66..c5217d62fb 100644 --- a/src/api/models/index.ts +++ b/src/api/models/index.ts @@ -18,8 +18,6 @@ export * from "./password-reset-request-data"; export * from "./permission"; export * from "./project"; export * from "./semantic-domain"; -export * from "./semantic-domain-full"; -export * from "./semantic-domain-tree-node"; export * from "./semantic-domain-with-subdomains"; export * from "./sense"; export * from "./site-banner"; diff --git a/src/api/models/semantic-domain-full.ts b/src/api/models/semantic-domain-full.ts deleted file mode 100644 index 995735b641..0000000000 --- a/src/api/models/semantic-domain-full.ts +++ /dev/null @@ -1,45 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * BackendFramework - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -/** - * - * @export - * @interface SemanticDomainFull - */ -export interface SemanticDomainFull { - /** - * - * @type {string} - * @memberof SemanticDomainFull - */ - name: string; - /** - * - * @type {string} - * @memberof SemanticDomainFull - */ - id: string; - /** - * - * @type {string} - * @memberof SemanticDomainFull - */ - description: string; - /** - * - * @type {Array} - * @memberof SemanticDomainFull - */ - questions: Array; -} diff --git a/src/api/models/semantic-domain-tree-node.ts b/src/api/models/semantic-domain-tree-node.ts deleted file mode 100644 index 552e4dbdf1..0000000000 --- a/src/api/models/semantic-domain-tree-node.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** - * BackendFramework - * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) - * - * The version of the OpenAPI document: 1.0 - * - * - * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * https://openapi-generator.tech - * Do not edit the class manually. - */ - -import { SemanticDomain } from "./semantic-domain"; - -/** - * - * @export - * @interface SemanticDomainTreeNode - */ -export interface SemanticDomainTreeNode { - /** - * - * @type {SemanticDomain} - * @memberof SemanticDomainTreeNode - */ - node: SemanticDomain; - /** - * - * @type {SemanticDomain} - * @memberof SemanticDomainTreeNode - */ - parent: SemanticDomain; - /** - * - * @type {SemanticDomain} - * @memberof SemanticDomainTreeNode - */ - previous: SemanticDomain; - /** - * - * @type {SemanticDomain} - * @memberof SemanticDomainTreeNode - */ - next: SemanticDomain; - /** - * - * @type {Array} - * @memberof SemanticDomainTreeNode - */ - children: Array; -} diff --git a/src/api/models/semantic-domain.ts b/src/api/models/semantic-domain.ts index 0ace8f39b5..e2e49ee07e 100644 --- a/src/api/models/semantic-domain.ts +++ b/src/api/models/semantic-domain.ts @@ -30,4 +30,10 @@ export interface SemanticDomain { * @memberof SemanticDomain */ id: string; + /** + * + * @type {string} + * @memberof SemanticDomain + */ + description: string; } diff --git a/src/components/DataEntry/DataEntryComponent.tsx b/src/components/DataEntry/DataEntryComponent.tsx index 8ddb63b281..71ee6f5359 100644 --- a/src/components/DataEntry/DataEntryComponent.tsx +++ b/src/components/DataEntry/DataEntryComponent.tsx @@ -7,10 +7,10 @@ import AppBar from "components/AppBar/AppBarComponent"; import DataEntryHeader from "components/DataEntry/DataEntryHeader/DataEntryHeader"; import DataEntryTable from "components/DataEntry/DataEntryTable/DataEntryTable"; import { ExistingDataTable } from "components/DataEntry/ExistingDataTable/ExistingDataTable"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; import TreeView from "components/TreeView/TreeViewComponent"; -import { newSemanticDomain, TreeSemanticDomain } from "types/semanticDomain"; import theme from "types/theme"; -import { DomainWord } from "types/word"; +import { DomainWord, newSemanticDomain } from "types/word"; interface DataEntryProps { domain: TreeSemanticDomain; diff --git a/src/components/DataEntry/DataEntryHeader/DataEntryHeader.tsx b/src/components/DataEntry/DataEntryHeader/DataEntryHeader.tsx index 17245a6f4b..aa194e64e0 100644 --- a/src/components/DataEntry/DataEntryHeader/DataEntryHeader.tsx +++ b/src/components/DataEntry/DataEntryHeader/DataEntryHeader.tsx @@ -4,7 +4,7 @@ import React from "react"; import { withTranslation, WithTranslation } from "react-i18next"; import { Key } from "ts-key-enum"; -import { TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; import theme from "types/theme"; interface DataEntryHeaderProps extends WithTranslation { diff --git a/src/components/DataEntry/DataEntryHeader/tests/DataEntryHeader.test.tsx b/src/components/DataEntry/DataEntryHeader/tests/DataEntryHeader.test.tsx index 97e264fdf4..c2d8bce17c 100644 --- a/src/components/DataEntry/DataEntryHeader/tests/DataEntryHeader.test.tsx +++ b/src/components/DataEntry/DataEntryHeader/tests/DataEntryHeader.test.tsx @@ -7,7 +7,7 @@ import "tests/mockReactI18next"; import DataEntryHeader, { getQuestions, } from "components/DataEntry/DataEntryHeader/DataEntryHeader"; -import { TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; const mockStore = configureMockStore()(); const mockCallback = jest.fn(); diff --git a/src/components/DataEntry/DataEntryTable/NewEntry/tests/NewEntry.test.tsx b/src/components/DataEntry/DataEntryTable/NewEntry/tests/NewEntry.test.tsx index 9959844875..6296b04b2d 100644 --- a/src/components/DataEntry/DataEntryTable/NewEntry/tests/NewEntry.test.tsx +++ b/src/components/DataEntry/DataEntryTable/NewEntry/tests/NewEntry.test.tsx @@ -3,7 +3,7 @@ import renderer from "react-test-renderer"; import "tests/mockReactI18next"; import NewEntry from "components/DataEntry/DataEntryTable/NewEntry/NewEntry"; -import { newSemanticDomain } from "types/semanticDomain"; +import { newSemanticDomain } from "types/word"; import { newWritingSystem } from "types/writingSystem"; jest.mock("components/Pronunciations/PronunciationsComponent", () => "div"); diff --git a/src/components/DataEntry/DataEntryTable/tests/DataEntryTable.test.tsx b/src/components/DataEntry/DataEntryTable/tests/DataEntryTable.test.tsx index 23a45e4df2..2acadc98ed 100644 --- a/src/components/DataEntry/DataEntryTable/tests/DataEntryTable.test.tsx +++ b/src/components/DataEntry/DataEntryTable/tests/DataEntryTable.test.tsx @@ -13,8 +13,12 @@ import DataEntryTable, { } from "components/DataEntry/DataEntryTable/DataEntryTable"; import NewEntry from "components/DataEntry/DataEntryTable/NewEntry/NewEntry"; import { newProject } from "types/project"; -import { newSemanticDomain } from "types/semanticDomain"; -import { multiSenseWord, newSense, simpleWord } from "types/word"; +import { + multiSenseWord, + newSemanticDomain, + newSense, + simpleWord, +} from "types/word"; import { firstGlossText } from "types/wordUtilities"; import { Bcp47Code } from "types/writingSystem"; diff --git a/src/components/DataEntry/ExistingDataTable/tests/ExistingDataTable.test.tsx b/src/components/DataEntry/ExistingDataTable/tests/ExistingDataTable.test.tsx index c511dc459e..602373a3d0 100644 --- a/src/components/DataEntry/ExistingDataTable/tests/ExistingDataTable.test.tsx +++ b/src/components/DataEntry/ExistingDataTable/tests/ExistingDataTable.test.tsx @@ -3,7 +3,7 @@ import renderer from "react-test-renderer"; import configureMockStore from "redux-mock-store"; import { ExistingDataTable } from "components/DataEntry/ExistingDataTable/ExistingDataTable"; -import { newSemanticDomain } from "types/semanticDomain"; +import { newSemanticDomain } from "types/word"; jest.mock("components/DataEntry/ExistingDataTable/ImmutableExistingData"); diff --git a/src/components/DataEntry/tests/DataEntryComponent.test.tsx b/src/components/DataEntry/tests/DataEntryComponent.test.tsx index 64c5630ac2..6201aada4e 100644 --- a/src/components/DataEntry/tests/DataEntryComponent.test.tsx +++ b/src/components/DataEntry/tests/DataEntryComponent.test.tsx @@ -4,7 +4,7 @@ import { filterWordsByDomain, sortDomainWordByVern, } from "components/DataEntry/DataEntryComponent"; -import { TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; import { DomainWord, newSense, simpleWord } from "types/word"; const mockWord = simpleWord("vern", "gloss"); diff --git a/src/components/TreeView/DomainTile.tsx b/src/components/TreeView/DomainTile.tsx index 614815cff1..d1feabb39e 100644 --- a/src/components/TreeView/DomainTile.tsx +++ b/src/components/TreeView/DomainTile.tsx @@ -7,7 +7,7 @@ import { } from "@material-ui/icons"; import React, { ReactElement } from "react"; -import { TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; export enum Direction { Down, diff --git a/src/components/TreeView/TreeDepiction.tsx b/src/components/TreeView/TreeDepiction.tsx index 8123e83ef1..58675dffae 100644 --- a/src/components/TreeView/TreeDepiction.tsx +++ b/src/components/TreeView/TreeDepiction.tsx @@ -2,6 +2,9 @@ import { Grid, ImageList, ImageListItem } from "@material-ui/core"; import React, { ReactElement } from "react"; import DomainTile, { Direction } from "components/TreeView/DomainTile"; +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; import { TreeViewHeader } from "components/TreeView/TreeViewHeader"; import { endcapLeft, @@ -14,7 +17,6 @@ import { teeUpLeft, teeUpRight, } from "resources/tree"; -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; const MAX_COL_WIDTH = 50; // Max gap. const MIN_COL_WIDTH = 30; // Multiply this by RATIO_TILE_TO_GAP for min tile width. diff --git a/src/components/TreeView/TreeSearch.tsx b/src/components/TreeView/TreeSearch.tsx index c5e2b2604b..1036738784 100644 --- a/src/components/TreeView/TreeSearch.tsx +++ b/src/components/TreeView/TreeSearch.tsx @@ -3,7 +3,9 @@ import React, { ReactElement, useState } from "react"; import { useTranslation } from "react-i18next"; import { Key } from "ts-key-enum"; -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; export interface TreeSearchProps { currentDomain: TreeSemanticDomain; diff --git a/src/components/TreeView/TreeSemanticDomain.ts b/src/components/TreeView/TreeSemanticDomain.ts new file mode 100644 index 0000000000..bea67bb5bb --- /dev/null +++ b/src/components/TreeView/TreeSemanticDomain.ts @@ -0,0 +1,22 @@ +import { SemanticDomainWithSubdomains } from "api/models"; + +export default class TreeSemanticDomain + implements SemanticDomainWithSubdomains +{ + id: string; + name: string; + description = ""; + subdomains: TreeSemanticDomain[] = []; + + // Additional fields not in SemanticDomainWithSubdomains + parentId?: string; + childIds: string[] = []; + questions: string[] = []; + + constructor(id = "", name = "") { + this.id = id; + this.name = name; + } +} + +export type DomainMap = Record; diff --git a/src/components/TreeView/TreeViewActions.ts b/src/components/TreeView/TreeViewActions.ts index ad75d9c3d6..6cba0d52d6 100644 --- a/src/components/TreeView/TreeViewActions.ts +++ b/src/components/TreeView/TreeViewActions.ts @@ -1,5 +1,7 @@ +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; import { StoreStateDispatch } from "types/Redux/actions"; -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; export enum TreeActionType { CLOSE_TREE = "CLOSE_TREE", diff --git a/src/components/TreeView/TreeViewComponent.tsx b/src/components/TreeView/TreeViewComponent.tsx index 88bc4254b1..8a7354cd0d 100644 --- a/src/components/TreeView/TreeViewComponent.tsx +++ b/src/components/TreeView/TreeViewComponent.tsx @@ -7,12 +7,12 @@ import { useDispatch, useSelector } from "react-redux"; import { WritingSystem } from "api"; import TreeDepiction from "components/TreeView/TreeDepiction"; import TreeSearch from "components/TreeView/TreeSearch"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; import { traverseTreeAction, updateTreeLanguage, } from "components/TreeView/TreeViewActions"; import { StoreState } from "types"; -import { TreeSemanticDomain } from "types/semanticDomain"; import { semDomWritingSystems } from "types/writingSystem"; function getSemDomWritingSystem( diff --git a/src/components/TreeView/TreeViewHeader.tsx b/src/components/TreeView/TreeViewHeader.tsx index 38e1559681..69cba3eea6 100644 --- a/src/components/TreeView/TreeViewHeader.tsx +++ b/src/components/TreeView/TreeViewHeader.tsx @@ -8,7 +8,9 @@ import { useCallback, useEffect } from "react"; import { Key } from "ts-key-enum"; import DomainTile, { Direction } from "components/TreeView/DomainTile"; -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; export interface TreeHeaderProps { currentDomain: TreeSemanticDomain; diff --git a/src/components/TreeView/TreeViewReducer.ts b/src/components/TreeView/TreeViewReducer.ts index 1bee6c69de..48563a9e09 100644 --- a/src/components/TreeView/TreeViewReducer.ts +++ b/src/components/TreeView/TreeViewReducer.ts @@ -1,9 +1,11 @@ +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; import { TreeViewAction, TreeActionType, } from "components/TreeView/TreeViewActions"; import { StoreAction, StoreActionTypes } from "rootActions"; -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; export interface TreeViewState { currentDomain: TreeSemanticDomain; diff --git a/src/components/TreeView/tests/MockSemanticDomain.ts b/src/components/TreeView/tests/MockSemanticDomain.ts index 6b697a2311..a8010057bd 100644 --- a/src/components/TreeView/tests/MockSemanticDomain.ts +++ b/src/components/TreeView/tests/MockSemanticDomain.ts @@ -1,4 +1,6 @@ -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; export enum mapIds { "head" = "", diff --git a/src/components/TreeView/tests/TreeDepiction.test.tsx b/src/components/TreeView/tests/TreeDepiction.test.tsx index 4e20ceff4f..77cc277ad5 100644 --- a/src/components/TreeView/tests/TreeDepiction.test.tsx +++ b/src/components/TreeView/tests/TreeDepiction.test.tsx @@ -1,8 +1,8 @@ import renderer, { ReactTestRenderer } from "react-test-renderer"; import TreeDepiction from "components/TreeView/TreeDepiction"; +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; import domMap, { mapIds } from "components/TreeView/tests/MockSemanticDomain"; -import { TreeSemanticDomain } from "types/semanticDomain"; var treeMaster: ReactTestRenderer; describe("Tests AddWords", () => { diff --git a/src/components/TreeView/tests/TreeViewActions.test.tsx b/src/components/TreeView/tests/TreeViewActions.test.tsx index aa0452dec4..5956158831 100644 --- a/src/components/TreeView/tests/TreeViewActions.test.tsx +++ b/src/components/TreeView/tests/TreeViewActions.test.tsx @@ -1,10 +1,12 @@ +import TreeSemanticDomain, { + DomainMap, +} from "components/TreeView/TreeSemanticDomain"; import { createDomainMap, setDomainMapAction, traverseTreeAction, TreeActionType, } from "components/TreeView/TreeViewActions"; -import { DomainMap, TreeSemanticDomain } from "types/semanticDomain"; describe("TraverseTreeAction", () => { it("SetDomainMapAction returns correct action", () => { diff --git a/src/components/TreeView/tests/TreeViewReducer.test.tsx b/src/components/TreeView/tests/TreeViewReducer.test.tsx index 26052b523d..8fdb6a2f6a 100644 --- a/src/components/TreeView/tests/TreeViewReducer.test.tsx +++ b/src/components/TreeView/tests/TreeViewReducer.test.tsx @@ -1,3 +1,4 @@ +import TreeSemanticDomain from "components/TreeView/TreeSemanticDomain"; import { TreeViewAction, TreeActionType, @@ -8,7 +9,6 @@ import { TreeViewState, } from "components/TreeView/TreeViewReducer"; import { StoreAction, StoreActionTypes } from "rootActions"; -import { TreeSemanticDomain } from "types/semanticDomain"; describe("Test the TreeViewReducer", () => { it("Returns defaultState when passed undefined", () => { diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx index 40e5fbff17..4a4bd0a2ff 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/CellComponents/DomainCell.tsx @@ -14,8 +14,8 @@ import { ReviewEntriesWord, } from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes"; import { StoreState } from "types"; -import { newSemanticDomain } from "types/semanticDomain"; import { themeColors } from "types/theme"; +import { newSemanticDomain } from "types/word"; interface DomainCellProps { rowData: ReviewEntriesWord; diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/CellColumns.test.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/CellColumns.test.tsx index e792dfdd6b..6681d55f10 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/CellColumns.test.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/CellColumns.test.tsx @@ -2,8 +2,12 @@ import columns, { ColumnTitle, } from "goals/ReviewEntries/ReviewEntriesComponent/CellColumns"; import { ReviewEntriesWord } from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes"; -import { newSemanticDomain } from "types/semanticDomain"; -import { newDefinition, newFlag, newGloss } from "types/word"; +import { + newDefinition, + newFlag, + newGloss, + newSemanticDomain, +} from "types/word"; import { Bcp47Code } from "types/writingSystem"; const LANG = Bcp47Code.En; diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/MockWords.ts b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/MockWords.ts index 41e79e1ab7..57a65af017 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/MockWords.ts +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/MockWords.ts @@ -3,8 +3,13 @@ import { ReviewEntriesSense, ReviewEntriesWord, } from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes"; -import { newSemanticDomain } from "types/semanticDomain"; -import { newFlag, newNote, newSense, newWord } from "types/word"; +import { + newFlag, + newNote, + newSemanticDomain, + newSense, + newWord, +} from "types/word"; import { Bcp47Code } from "types/writingSystem"; export default function mockWords(): ReviewEntriesWord[] { diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesActions.test.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesActions.test.tsx index fbee89406a..2a92f1d22f 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesActions.test.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesActions.test.tsx @@ -11,8 +11,7 @@ import { ReviewEntriesSense, ReviewEntriesWord, } from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes"; -import { newSemanticDomain } from "types/semanticDomain"; -import { newGloss, newSense, newWord } from "types/word"; +import { newGloss, newSemanticDomain, newSense, newWord } from "types/word"; import { Bcp47Code } from "types/writingSystem"; const mockGetWord = jest.fn(); diff --git a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesReducer.test.tsx b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesReducer.test.tsx index b99dc25bff..293e00df22 100644 --- a/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesReducer.test.tsx +++ b/src/goals/ReviewEntries/ReviewEntriesComponent/tests/ReviewEntriesReducer.test.tsx @@ -5,7 +5,7 @@ import { } from "goals/ReviewEntries/ReviewEntriesComponent/Redux/ReviewEntriesReduxTypes"; import { ReviewEntriesWord } from "goals/ReviewEntries/ReviewEntriesComponent/ReviewEntriesTypes"; import mockWords from "goals/ReviewEntries/ReviewEntriesComponent/tests/MockWords"; -import { newSemanticDomain } from "types/semanticDomain"; +import { newSemanticDomain } from "types/word"; import { Bcp47Code } from "types/writingSystem"; const mockState = { diff --git a/src/types/semanticDomain.ts b/src/types/semanticDomain.ts deleted file mode 100644 index b33fd7d871..0000000000 --- a/src/types/semanticDomain.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - SemanticDomain, - SemanticDomainTreeNode, - SemanticDomainWithSubdomains, -} from "api/models"; - -export function newSemanticDomain(id = "", name = ""): SemanticDomain { - return { id, name }; -} - -export function newSemanticDomainTreeNode( - id = "", - name = "" -): SemanticDomainTreeNode { - return { - node: newSemanticDomain(id, name), - parent: newSemanticDomain(), - previous: newSemanticDomain(), - next: newSemanticDomain(), - children: [], - }; -} - -export class TreeSemanticDomain implements SemanticDomainWithSubdomains { - id: string; - name: string; - description = ""; - subdomains: TreeSemanticDomain[] = []; - - // Additional fields not in SemanticDomainWithSubdomains - parentId?: string; - childIds: string[] = []; - questions: string[] = []; - - constructor(id = "", name = "") { - this.id = id; - this.name = name; - } -} - -export type DomainMap = Record; diff --git a/src/types/word.ts b/src/types/word.ts index 587543ddc0..01d73456cc 100644 --- a/src/types/word.ts +++ b/src/types/word.ts @@ -20,6 +20,10 @@ export function newGloss(def = "", language = ""): Gloss { return { def, language }; } +export function newSemanticDomain(id = "", name = ""): SemanticDomain { + return { id, name, description: "" }; +} + export function newSense( gloss?: string, lang?: string,