From ec3aff8751c6f7ac6dc6320950b5e9e3e96ee327 Mon Sep 17 00:00:00 2001 From: kokrui Date: Thu, 9 Nov 2023 10:55:07 +0800 Subject: [PATCH 1/3] Remove show all persons behaviour from commands --- src/main/java/seedu/address/logic/commands/AddAltCommand.java | 2 -- src/main/java/seedu/address/logic/commands/EditCommand.java | 2 -- .../java/seedu/address/logic/commands/UpdatePhotoCommand.java | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/AddAltCommand.java b/src/main/java/seedu/address/logic/commands/AddAltCommand.java index 9a3dbdfb67b..4228cf2ee3a 100644 --- a/src/main/java/seedu/address/logic/commands/AddAltCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddAltCommand.java @@ -5,7 +5,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_LINKEDIN; import static seedu.address.logic.parser.CliSyntax.PREFIX_SECONDARY_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.ArrayList; import java.util.List; @@ -80,7 +79,6 @@ public CommandResult execute(Model model) throws CommandException { Person editedPerson = createAddAltPerson(personToEdit, addAltPersonDescriptor); model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult(String.format(MESSAGE_ADDALT_SUCCESS, Messages.format(editedPerson))); } diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 158981edea7..0854fbec0bc 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -10,7 +10,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_SECONDARY_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; import static seedu.address.logic.parser.CliSyntax.PREFIX_TELEGRAM; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.ArrayList; import java.util.Collections; @@ -104,7 +103,6 @@ public CommandResult execute(Model model) throws CommandException { } model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, Messages.format(editedPerson))); } diff --git a/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java b/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java index d6957d5f66f..9ff345ac0e2 100644 --- a/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java +++ b/src/main/java/seedu/address/logic/commands/UpdatePhotoCommand.java @@ -2,7 +2,6 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_AVATAR; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.io.FileNotFoundException; import java.io.IOException; @@ -80,7 +79,6 @@ public CommandResult execute(Model model) throws CommandException { Person editedPerson = createPersonWithAvatar(personToEdit, avatar); model.setPerson(personToEdit, editedPerson); - model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); return new CommandResult(MESSAGE_SUCCESS); } From e3280622a5578e5d8875a1a9967ba952aea346f7 Mon Sep 17 00:00:00 2001 From: kokrui Date: Thu, 9 Nov 2023 12:51:02 +0800 Subject: [PATCH 2/3] Add integration tests for reactive find view --- .../logic/commands/FindCommandTest.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index b08b62dd21c..e07b80f2aed 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -15,9 +15,12 @@ import org.junit.jupiter.api.Test; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; +import seedu.address.model.person.Balance; import seedu.address.model.person.NameContainsKeywordsPredicate; /** @@ -82,6 +85,44 @@ public void toStringMethod() { assertEquals(expected, findCommand.toString()); } + // Integration tests for reactive commands + + @Test + public void execute_payAfterFiltered_reactive() throws CommandException { + Model tempModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + assert tempModel.hasPerson(CARL); + + FindCommand command = new FindCommand(person -> person.getBalance().value < 50); + command.execute(tempModel); + + int originalSize = tempModel.getFilteredPersonList().size(); + + assert tempModel.getFilteredPersonList().get(1) == CARL; + + PayCommand payCommand = new PayCommand(Index.fromZeroBased(1), new Balance(50000)); + payCommand.execute(tempModel); + + assert CARL.getBalance().value >= 50; + + assertEquals(originalSize - 1, tempModel.getFilteredPersonList().size()); + } + + @Test + public void execute_deleteAfterFiltered_reactive() { + Model tempModel = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + assert tempModel.hasPerson(CARL); + + FindCommand command = new FindCommand(person -> true); + command.execute(tempModel); + + int originalSize = tempModel.getFilteredPersonList().size(); + + tempModel.deletePerson(CARL); + + assertEquals(originalSize - 1, tempModel.getFilteredPersonList().size()); + } + + /** * Parses {@code userInput} into a {@code NameContainsKeywordsPredicate}. */ From d2d0502c854498c11df1d344bb2492e6e04452cd Mon Sep 17 00:00:00 2001 From: kokrui Date: Thu, 9 Nov 2023 13:02:46 +0800 Subject: [PATCH 3/3] Add info box to explain reactive nature of find --- docs/UserGuide.md | 6 ++++++ .../java/seedu/address/logic/commands/FindCommandTest.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 03c3d4f86e1..a03086d4d09 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -589,6 +589,12 @@ This feature involves only 1 command: `find`, which list contacts whose fields m Format: `find FIND_EXPRESSION` + + +The contact list will be filtered until you perform another `find` command or use the [`list` command](#list-all-contacts-list). +This includes commands that add, delete, or edit contacts — newly-added more edited contacts will be shown only if they match the criteria. + + Find expressions have a low barrier to entry that allows for simple filtering by field. This basic filtering for contacts is likely sufficient for most of your use cases. We recommend that you first read the [basic filtering](#basic-filtering) section to learn how to perform simple filtering by a single field. If you then find that the basic filtering is insufficient for your use case, you can read the [advanced filtering](#advanced-filtering) section to learn how to perform more complex filtering. diff --git a/src/test/java/seedu/address/logic/commands/FindCommandTest.java b/src/test/java/seedu/address/logic/commands/FindCommandTest.java index e07b80f2aed..1c31eed9153 100644 --- a/src/test/java/seedu/address/logic/commands/FindCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/FindCommandTest.java @@ -86,7 +86,7 @@ public void toStringMethod() { } // Integration tests for reactive commands - + @Test public void execute_payAfterFiltered_reactive() throws CommandException { Model tempModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());