diff --git a/.github/workflows/e2etests.yml b/.github/workflows/e2etests.yml index 0a6c269a..306a6be7 100644 --- a/.github/workflows/e2etests.yml +++ b/.github/workflows/e2etests.yml @@ -22,7 +22,7 @@ jobs: if [[ $BRANCH == master ]]; then echo "VERSION=master" >> $GITHUB_ENV else - echo "VERSION=develop" >> $GITHUB_ENV + echo "VERSION=feature/project-ownership" >> $GITHUB_ENV fi - name: Clone backend uses: actions/checkout@v2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a8328bc..630fe3ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,12 +57,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -- Folder's Id is needed when creating a new object or draft object -- Patching folder is no longer needed when patching object or draft object +- Updated projectId in GET and POST requests for folders and templates #696 + + ### Added + + - ProjectId is a mandatory query parameter in GET requests for folders and templates + - ProjectId is a mandatory propperty in POST requests for folders and templates + - Templates has a separate API endpoint and is no longer a propety under User + - Template's index is a mandatory property in PATCH request for a template + +- Folder's Id is needed when creating a new object or draft object #672 ### Added - Added folderId as query parameter for object's and draft object's Post request + - Patching folder is no longer needed when patching object or draft object - Updated Node.js version in GitHub workflows and Dockerfile #655 - Disallow use of any-type #624 diff --git a/cypress/integration/doiForm.spec.ts b/cypress/integration/doiForm.spec.ts index 4b515bf4..7adad0c0 100644 --- a/cypress/integration/doiForm.spec.ts +++ b/cypress/integration/doiForm.spec.ts @@ -1,9 +1,7 @@ describe("DOI form", function () { beforeEach(() => { cy.task("resetDb") - cy.login() - cy.get("button", { timeout: 10000 }).contains("Create submission").click() // Add folder name & description, navigate to submissions diff --git a/cypress/integration/home.spec.ts b/cypress/integration/home.spec.ts index f379702f..6358b7dd 100644 --- a/cypress/integration/home.spec.ts +++ b/cypress/integration/home.spec.ts @@ -6,6 +6,10 @@ describe("Home e2e", function () { it("show draft submission data table in Home page, be able to edit and delete a draft submission inside the table", () => { cy.intercept("/folders*").as("fetchFolders") + + // Check that there is projectId in home page + cy.get("[data-testid='project-id-selection']").should("be.visible") + cy.get("[data-testid='project-id-selection'] > div > input").invoke("val").should("not.be.empty") // Create a new Unpublished folder cy.get("button").contains("Create submission").click() diff --git a/cypress/integration/objectLinksAttributes.spec.ts b/cypress/integration/objectLinksAttributes.spec.ts index 63b3a6d3..0d3d14ab 100644 --- a/cypress/integration/objectLinksAttributes.spec.ts +++ b/cypress/integration/objectLinksAttributes.spec.ts @@ -87,11 +87,8 @@ describe("render objects' links and attributes ", function () { cy.get("div[data-testid='studyLinks'] > div", { timeout: 10000 }).should("have.length", 3) // Remove URL Link and check that the rest of the Study Links render correctly - cy.get("[data-testid='studyLinks[1]']").should("be.visible") - - cy.get("[data-testid='studyLinks[1]'] > button", { timeout: 30000 }) - .should("be.visible") - .then($el => $el.click()) + cy.wait(0) + cy.get("[data-testid='studyLinks[1]'] > button", { timeout: 10000 }).should("be.visible").click() cy.get("div[data-testid='studyLinks'] > div", { timeout: 30000 }).should("have.length", 2) diff --git a/cypress/integration/pagination.spec.ts b/cypress/integration/pagination.spec.ts index 3f0c7ae0..8756bf40 100644 --- a/cypress/integration/pagination.spec.ts +++ b/cypress/integration/pagination.spec.ts @@ -1,146 +1,153 @@ describe("unpublished folders, published folders, and user's draft templates pagination", function () { - beforeEach(() => cy.task("resetDb")) + beforeEach(() => { + cy.task("resetDb") + const userResponse = { + name: "test user", + id: "USERID", + projects: [ + { projectId: "PROJECT1", projectName: "Project 1" }, + { projectId: "PROJECT2", projectName: "Project 2" }, + ], + } + + cy.intercept({ method: "GET", url: "/users/current" }, userResponse) + }) it("should renders pagination for unpublished folders list correctly", () => { // Mock responses for Unpublished Folders const unpublishedFoldersResponse5 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, ], - page: { page: 1, size: 5, totalPages: 20, totalFolders: 100 }, + page: { page: 1, size: 5, totalPages: 10, totalFolders: 50 }, } const unpublishedFoldersResponse15 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub11", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub12", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub13", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub14", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub15", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub11", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub12", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub13", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub14", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub15", published: false }, ], - page: { page: 1, size: 15, totalPages: 7, totalFolders: 100 }, + page: { page: 1, size: 15, totalPages: 4, totalFolders: 50 }, } const unpublishedFoldersResponse25 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub11", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub12", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub13", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub14", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub15", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub16", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub17", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub18", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub19", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub20", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub21", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub22", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub23", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub24", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub25", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub11", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub12", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub13", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub14", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub15", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub16", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub17", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub18", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub19", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub20", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub21", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub22", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub23", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub24", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub25", published: false }, ], - page: { page: 1, size: 25, totalPages: 4, totalFolders: 100 }, + page: { page: 1, size: 25, totalPages: 2, totalFolders: 50 }, } const unpublishedFoldersResponse50 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, ], - page: { page: 1, size: 50, totalPages: 2, totalFolders: 100 }, + page: { page: 1, size: 50, totalPages: 1, totalFolders: 50 }, } const unpublishedFoldersResponsePage2 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, ], - page: { page: 2, size: 5, totalPages: 20, totalFolders: 100 }, + page: { page: 2, size: 5, totalPages: 10, totalFolders: 50 }, } cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=5&published=false", + url: "/folders?page=1&per_page=5&published=false&projectId=PROJECT1", }, unpublishedFoldersResponse5 ) @@ -148,7 +155,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=15&published=false", + url: "/folders?page=1&per_page=15&published=false&projectId=PROJECT1", }, unpublishedFoldersResponse15 ) @@ -156,7 +163,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=25&published=false", + url: "/folders?page=1&per_page=25&published=false&projectId=PROJECT1", }, unpublishedFoldersResponse25 ) @@ -164,7 +171,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=50&published=false", + url: "/folders?page=1&per_page=50&published=false&projectId=PROJECT1", }, unpublishedFoldersResponse50 ) @@ -172,7 +179,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=2&per_page=5&published=false", + url: "/folders?page=2&per_page=5&published=false&projectId=PROJECT1", }, unpublishedFoldersResponsePage2 ).as("unpublishedPage2") @@ -180,26 +187,65 @@ describe("unpublished folders, published folders, and user's draft templates pag // Mock response for Published Folders const publishedFoldersResponse5 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + ], + page: { page: 1, size: 5, totalPages: 10, totalFolders: 50 }, + } + + const publishedFoldersResponse50 = { + folders: [ + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, ], - page: { page: 1, size: 5, totalPages: 20, totalFolders: 100 }, + page: { page: 1, size: 50, totalPages: 1, totalFolders: 50 }, } cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=5&published=true", + url: "/folders?page=1&per_page=5&published=true&projectId=PROJECT1", }, publishedFoldersResponse5 ) + + cy.intercept( + { + method: "GET", + url: "/folders?page=1&per_page=50&published=true&projectId=PROJECT1", + }, + publishedFoldersResponse50 + ) cy.login() cy.get("[data-testid='table-pagination']", { timeout: 10000 }).should("be.visible") - cy.get("[data-testid='page info']", { timeout: 10000 }).contains("1 of 20 pages").should("be.visible") + cy.get("[data-testid='page info']", { timeout: 10000 }).contains("1 of 10 pages").should("be.visible") // Click Next page button cy.get("[data-testid='NavigateNextIcon']") .parent() @@ -209,8 +255,8 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.wait("@unpublishedPage2") cy.get("div[aria-haspopup='listbox']").contains(5, { timeout: 10000 }).as("button") - cy.contains("6-10 of 100", { timeout: 10000 }).should("be.visible") - cy.get("[data-testid='page info']").contains("2 of 20 pages", { timeout: 10000 }).should("be.visible") + cy.contains("6-10 of 50", { timeout: 10000 }).should("be.visible") + cy.get("[data-testid='page info']").contains("2 of 10 pages", { timeout: 10000 }).should("be.visible") // Check "Items per page" options cy.wait(0) cy.get("@button") @@ -226,127 +272,136 @@ describe("unpublished folders, published folders, and user's draft templates pag // Select 15 items cy.get("li[data-value='15']").click({ force: true }) - cy.get("p", { timeout: 10000 }).contains("1-15 of 100").should("be.visible") - cy.get("[data-testid='page info']").contains("1 of 7 pages").should("be.visible") + cy.get("p", { timeout: 10000 }).contains("1-15 of 50").should("be.visible") + cy.get("[data-testid='page info']").contains("1 of 4 pages").should("be.visible") // Select 25 items cy.get("div[aria-haspopup='listbox']", { timeout: 10000 }).contains(15).click() cy.get("li[data-value='25']").click() - cy.get("p", { timeout: 10000 }).contains("1-25 of 100").should("be.visible") - cy.get("[data-testid='page info']").contains("1 of 4 pages").should("be.visible") + cy.get("p", { timeout: 10000 }).contains("1-25 of 50").should("be.visible") + cy.get("[data-testid='page info']").contains("1 of 2 pages").should("be.visible") // Select 50 items cy.get("div[aria-haspopup='listbox']", { timeout: 10000 }).contains(25).click() cy.get("li[data-value='50']").click() - cy.get("p", { timeout: 10000 }).contains("1-50 of 100").should("be.visible") - cy.get("[data-testid='page info']").contains("1 of 2 pages").should("be.visible") + cy.get("p", { timeout: 10000 }).contains("1-50 of 50").should("be.visible") + cy.get("[data-testid='page info']").contains("1 of 1 pages").should("be.visible") }) it("should render pagination for unpublished folders list correctly", () => { + // Mock responses for Unpublished Folders + const unpublishedFoldersResponse5 = { + folders: [ + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + ], + page: { page: 1, size: 5, totalPages: 10, totalFolders: 5 }, + } // Mock responses for Published Folders const publishedFoldersResponse5 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, ], - page: { page: 1, size: 5, totalPages: 30, totalFolders: 150 }, + page: { page: 1, size: 5, totalPages: 1, totalFolders: 50 }, } const publishedFoldersResponse50 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, ], - page: { page: 1, size: 50, totalPages: 3, totalFolders: 150 }, + page: { page: 1, size: 50, totalPages: 1, totalFolders: 50 }, } const publishedFoldersResponsePage2 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, ], - page: { page: 2, size: 5, totalPages: 30, totalFolders: 150 }, + page: { page: 2, size: 5, totalPages: 10, totalFolders: 50 }, } const publishedFoldersResponsePage3 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, ], - page: { page: 3, size: 5, totalPages: 30, totalFolders: 150 }, + page: { page: 3, size: 5, totalPages: 10, totalFolders: 50 }, } cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=5&published=true", + url: "/folders?page=1&per_page=5&published=false&projectId=PROJECT1", + }, + unpublishedFoldersResponse5 + ) + + cy.intercept( + { + method: "GET", + url: "/folders?page=1&per_page=5&published=true&projectId=PROJECT1", }, publishedFoldersResponse5 ) @@ -354,7 +409,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=50&published=true", + url: "/folders?page=1&per_page=50&published=true&projectId=PROJECT1", }, publishedFoldersResponse50 ) @@ -362,7 +417,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=2&per_page=5&published=true", + url: "/folders?page=2&per_page=5&published=true&projectId=PROJECT1", }, publishedFoldersResponsePage2 ).as("publishedPage2") @@ -370,7 +425,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=3&per_page=5&published=true", + url: "/folders?page=3&per_page=5&published=true&projectId=PROJECT1", }, publishedFoldersResponsePage3 ) @@ -380,18 +435,23 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.get("[data-testid='published-tab']").click() cy.get("[data-testid='page info']").should("be.visible") - cy.get("[data-testid='page info']").contains("1 of 30 pages").should("be.visible") + cy.get("[data-testid='page info']").contains("1 of 10 pages").should("be.visible") // Click Next page button cy.get("[data-testid='NavigateNextIcon']") .parent() .should("be.visible") .then($el => $el.click()) - cy.contains("6-10 of 150", { timeout: 10000 }).should("be.visible") - cy.get("[data-testid='page info']").contains("2 of 30 pages").should("be.visible") + cy.contains("6-10 of 50", { timeout: 10000 }).should("be.visible") + cy.get("[data-testid='page info']").contains("2 of 10 pages").should("be.visible") cy.wait("@publishedPage2") - cy.get("button[aria-label='Go to page 3']").click() - cy.get("[data-testid='page info']").contains("3 of 30 pages").should("be.visible") + cy.wait(0) + cy.get("button[aria-label='Go to page 3']") + .then($el => { + expect(Cypress.dom.isAttached($el).valueOf()).to.be.true + }) + .click() + cy.get("[data-testid='page info']").contains("3 of 10 pages").should("be.visible") // Check "Items per page" options cy.get("div[aria-haspopup='listbox']", { timeout: 10000 }).contains(5).click() @@ -402,43 +462,43 @@ describe("unpublished folders, published folders, and user's draft templates pag // Select 50 items cy.get("li[data-value='50']").click() - cy.get("p", { timeout: 10000 }).contains("1-50 of 150").should("be.visible") - cy.get("[data-testid='page info']").contains("1 of 3 pages").should("be.visible") + cy.get("p", { timeout: 10000 }).contains("1-50 of 50").should("be.visible") + cy.get("[data-testid='page info']").contains("1 of 1 pages").should("be.visible") }), it("should render pagination correctly when filtering the submission name", () => { const unpublishedPage1 = { folders: [ { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "draft-folder1", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, ], page: { page: 1, size: 5, totalPages: 6, totalFolders: 30 }, } const unpublishedPage2 = { folders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, ], page: { page: 2, size: 5, totalPages: 6, totalFolders: 30 }, } @@ -446,35 +506,35 @@ describe("unpublished folders, published folders, and user's draft templates pag const unpublished15 = { folders: [ { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "draft-folder1", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "test3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "test3", published: false }, ], page: { page: 1, size: 15, totalPages: 2, totalFolders: 30 }, } @@ -482,52 +542,52 @@ describe("unpublished folders, published folders, and user's draft templates pag const allUnpublished = { folders: [ { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "draft-folder1", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Biology", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "test3", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "test4", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "test5", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "test6", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub1", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub2", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "test3", published: false }, + { description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "test4", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "test5", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "test6", published: false }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub10", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "test7", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test8", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "test9", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test10", published: false }, + { description: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "test7", published: false }, + { description: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "test8", published: false }, + { description: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "test9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "test10", published: false }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], @@ -535,7 +595,7 @@ describe("unpublished folders, published folders, and user's draft templates pag published: false, }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], @@ -543,17 +603,17 @@ describe("unpublished folders, published folders, and user's draft templates pag published: false, }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "draft-folder3", published: false, }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "abc", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, + { description: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "abc", published: false }, + { description: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub9", published: false }, { - descriptioni: "d", + description: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], @@ -564,10 +624,22 @@ describe("unpublished folders, published folders, and user's draft templates pag page: { page: 1, size: 30, totalPages: 1, totalFolders: 30 }, } + // Mock responses for Published Folders + const publishedFoldersResponse5 = { + folders: [ + { description: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub1", published: false }, + { description: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub2", published: false }, + { description: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub3", published: false }, + { description: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub4", published: false }, + { description: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub5", published: false }, + ], + page: { page: 1, size: 5, totalPages: 1, totalFolders: 5 }, + } + cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=5&published=false", + url: "/folders?page=1&per_page=5&published=false&projectId=PROJECT1", }, unpublishedPage1 ) @@ -575,7 +647,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=2&per_page=5&published=false", + url: "/folders?page=2&per_page=5&published=false&projectId=PROJECT1", }, unpublishedPage2 ) @@ -583,7 +655,7 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=30&published=false", + url: "/folders?page=1&per_page=30&published=false&projectId=PROJECT1", }, allUnpublished ) @@ -595,11 +667,19 @@ describe("unpublished folders, published folders, and user's draft templates pag cy.intercept( { method: "GET", - url: "/folders?page=1&per_page=15&published=false", + url: "/folders?page=1&per_page=15&published=false&projectId=PROJECT1", }, unpublished15 ).as("unpublished15") + cy.intercept( + { + method: "GET", + url: "/folders?page=1&per_page=5&published=true&projectId=PROJECT1", + }, + publishedFoldersResponse5 + ) + cy.login() cy.get("[data-testid='page info']").contains("1 of 6 pages").should("be.visible") diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 5a164d72..100cc989 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -64,7 +64,9 @@ Cypress.on("uncaught:exception", () => { Cypress.Commands.add("login", () => { cy.visit(baseUrl) + cy.intercept("/folders*").as("getFolders") cy.get('a[data-testid="login-button"]').click() + cy.wait("@getFolders") }) Cypress.Commands.add("newSubmission", folderName => { diff --git a/src/__tests__/Home.test.tsx b/src/__tests__/Home.test.tsx index fabaa273..9a49eb05 100644 --- a/src/__tests__/Home.test.tsx +++ b/src/__tests__/Home.test.tsx @@ -21,7 +21,13 @@ jest.mock("react-i18next", () => ({ describe("HomePage", () => { const store = mockStore({ - user: { name: "Test User" }, + user: { + name: "Test User", + projects: [ + { projectId: "PROJECT1", projectName: "Project 1" }, + { projectId: "PROJECT2", projectName: "Project 2" }, + ], + }, }) beforeEach(() => { render( diff --git a/src/__tests__/Page403.test.tsx b/src/__tests__/Page403.test.tsx index 6a9b571a..a4c15d8a 100644 --- a/src/__tests__/Page403.test.tsx +++ b/src/__tests__/Page403.test.tsx @@ -36,45 +36,11 @@ describe("Page403", () => { test("redirects to Home Page after 10s", () => { jest.useFakeTimers() const store = mockStore({ - user: { name: "test" }, - unpublishedFolders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub", published: false }, - ], - publishedFolders: [ - { descriptioni: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub", published: false }, - ], - totalFolders: { - totalUnpublishedFolders: [ - { descriptioni: "d", drafts: [], folderId: "UNPUB1", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB2", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB3", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB4", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB5", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB6", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB7", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB8", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB9", metadataObjects: [], name: "Unpub", published: false }, - { descriptioni: "d", drafts: [], folderId: "UNPUB10", metadataObjects: [], name: "Unpub", published: false }, - ], - totalPublishedFolders: [ - { descriptioni: "d", drafts: [], folderId: "PUB1", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB2", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB3", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB4", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB5", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB6", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB7", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB8", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB9", metadataObjects: [], name: "Pub", published: false }, - { descriptioni: "d", drafts: [], folderId: "PUB10", metadataObjects: [], name: "Pub", published: false }, + user: { + name: "test", + projects: [ + { projectId: "PROJECT1", projectName: "Project 1" }, + { projectId: "PROJECT2", projectName: "Project 2" }, ], }, }) diff --git a/src/components/Home/SubmissionDataTable.tsx b/src/components/Home/SubmissionDataTable.tsx index 3ac61d16..62bac692 100644 --- a/src/components/Home/SubmissionDataTable.tsx +++ b/src/components/Home/SubmissionDataTable.tsx @@ -36,13 +36,18 @@ const DataTable = styled(DataGrid)(({ theme }) => ({ color: theme.palette.secondary.main, "&.MuiDataGrid-root .MuiDataGrid-columnHeader:focus, &.MuiDataGrid-root .MuiDataGrid-cell:focus": { outline: "none", - }, - "& .MuiDataGrid-columnHeaders": { - fontSize: "1.4rem", + position: "relative", }, "& .MuiDataGrid-columnSeparator": { display: "none", }, + "& .MuiDataGrid-cell:last-of-type:not(.MuiDataGrid-cell--withRenderer)": { + display: "none", + }, + "& .MuiDataGrid-columnHeadersInner, .MuiDataGrid-columnHeader, .MuiDataGrid-virtualScrollerRenderZone, .MuiDataGrid-cell, .MuiDataGrid-cell--withRenderer": + { + width: "100% !important", + }, "& .MuiDataGrid-columnHeaderTitleContainer": { padding: 0, "& > *": { fontWeight: 700 }, @@ -56,19 +61,17 @@ const DataTable = styled(DataGrid)(({ theme }) => ({ }, "& .MuiDataGrid-row": { border: `1px solid ${theme.palette.secondary.light}`, + width: "100% !important", }, - "& .MuiDataGrid-virtualScrollerContent": { - fontSize: "1.6rem", - }, - "& .MuiDataGrid-cell--withRenderer": { - width: "100%", - maxWidth: "none !important", - }, + "& .MuiDataGrid-actionsCell": { color: theme.palette.primary.main, - marginRight: "1rem", - "& .MuiMenuItem-root": { - fontSize: "1.6rem", + alignItems: "flex-start", + [theme.breakpoints.down("sm")]: { + display: "flex", + flexDirection: "column", + gridGap: 0, + "& .MuiMenuItem-root.MuiMenuItem-gutters.MuiButtonBase-root": { minHeight: "0 !important" }, }, }, })) @@ -95,12 +98,10 @@ const SubmissionDataTable: React.FC = props => { field: "name", headerName: "Name", sortable: false, - width: 310, }, { field: "dateCreated", headerName: "Date created", - width: 250, type: "date", valueFormatter: (params: GridValueFormatterParams): GridCellValue => { const { convertedDate } = params.value as Record @@ -115,13 +116,6 @@ const SubmissionDataTable: React.FC = props => { { field: "lastModifiedBy", headerName: "Last modified by", - width: 250, - sortable: false, - }, - { - field: "cscProject", - headerName: "CSC Project", - width: 250, sortable: false, }, { diff --git a/src/components/Home/UserDraftTemplateActions.tsx b/src/components/Home/UserDraftTemplateActions.tsx index a0824f67..33fbd7fa 100644 --- a/src/components/Home/UserDraftTemplateActions.tsx +++ b/src/components/Home/UserDraftTemplateActions.tsx @@ -10,7 +10,7 @@ import WizardFillObjectDetailsForm from "components/NewDraftWizard/WizardForms/W import { ResponseStatus } from "constants/responseStatus" import { ObjectStatus } from "constants/wizardObject" import { updateStatus } from "features/statusMessageSlice" -import { deleteTemplateByAccessionId } from "features/userSlice" +import { deleteTemplateByAccessionId } from "features/templateSlice" import { setCurrentObject, resetCurrentObject } from "features/wizardCurrentObjectSlice" import { setObjectType, resetObjectType } from "features/wizardObjectTypeSlice" import { setFolder } from "features/wizardSubmissionFolderSlice" diff --git a/src/components/Home/UserDraftTemplates.tsx b/src/components/Home/UserDraftTemplates.tsx index 5f363f0b..6e8172ca 100644 --- a/src/components/Home/UserDraftTemplates.tsx +++ b/src/components/Home/UserDraftTemplates.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useEffect, useState } from "react" import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown" import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp" @@ -17,10 +17,11 @@ import { makeStyles } from "@mui/styles" import UserDraftTemplateActions from "./UserDraftTemplateActions" -import { setTemplateAccessionIds } from "features/templatesSlice" +import { setTemplateAccessionIds } from "features/templateAccessionIdsSlice" +import { getTemplates } from "features/templateSlice" import { useAppSelector, useAppDispatch } from "hooks" import { ObjectInsideFolderWithTags } from "types" -import { formatDisplayObjectType, getUserTemplates, getItemPrimaryText } from "utils" +import { formatDisplayObjectType, getItemPrimaryText, getUserTemplates } from "utils" const useStyles = makeStyles(theme => ({ card: { @@ -65,19 +66,25 @@ const useStyles = makeStyles(theme => ({ const UserDraftTemplates: React.FC = () => { const classes = useStyles() - const user = useAppSelector(state => state.user) + const dispatch = useAppDispatch() + + const projectId = useAppSelector(state => state.projectId) + const templates: Array | [] = useAppSelector(state => state.templates) const objectTypesArray = useAppSelector(state => state.objectTypesArray) const templateAccessionIds = useAppSelector(state => state.templateAccessionIds) - const templates = user.templates ? getUserTemplates(user.templates, objectTypesArray) : [] - + const displayTemplates = getUserTemplates(templates, objectTypesArray) type TemplateGroupProps = { draft: { [schema: string]: ObjectInsideFolderWithTags[] } } + useEffect(() => { + dispatch(getTemplates(projectId)) + }, [dispatch]) + // Render when there is user's draft template(s) const DraftList = () => { return ( - {templates.map((draft: { [key: string]: ObjectInsideFolderWithTags[] }, index: number) => ( + {displayTemplates.map((draft: { [key: string]: ObjectInsideFolderWithTags[] }, index: number) => ( ))} @@ -87,7 +94,6 @@ const UserDraftTemplates: React.FC = () => { const TemplateGroup = (props: TemplateGroupProps) => { const { draft } = props - const dispatch = useAppDispatch() const [checkedItems, setCheckedItems] = useState(templateAccessionIds) const handleChange = (accessionId: string) => { diff --git a/src/components/NewDraftWizard/WizardComponents/WizardFooter.tsx b/src/components/NewDraftWizard/WizardComponents/WizardFooter.tsx index a42caabd..e500708e 100644 --- a/src/components/NewDraftWizard/WizardComponents/WizardFooter.tsx +++ b/src/components/NewDraftWizard/WizardComponents/WizardFooter.tsx @@ -47,6 +47,7 @@ const useStyles = makeStyles(theme => ({ const WizardFooter: React.FC = () => { const classes = useStyles() const dispatch = useAppDispatch() + const projectId = useAppSelector(state => state.projectId) const folder = useAppSelector(state => state.submissionFolder) const [dialogOpen, setDialogOpen] = useState(false) @@ -81,7 +82,7 @@ const WizardFooter: React.FC = () => { resetDispatch() } else if (alertWizard && alertType === "publish") { if (formData && formData?.length > 0) { - await saveDraftsAsTemplates(formData, dispatch) + await saveDraftsAsTemplates(projectId, formData, dispatch) } // Publish the folder dispatch(publishFolderContent(folder)) diff --git a/src/components/NewDraftWizard/WizardForms/WizardFillObjectDetailsForm.tsx b/src/components/NewDraftWizard/WizardForms/WizardFillObjectDetailsForm.tsx index fa1967f0..f6f20212 100644 --- a/src/components/NewDraftWizard/WizardForms/WizardFillObjectDetailsForm.tsx +++ b/src/components/NewDraftWizard/WizardForms/WizardFillObjectDetailsForm.tsx @@ -28,7 +28,7 @@ import { setDraftStatus, resetDraftStatus } from "features/draftStatusSlice" import { setFileTypes } from "features/fileTypesSlice" import { resetFocus } from "features/focusSlice" import { updateStatus } from "features/statusMessageSlice" -import { replaceTemplate } from "features/userSlice" +import { updateTemplateDisplayTitle } from "features/templateSlice" import { setCurrentObject, resetCurrentObject } from "features/wizardCurrentObjectSlice" import { deleteObjectFromFolder, replaceObjectInFolder } from "features/wizardSubmissionFolderSlice" import { useAppSelector, useAppDispatch } from "hooks" @@ -246,8 +246,8 @@ const FormContent = ({ const draftStatus = useAppSelector(state => state.draftStatus) const alert = useAppSelector(state => state.alert) const clearForm = useAppSelector(state => state.clearForm) - const user = useAppSelector(state => state.user) + const templates = useAppSelector(state => state.templates) const methods = useForm({ mode: "onBlur", resolver }) const [currentObjectId, setCurrentObjectId] = useState(currentObject?.accessionId) @@ -406,35 +406,28 @@ const FormContent = ({ const cleanedValues = getCleanedValues() if (checkFormCleanedValuesEmpty(cleanedValues)) { - const response = await templateAPI.patchTemplateFromJSON(objectType, currentObject.accessionId, cleanedValues) - - const templates = user.templates - const index = templates.findIndex( - (item: { accessionId: string }) => item.accessionId === currentObject.accessionId + const index = + templates?.findIndex((item: { accessionId: string }) => item.accessionId === currentObject.accessionId) || 0 + const response = await templateAPI.patchTemplateFromJSON( + objectType, + currentObject.accessionId, + cleanedValues, + index ) + const displayTitle = getObjectDisplayTitle(objectType, cleanedValues as unknown as ObjectDisplayValues) if (response.ok) { closeDialog() - dispatch(replaceTemplate(index, displayTitle, currentObject.accessionId)) - .then(() => - dispatch( - updateStatus({ - status: ResponseStatus.success, - response: response, - helperText: "", - }) - ) - ) - .catch(error => { - dispatch( - updateStatus({ - status: ResponseStatus.error, - response: error, - helperText: "Cannot replace template", - }) - ) + dispatch(updateTemplateDisplayTitle({ accessionId: currentObject.accessionId, displayTitle: displayTitle })) + + dispatch( + updateStatus({ + status: ResponseStatus.success, + response: response, + helperText: "", }) + ) } else { dispatch( updateStatus({ diff --git a/src/components/NewDraftWizard/WizardHooks/WizardSaveTemplatesHook.tsx b/src/components/NewDraftWizard/WizardHooks/WizardSaveTemplatesHook.tsx index 61710989..c7a5310b 100644 --- a/src/components/NewDraftWizard/WizardHooks/WizardSaveTemplatesHook.tsx +++ b/src/components/NewDraftWizard/WizardHooks/WizardSaveTemplatesHook.tsx @@ -8,7 +8,11 @@ import templateAPIService from "services/templateAPI" import { ObjectInsideFolderWithTags } from "types" import { getOrigObjectType, getObjectDisplayTitle } from "utils" -const saveDraftsAsTemplates = async (formData: ObjectInsideFolderWithTags[], dispatch: (reducer: unknown) => void) => { +const saveDraftsAsTemplates = async ( + projectId: string, + formData: ObjectInsideFolderWithTags[], + dispatch: (reducer: unknown) => void +) => { // Filter unique draft-schemas existing in formData const draftSchemas = formData .map((item: { schema: string }) => item.schema) @@ -40,7 +44,7 @@ const saveDraftsAsTemplates = async (formData: ObjectInsideFolderWithTags[], dis // Remove unnecessary values such as "date" // Add the object in the form of {template: draft's values, tags: {displayTitle}} to the array - draftsArr.push({ template: { ...omit(draftResponse.data, OmitObjectValues) }, ...draftTags }) + draftsArr.push({ projectId, template: { ...omit(draftResponse.data, OmitObjectValues) }, ...draftTags }) } catch (err) { dispatch( updateStatus({ diff --git a/src/components/NewDraftWizard/WizardSteps/WizardCreateFolderStep.tsx b/src/components/NewDraftWizard/WizardSteps/WizardCreateFolderStep.tsx index 8fd2ed08..4747f9d2 100644 --- a/src/components/NewDraftWizard/WizardSteps/WizardCreateFolderStep.tsx +++ b/src/components/NewDraftWizard/WizardSteps/WizardCreateFolderStep.tsx @@ -17,7 +17,7 @@ import UserDraftTemplates from "components/Home/UserDraftTemplates" import transformTemplatesToDrafts from "components/NewDraftWizard/WizardHooks/WizardTransformTemplatesToDrafts" import { ResponseStatus } from "constants/responseStatus" import { updateStatus } from "features/statusMessageSlice" -import { resetTemplateAccessionIds } from "features/templatesSlice" +import { resetTemplateAccessionIds } from "features/templateAccessionIdsSlice" import { createNewDraftFolder, updateNewDraftFolder } from "features/wizardSubmissionFolderSlice" import { useAppSelector, useAppDispatch } from "hooks" import type { FolderDataFromForm, CreateFolderFormRef } from "types" @@ -64,8 +64,9 @@ const useStyles = makeStyles(() => ({ const CreateFolderForm = ({ createFolderFormRef }: { createFolderFormRef: CreateFolderFormRef }) => { const classes = useStyles() const dispatch = useAppDispatch() + const projectId = useAppSelector(state => state.projectId) const folder = useAppSelector(state => state.submissionFolder) - const user = useAppSelector(state => state.user) + const templates = useAppSelector(state => state.templates) const templateAccessionIds = useAppSelector(state => state.templateAccessionIds) const { @@ -79,8 +80,8 @@ const CreateFolderForm = ({ createFolderFormRef }: { createFolderFormRef: Create const onSubmit = async (data: FolderDataFromForm) => { // Transform the format of templates to drafts with proper values to be added to current folder or new folder const selectedDraftsArray = - user.templates && folder?.folderId - ? await transformTemplatesToDrafts(templateAccessionIds, user.templates, folder.folderId, dispatch) + templates && folder?.folderId + ? await transformTemplatesToDrafts(templateAccessionIds, templates, folder.folderId, dispatch) : [] if (folder && folder?.folderId) { @@ -94,7 +95,7 @@ const CreateFolderForm = ({ createFolderFormRef }: { createFolderFormRef: Create }) } else { // Create a new folder with selected templates as drafts - dispatch(createNewDraftFolder(data, selectedDraftsArray)) + dispatch(createNewDraftFolder(projectId, data, selectedDraftsArray)) .then(response => { const folderId = response.data.folderId navigate({ pathname: pathWithLocale(`newdraft/${folderId}`), search: "step=1" }) diff --git a/src/features/projectIdSlice.tsx b/src/features/projectIdSlice.tsx new file mode 100644 index 00000000..8209fd7e --- /dev/null +++ b/src/features/projectIdSlice.tsx @@ -0,0 +1,14 @@ +import { createSlice } from "@reduxjs/toolkit" + +const initialState = "" + +const projectIdSlice = createSlice({ + name: "project", + initialState, + reducers: { + setProjectId: (_state, action) => action.payload, + resetProjectId: () => initialState, + }, +}) +export const { setProjectId, resetProjectId } = projectIdSlice.actions +export default projectIdSlice.reducer diff --git a/src/features/templatesSlice.tsx b/src/features/templateAccessionIdsSlice.tsx similarity index 100% rename from src/features/templatesSlice.tsx rename to src/features/templateAccessionIdsSlice.tsx diff --git a/src/features/templateSlice.tsx b/src/features/templateSlice.tsx new file mode 100644 index 00000000..b915c13e --- /dev/null +++ b/src/features/templateSlice.tsx @@ -0,0 +1,45 @@ +import { createSlice } from "@reduxjs/toolkit" +import _reject from "lodash/reject" + +import templateAPIService from "services/templateAPI" +import { ObjectInsideFolderWithTags, APIResponse, DispatchReducer } from "types" + +const initialState: Array | [] = [] + +const templateSlice = createSlice({ + name: "project", + initialState, + reducers: { + setTemplates: (_state, action) => action.payload, + updateTemplateDisplayTitle: (state, action) => { + const selectedTemplate = state.find(item => item.accessionId === action.payload.accessionId) + if (selectedTemplate) { + selectedTemplate.tags.displayTitle = action.payload.displayTitle + } + }, + deleteTemplateByAccessionId: (state, action) => { + state = _reject(state, (template: { accessionId: string }) => { + return template.accessionId === action.payload + }) + }, + resetTemplates: () => initialState, + }, +}) +export const { setTemplates, updateTemplateDisplayTitle, deleteTemplateByAccessionId, resetTemplates } = + templateSlice.actions +export default templateSlice.reducer + +export const getTemplates = + (projectId: string) => + async (dispatch: (reducer: DispatchReducer) => void): Promise => { + const response = await templateAPIService.getTemplates({ projectId }) + + return new Promise((resolve, reject) => { + if (response.ok) { + dispatch(setTemplates(response.data)) + resolve(response) + } else { + reject(JSON.stringify(response)) + } + }) + } diff --git a/src/features/userSlice.tsx b/src/features/userSlice.tsx index 16ea0d74..a4f9c848 100644 --- a/src/features/userSlice.tsx +++ b/src/features/userSlice.tsx @@ -1,14 +1,12 @@ import { createSlice } from "@reduxjs/toolkit" -import _reject from "lodash/reject" import userAPIService from "services/usersAPI" -import type { User, APIResponse, DispatchReducer, ObjectInsideFolderWithTags, ObjectTags } from "types" +import type { User, APIResponse, DispatchReducer, ObjectInsideFolderWithTags } from "types" const initialState: User = { id: "", name: "", - templates: [], - folders: [], + projects: [], } const userSlice = createSlice({ @@ -16,24 +14,11 @@ const userSlice = createSlice({ initialState, reducers: { setUser: (_state, action) => action.payload, - updateTemplateDisplayTitle: (state: { templates: ObjectInsideFolderWithTags[] }, action) => { - const selectedTemplate = state.templates.find( - (item: { accessionId: string }) => item.accessionId === action.payload.accessionId - ) - if (selectedTemplate) { - selectedTemplate.tags.displayTitle = action.payload.displayTitle - } - }, - deleteTemplateByAccessionId: (state, action) => { - state.templates = _reject(state.templates, (template: { accessionId: string }) => { - return template.accessionId === action.payload - }) - }, resetUser: () => initialState, }, }) -export const { setUser, resetUser, updateTemplateDisplayTitle, deleteTemplateByAccessionId } = userSlice.actions +export const { setUser, resetUser } = userSlice.actions export default userSlice.reducer export const fetchUserById = @@ -46,8 +31,7 @@ export const fetchUserById = const user: User = { id: response.data.userId, name: response.data.name, - templates: response.data.templates, - folders: response.data.folders, + projects: response.data.projects, } dispatch(setUser(user)) resolve(response) @@ -70,21 +54,3 @@ export const addDraftsToUser = } }) } - -export const replaceTemplate = - (index: number, displayTitle: string, accessionId: string) => - async (dispatch: (reducer: DispatchReducer) => void): Promise => { - const tags: ObjectTags = { displayTitle: displayTitle } - - const changes = [{ op: "replace", path: `/templates/${index}/tags`, value: tags }] - const response = await userAPIService.patchUserById("current", changes) - - return new Promise((resolve, reject) => { - if (response.ok) { - dispatch(updateTemplateDisplayTitle({ accessionId: accessionId, displayTitle: displayTitle })) - resolve(response) - } else { - reject(JSON.stringify(response)) - } - }) - } diff --git a/src/features/wizardSubmissionFolderSlice.tsx b/src/features/wizardSubmissionFolderSlice.tsx index 9fa5fcea..edf72e52 100644 --- a/src/features/wizardSubmissionFolderSlice.tsx +++ b/src/features/wizardSubmissionFolderSlice.tsx @@ -87,10 +87,11 @@ export const { export default wizardSubmissionFolderSlice.reducer export const createNewDraftFolder = - (folderDetails: FolderDataFromForm, drafts?: ObjectInsideFolderWithTags[]) => + (projectId: string, folderDetails: FolderDataFromForm, drafts?: ObjectInsideFolderWithTags[]) => async (dispatch: (reducer: DispatchReducer) => void): Promise => { - const folderForBackend: FolderDetails = { + const folderForBackend: FolderDetails & { projectId: string } = { ...folderDetails, + projectId, published: false, metadataObjects: [], drafts: drafts ? drafts : [], diff --git a/src/rootReducer.ts b/src/rootReducer.ts index 715aa17a..153bcbbb 100644 --- a/src/rootReducer.ts +++ b/src/rootReducer.ts @@ -10,9 +10,11 @@ import localeReducer from "features/localeSlice" import objectTypesArrayReducer from "features/objectTypesArraySlice" import openedDoiFormReducer from "features/openedDoiFormSlice" import openedRowsReducer from "features/openedRowsSlice" +import projectReducer from "features/projectIdSlice" import selectedFolderReducer from "features/selectedFolderSlice" import statusMessageReducer from "features/statusMessageSlice" -import templatesReducer from "features/templatesSlice" +import templateAccessionIdsReducer from "features/templateAccessionIdsSlice" +import templatesReducer from "features/templateSlice" import userReducer from "features/userSlice" import wizardAlertReducer from "features/wizardAlertSlice" import currentObjectReducer from "features/wizardCurrentObjectSlice" @@ -36,10 +38,12 @@ const rootReducer = combineReducers({ objectTypesArray: objectTypesArrayReducer, openedRows: openedRowsReducer, clearForm: clearFormReducer, - templateAccessionIds: templatesReducer, + templates: templatesReducer, + templateAccessionIds: templateAccessionIdsReducer, autocompleteField: autocompleteReducer, fileTypes: fileTypesReducer, openedDoiForm: openedDoiFormReducer, + projectId: projectReducer, }) export type RootState = ReturnType diff --git a/src/services/folderAPI.ts b/src/services/folderAPI.ts index 162e6a2d..fdba7e01 100644 --- a/src/services/folderAPI.ts +++ b/src/services/folderAPI.ts @@ -24,11 +24,11 @@ const deleteFolderById = async (folderId: string): Promise => { return await api.delete(`/${folderId}`) } -const getFolders = async (params?: { - page?: number - per_page?: number - published?: boolean - name?: string +const getFolders = async (params: { + page: number + per_page: number + published: boolean + projectId: string }): Promise => { return await api.get("", params) } diff --git a/src/services/templateAPI.ts b/src/services/templateAPI.ts index da81fffe..d94c5dae 100644 --- a/src/services/templateAPI.ts +++ b/src/services/templateAPI.ts @@ -24,19 +24,30 @@ const getTemplateByAccessionId = async (objectType: string, accessionId: string) const patchTemplateFromJSON = async ( objectType: string, accessionId: string, - JSONContent: Record + JSONContent: Record, + index: number ): Promise => { const draftTags = { tags: { displayTitle: getObjectDisplayTitle(objectType, JSONContent as ObjectDisplayValues) } } - return await api.patch(`/${objectType}/${accessionId}`, { ...omit(JSONContent, OmitObjectValues), draftTags }) + const draftIndex = { index } + return await api.patch(`/${objectType}/${accessionId}`, { + ...omit(JSONContent, OmitObjectValues), + draftTags, + draftIndex, + }) } const deleteTemplateByAccessionId = async (objectType: string, accessionId: string): Promise => { return await api.delete(`/${objectType}/${accessionId}`) } +const getTemplates = async (params: { projectId: string }): Promise => { + return await api.get("", params) +} + export default { createTemplatesFromJSON, getTemplateByAccessionId, patchTemplateFromJSON, deleteTemplateByAccessionId, + getTemplates, } diff --git a/src/theme.ts b/src/theme.ts index 2de9bb51..3355c8cc 100644 --- a/src/theme.ts +++ b/src/theme.ts @@ -9,13 +9,13 @@ const defaultTheme = createTheme() const palette = { primary: { - // green + // green colors main: "#006778", light: "#c2dbdf", lightest: "#e5eff1", }, secondary: { - // grey + // grey colors main: "#595959", light: "#dfe1e3", }, @@ -118,8 +118,14 @@ let CSCtheme = createTheme({ }, MuiDataGrid: { styleOverrides: { - columnHeader: fontSizeBreakpoints, - row: fontSizeBreakpoints, + cell: { minWidth: "none !important", maxWidth: "none !important" }, + columnHeader: { minWidth: "none !important", maxWidth: "none !important", fontSizeBreakpoints }, + row: { minWidth: "none !important", maxWidth: "none !important", fontSizeBreakpoints }, + }, + }, + MuiMenuItem: { + styleOverrides: { + root: { padding: 0, fontSizeBreakpoints }, }, }, MuiTab: { diff --git a/src/types/index.ts b/src/types/index.ts index 6971b3cc..f995ddff 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -21,8 +21,7 @@ import { export type User = { id: string name: string - templates: Array - folders: Array + projects: Array<{ projectId: string; projectNumber: string }> } export type Schema = "study" | "sample" | "experiment" | "run" | "analysis" | "dac" | "policy" | "dataset" @@ -74,7 +73,6 @@ export type FolderRow = { name: string dateCreated?: number lastModifiedBy: string - cscProject: string } export type FolderDataFromForm = { diff --git a/src/views/Home.tsx b/src/views/Home.tsx index 871342ae..9542f087 100644 --- a/src/views/Home.tsx +++ b/src/views/Home.tsx @@ -4,9 +4,12 @@ import Box from "@mui/material/Box" import Button from "@mui/material/Button" import CircularProgress from "@mui/material/CircularProgress" import Container from "@mui/material/Container" +import FormControl from "@mui/material/FormControl" import Grid from "@mui/material/Grid" import Link from "@mui/material/Link" +import MenuItem from "@mui/material/MenuItem" import Paper from "@mui/material/Paper" +import Select, { SelectChangeEvent } from "@mui/material/Select" import { styled } from "@mui/material/styles" import Tab from "@mui/material/Tab" import Tabs from "@mui/material/Tabs" @@ -18,14 +21,30 @@ import SubmissionDataTable from "components/Home/SubmissionDataTable" import WizardSearchBox from "components/NewDraftWizard/WizardComponents/WizardSearchBox" import { ResponseStatus } from "constants/responseStatus" import { FolderSubmissionStatus } from "constants/wizardFolder" +import { setProjectId } from "features/projectIdSlice" import { updateStatus } from "features/statusMessageSlice" import { resetObjectType } from "features/wizardObjectTypeSlice" import { deleteFolderAndContent, resetFolder } from "features/wizardSubmissionFolderSlice" -import { useAppDispatch } from "hooks" +import { useAppDispatch, useAppSelector } from "hooks" import folderAPIService from "services/folderAPI" import type { FolderDetailsWithId, FolderRow } from "types" import { pathWithLocale } from "utils" +const ProjectDropdown = styled(FormControl)(({ theme }) => ({ + marginTop: "1rem", + marginBottom: "2rem", + "& .MuiOutlinedInput-root": { + width: "40rem", + height: "4rem", + backgroundColor: theme.palette.common.white, + color: theme.palette.secondary.main, + border: `0.15rem solid ${theme.palette.secondary.main}`, + borderRadius: "0.375rem", + }, + "& .MuiOutlinedInput-notchedOutline": { border: "none" }, + "& svg": { fontSize: "2rem" }, +})) + const FrontPageContainer = styled(Container)(() => ({ display: "flex", minHeight: "100vh", @@ -61,13 +80,13 @@ const getDisplayRows = (items: Array): Array => name: item.name, dateCreated: item.dateCreated, lastModifiedBy: "TBA", - cscProject: "TBA", })) } const Home: React.FC = () => { const dispatch = useAppDispatch() - + const user = useAppSelector(state => state.user) + const projectId = useAppSelector(state => state.projectId) const [isFetchingFolders, setFetchingFolders] = useState(true) // Selected tab value @@ -96,6 +115,15 @@ const Home: React.FC = () => { const [numberOfDraftSubmissions, setNumberOfDraftSubmissions] = useState(0) const [numberOfPublishedSubmissions, setNumberOfPublishedSubmissions] = useState(0) + /* + * Set the current projectId as the first one if no projectId has been selected + */ + useEffect(() => { + if (user.projects.length > 0) { + dispatch(setProjectId(user.projects[0].projectId)) + } + }, [user]) + /* * Get draft and published submissions for the first page in data table */ @@ -106,9 +134,15 @@ const Home: React.FC = () => { page: 1, per_page: 5, published: false, + projectId: projectId, }) - const publishedResponse = await folderAPIService.getFolders({ page: 1, per_page: 5, published: true }) + const publishedResponse = await folderAPIService.getFolders({ + page: 1, + per_page: 5, + published: true, + projectId: projectId, + }) if (isMounted) { if (unpublishedResponse.ok && publishedResponse.ok) { @@ -136,11 +170,11 @@ const Home: React.FC = () => { } } } - getFolders() + if (projectId) getFolders() return () => { isMounted = false } - }, [dispatch, tabValue]) + }, [dispatch, tabValue, projectId]) /* * Get the list of all draft submissions @@ -154,6 +188,7 @@ const Home: React.FC = () => { page: 1, per_page: numberOfDraftSubmissions, published: false, + projectId, }) setAllDraftSubmissions(unpublishedResponse.data?.folders) } @@ -177,6 +212,7 @@ const Home: React.FC = () => { page: 1, per_page: numberOfPublishedSubmissions, published: true, + projectId, }) setAllPublishedSubmissions(publishedResponse.data?.folders) } @@ -202,6 +238,26 @@ const Home: React.FC = () => { dispatch(resetFolder()) } + const handleProjectIdChange = (event: SelectChangeEvent) => { + dispatch(setProjectId(event.target.value)) + } + + const projectSelection = ( + + + + ) + const handleChangeTab = (event, newValue) => { setTabValue(newValue) if (filteringText) getFilter(filteringText, newValue) @@ -235,7 +291,8 @@ const Home: React.FC = () => { const response = await folderAPIService.getFolders({ page: 1, per_page: numberOfItems, - published: folderType === FolderSubmissionStatus.published, + published: folderType === FolderSubmissionStatus.unpublished ? false : true, + projectId, }) if (response.ok) { @@ -273,7 +330,8 @@ const Home: React.FC = () => { const response = await folderAPIService.getFolders({ page: page + 1, per_page: folderType === FolderSubmissionStatus.unpublished ? draftItemsPerPage : publishedItemsPerPage, - published: folderType === FolderSubmissionStatus.published, + published: folderType === FolderSubmissionStatus.unpublished ? false : true, + projectId, }) if (response.ok) { @@ -359,10 +417,11 @@ const Home: React.FC = () => { // Render either unpublished or published folders based on selected tab return ( - + My submissions + {projectSelection}