projectcaluma / caluma

A collaborative form editing service
https://caluma.io/
GNU General Public License v3.0
67 stars 26 forks source link

RFC: New question type "MultipleFileQuestion" #1780

Open czosel opened 2 years ago

czosel commented 2 years ago

When using file questions, it is often desired that more that one file can be uploaded. Currently this is only possible in Caluma using TableQuestions, which doesn't yield a good UX when the table form consists of just one FileQuestion.

We'd propose to add a new question type "MultipleFileQuestion" which is very similar to the existing "FileQuestion", but allows uploading more than one file.

The API could look like this:

FileAnswer (existing, just for reference)

Request:

{
    "operationName": "SaveDocumentFileAnswer",
    "variables": {
        "input": {
            "question": "some-slug",
            "document": "7da68336-8ccd-47cb-8800-81e4444bc649",
            "value": "test.pdf"
        }
    },
    "query": "mutation SaveDocumentFileAnswer($input: SaveDocumentFileAnswerInput!) { ... }"
}

Response:

{
  "answer": {
    "id": "some-id",
    "question": {
      "slug": "some-slug",
      "__typename": "FileQuestion"
    },
    "fileValue": {
      "id": "some-id",
      "uploadUrl": "",
      "downloadUrl": "",
      "metadata": null,
      "name": "pdf-test (copy).pdf",
      "__typename": "File"
    },
  },
}

MultipleFileAnswer

Request:

{
    "operationName": "SaveDocumentMultipleFileAnswer",
    "variables": {
        "input": {
            "question": "some-id",
            "document": "7da68336-8ccd-47cb-8800-81e4444bc649",
            "value": [
              // existing file
              {
                "id": <File UUID>,
                "name": "pdf-test (copy).pdf"
              },
              {
                "name": "pdf-test (copy).pdf" // new file
              }
              // deleting files: just leave them out
            ]
        }
    },
    "query": "mutation SaveDocumentFileAnswer($input: SaveDocumentFileAnswerInput!) { ... }"
}

Response:

{
  "answer": {
    "id": "some-id",
    "question": {
      "slug": "some-slug",
      "__typename": "MultipleFileQuestion"
    },
    "multipleFileValue": [
      {
        "id": "some_id",
        "uploadUrl": "",
        "downloadUrl": "",
        "metadata": null,
        "name": "pdf-test (copy).pdf",
        "__typename": "File"
      },
      ...
    ]
  }
}
StephanH90 commented 2 years ago

Does this allow you to rename the files as well by supplying an ID with a different name?

derrabauke commented 2 years ago

Does this allow you to rename the files as well by supplying an ID with a different name?

Currently this is not intended. For this use-case you would have to delete the file and upload it again with the correct name.

StephanH90 commented 2 years ago

But doesn't that go against the general caluma API where you can simply supply the same mutation with new values to change an existing resource?

mutation changeTitle {
  SaveTextQuestion(input: { slug: "some-question", label: "cool new label" }) {
    question {
      id
    }
  }
}

The only 2 places where I had to implement or work with file uploads (TCS and alexandria) both required the renaming of files.

If it isn't much effort it might be worth doing it now, otherwise I guess we wait until its requested.

winged commented 2 years ago

Does this allow you to rename the files as well by supplying an ID with a different name?

Currently this is not intended. For this use-case you would have to delete the file and upload it again with the correct name.

Sorry for correcting you, but what @StephanH90 asks is indeed possible with the current backend implementation: If you provide a new name for a given file ID, it will rename it internally and do the work needed so the file is moved in Minio as well. See the update_answer_files() implementation in the PR.

derrabauke commented 2 years ago

Oh sorry, for the incorrect feedback then! But this feature will not be part of the current ember-caluma implementation for now.

winged commented 2 years ago

Oh sorry, for the incorrect feedback then! But this feature will not be part of the current ember-caluma implementation for now.

So what's the ember-caluma release plan for this? Just not ready jet, or is it delayed on purpose?