Skip to content

feat: import CSV UI#9437

Closed
david-allison wants to merge 9 commits into
ankidroid:mainfrom
david-allison:6772-import
Closed

feat: import CSV UI#9437
david-allison wants to merge 9 commits into
ankidroid:mainfrom
david-allison:6772-import

Conversation

@david-allison

Copy link
Copy Markdown
Member

Pull Request template

Purpose / Description

We want to allow the user to import CSVs

Fixes

Fixes #6772

Approach

We already have the python code converted. We use a fragment-based approach for the UI

  • Host Fragment
    • Load File
    • Options
      • Delimiter Dialog
      • Mapping (CSV -> Field) Fragment
    • Load/Display Log

⚠️ We use Kotlin coroutines for async, mostly as I'd like to try them out as a new async mechanism, I'm very open to changing this if it's not ideal

  • Parcelize has been added to reduce the code needed to create bundles

How Has This Been Tested?

Some unit tests, tested on my phone

⚠️ Large feature, likely needs more integration tests on the progress/end state

Checklist

  • You have not changed whitespace unnecessarily (it makes diffs hard to read)
  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • Your code follows the style of the project (e.g. never omit braces in if statements)
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner
    • ❌See below
Screenshots

image
image
image
image
image
image

Accessibility failures

image
image
image
image
image
image

@david-allison david-allison marked this pull request as draft August 22, 2021 21:03
@david-allison david-allison added the Blocked by dependency Currently blocked by some other dependent / related change label Aug 22, 2021
@david-allison

david-allison commented Aug 22, 2021

Copy link
Copy Markdown
Member Author

Contains commits from #9423, best to get that in first

@mikehardy

Copy link
Copy Markdown
Member

#9423 is in!

@david-allison david-allison removed the Blocked by dependency Currently blocked by some other dependent / related change label Aug 22, 2021
@david-allison

Copy link
Copy Markdown
Member Author

I expect this'll pass CI now. Will remove the draft if it does

Review questions:

  • should we backup before import? Will this potentially make restoration less likely (if a user messes up, I feel they're likely to try again a few times)
  • How do we we want to handle the accessibility issues?

@david-allison david-allison marked this pull request as ready for review August 22, 2021 23:09
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.java
Comment thread AnkiDroid/src/main/java/com/ichi2/anki/importer/CsvMapping.kt Outdated
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

downloadPercentage = view.findViewById(R.id.import_progress_text)

@david-allison david-allison Aug 23, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would other reviewers feel about using a DI framework to reduce code here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to Google it, and I see no issue here.
I mean, I'm never totally fan of adding state, but I'm not fan of huge method either

AnkiDroidApp.sendExceptionReport(ex, "import failed")
onException(ex)
}
GlobalScope.launch(Dispatchers.Main + exceptionHandler) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Arthur-Milchior pinging for your opinion on me testing a new async mechanism, and thoughts on whether this API is too far from what we're currently using

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know the first thing about GlobalScope.launch, so hard to tell.
My main concern with switching with a new async mechanism is that all async code currently assume that a single background thread runs at one point in time (appart from synchronization thread). In particular, it means that there is never two activities touching the database at the same time.
I suppose that "performImport" will write to the database.
I can't imagine any actual trouble, but even if it works as expected, still not a great idea to break this invariant until we know how we want async to evolve.

Plus, I'd assume it make testing it more complex as you can't use the same tooling to move this method to frontend

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed in general that testing a new async exec mechanism as a sort of one-off mixed in another PR doesn't seem like the right spot.

const val RESULT_BUNDLE_OPTIONS = "importOptions"

/**
*

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing comment

@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author and removed Needs Review labels Aug 24, 2021
usage: `collection.models[noteTypeId]!!`
Handles a user selecting a file

For use in the CSV Import (issue 6772)
Handles obtaining a single character (and allows tab input)

For use in the CSV Import (issue 6772)
Handles the UI of mapping from CSV to Note fields/tags

For use in the CSV Import (issue 6772)
Also made NoteImporter/TextImporter mutable to handle this
as is in the Python

Handles the UI of all options when mapping from CSV to Note fields/tags

For use in the CSV Import (issue 6772)
For CSV import: Issue 6772
Performs import, shows progress and results

For use in the CSV Import (issue 6772)
Ties all the fragments together and responsible for workflow

Related: 6772
Adds activity, linked to host fragment
and implemented as menu in DeckPicker

Fixes 6772
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Aug 24, 2021
@david-allison

This comment has been minimized.

@mindinsomnia

Copy link
Copy Markdown

Import-Workflow
UI Mockup for CSV Import Workflow:

Rationale:

Menu -> Import Cards: Clearly labelled now so users should be able to tell easily from that menu item that if they desire to import some cards, to follow that pathway.

Import Cards screen: Clearly explains the process they are about to begin, both informs the user what type of files are supported for importing, and allows the user to choose the format to import and begin a process. Followed by a file selection screen which should be self explanatory at that point.

Select Deck: Button to popup what I suspect would be some kind of chooser dialog for choosing a deck, displaying selected deck gives the user a chance to preview that choice before they continue to avoid mistakes.

CSV Data: Preview the data to ensure it's being formatted nicely before continuing, chance to choose one of several common CSV delimiters if the current automatically selected delimiter is resulting in incorrect formatting. Preview does not need to list all data, even the first 100 or so rows would be sufficient.

Import Options: All the other decisions and choices out of the way, the user can focus on how the data is mapped, and confirm the operation to begin importing.

Summary Page: Neatly displays results of import process.

@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Aug 30, 2021
@david-allison david-allison self-assigned this Aug 30, 2021
@david-allison

Copy link
Copy Markdown
Member Author

Soft-blocked on #9466

@david-allison david-allison added Blocked by dependency Currently blocked by some other dependent / related change and removed Needs Review labels Aug 31, 2021
@ankidroid ankidroid deleted a comment from Arthur-Milchior Aug 31, 2021
@mikehardy

Copy link
Copy Markdown
Member

mostly just noting soft-block PR was merged, and I took a moment to briefly scan comments and perform Seagull Management duties (swoop in, squawk, leave droppings, swoop out hahah)

@david-allison david-allison removed the Blocked by dependency Currently blocked by some other dependent / related change label Aug 31, 2021
@github-actions

Copy link
Copy Markdown
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions

Copy link
Copy Markdown
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions Bot added the Stale label Dec 29, 2021
@david-allison david-allison added Needs a new dev For PR that were good start but the original dev' left. Any dev can take over and finish it. and removed Stale labels Dec 29, 2021
@david-allison

david-allison commented Dec 29, 2021

Copy link
Copy Markdown
Member Author

Not going to get to this for a while - scoped storage needs to happen and working on that is my prioirty.

@github-actions

Copy link
Copy Markdown
Contributor

Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically

@github-actions github-actions Bot added the Stale label Feb 27, 2022
@krmanik krmanik added Keep Open avoids the stale bot and removed Stale labels Feb 28, 2022
@david-allison david-allison removed Keep Open avoids the stale bot Needs a new dev For PR that were good start but the original dev' left. Any dev can take over and finish it. Needs Author Reply Waiting for a reply from the original author labels Aug 23, 2022
@david-allison

Copy link
Copy Markdown
Member Author

Superseded by #12105

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Import CSV/TSV files

5 participants