Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #217 from kokrui/consistent-show-list
Browse files Browse the repository at this point in the history
Make filtered contact list reactive to contact additions/modifications
  • Loading branch information
kokrui committed Nov 10, 2023
2 parents 76442fb + d2d0502 commit 1144c13
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
6 changes: 6 additions & 0 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ This feature involves only 1 command: `find`, which list contacts whose fields m

Format: `find FIND_EXPRESSION`

<box theme="primary" icon=":fa-solid-lightbulb:">

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.
</box>

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.
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddAltCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
41 changes: 41 additions & 0 deletions src/test/java/seedu/address/logic/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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}.
*/
Expand Down

0 comments on commit 1144c13

Please sign in to comment.