Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create view command #138

Merged

Conversation

Andrew22Teoh
Copy link
Collaborator

@Andrew22Teoh Andrew22Teoh commented Oct 23, 2024

Closes #121

This is a very barebones implementation of the View command by creating a new window with the user's information.

In future iterations, this should be changed such that the View does not pop up a new window and rather has a pre-allocated space within the main window GUI so as not to interrupt user typing.

The biggest problem with this is maintaining abstraction, since there is no way to pass a Person out of the Model and into the UI for the processing. This view command is implemented by filtering the list to only match the exact Person indexed, and viewing the first item in the list.

Some minor changes are also made:

  • Minor refactoring of PersonCard to reduce method length
  • Enable text wrapping in UI element ResultDisplay
  • Remove a redundant line from AddressBookParserTest of the sort command
  • PersonCard as displayed by ListCommand now contains less information so as to prevent visually overwhelming users, motivating the creation of this ViewCommand.

Tests have been updated and written, but CodeCov is low due to UI files not being tested.
User guide has not yet been updated, and will be done in the next PR.

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

Attention: Patch coverage is 33.82353% with 90 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/main/java/seedu/address/ui/ViewWindow.java 0.00% 62 Missing ⚠️
src/main/java/seedu/address/ui/PersonCard.java 0.00% 19 Missing ⚠️
src/main/java/seedu/address/ui/MainWindow.java 0.00% 9 Missing ⚠️
Files with missing lines Coverage Δ Complexity Δ
src/main/java/seedu/address/logic/Messages.java 90.00% <100.00%> (-5.46%) 17.00 <1.00> (ø)
.../java/seedu/address/logic/commands/AddCommand.java 100.00% <100.00%> (ø) 8.00 <0.00> (ø)
...va/seedu/address/logic/commands/CommandResult.java 100.00% <100.00%> (ø) 15.00 <3.00> (+2.00)
...java/seedu/address/logic/commands/ExitCommand.java 100.00% <100.00%> (ø) 2.00 <1.00> (ø)
...java/seedu/address/logic/commands/HelpCommand.java 100.00% <100.00%> (ø) 2.00 <1.00> (ø)
...java/seedu/address/logic/commands/ViewCommand.java 100.00% <100.00%> (ø) 8.00 <8.00> (?)
.../seedu/address/logic/parser/AddressBookParser.java 100.00% <100.00%> (ø) 16.00 <0.00> (+1.00)
.../seedu/address/logic/parser/ViewCommandParser.java 100.00% <100.00%> (ø) 4.00 <4.00> (?)
src/main/java/seedu/address/model/Model.java 100.00% <100.00%> (ø) 2.00 <1.00> (+1.00)
src/main/java/seedu/address/ui/MainWindow.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
... and 2 more

... and 1 file with indirect coverage changes

@Andrew22Teoh Andrew22Teoh marked this pull request as ready for review October 24, 2024 09:17
Copy link
Collaborator

@AbdulrahmanAlRammah AbdulrahmanAlRammah left a comment

Choose a reason for hiding this comment

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

Good Job. This pr is a substantial step towards a complete view command. Some minor comments on the messages to be improved.

@@ -13,6 +13,9 @@ public class CommandResult {

private final String feedbackToUser;

/** User wants to view all information about a contact. */
private final boolean shouldView;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest changing the name to showFullView or another more descriptive name.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good, I've changed this to shouldOpenView

public static final String COMMAND_WORD = "view";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Views all information about the person identified by the index number in the displayed person list.\n"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Message should be ": Shows all" instead of views.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds good to me, changed accordingly!

+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_VIEW_SUCCESS = "Showing view for %1$s.";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think "Displaying information for" would be better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, edited to "Showing information for..."!

*
* @param personList The filtered {@code ObservableList} from {@code Logic}. Will only view 1 {@code Person}.
*/
public void view(ObservableList<Person> personList) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wondering. Why does this method accept a list instead of just accepting the person straight up. Isn't just complicating things?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This method is called in the MainWindow class, which is at quite a high level of abstraction. Within the UI elements, there are generally no mentions or references to any Logic objects like the Person class, and so this method is called as view(logic.getFilteredPersonList()). If I were to make this accept a Person, the method call would have to invoke the .get() within MainWindow, which I think makes the SLAP worse.

public void parse_validArgsWithWhitespace_returnsViewCommand() {
assertParseSuccess(parser, " 1", new ViewCommand(INDEX_FIRST_PERSON));
assertParseSuccess(parser, "3 ", new ViewCommand(INDEX_THIRD_PERSON));
assertParseSuccess(parser, " \n 2 \t ", new ViewCommand(INDEX_SECOND_PERSON));
Copy link
Collaborator

Choose a reason for hiding this comment

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

How does this line succeed? Aren't the \n \t misinputs? When I tried it in the actual console it failed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The \n and \t are special characters here to indicate new line and tab respectively, and not the n/ t/ prefixes we use for specific types of inputs.

This test will never come to pass though, since the user cannot enter newline or tab characters within the command input box. It's meant to be a check to ensure that we never lose the functionality to ignore excess whitespace within the ViewCommandParser, in case we change the UI in the future and allow users to enter newline or tab characters!

Hope this helps, do let me know if more clarification is required :)

@AbdulrahmanAlRammah AbdulrahmanAlRammah merged commit 26a143e into AY2425S1-CS2103-F10-2:master Oct 24, 2024
3 of 4 checks passed
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.

Create view command
2 participants