-
Notifications
You must be signed in to change notification settings - Fork 1
IdeaListViewComponent JavaScript
Ethan Dunzer edited this page Aug 29, 2024
·
1 revision
The IdeaListViewComponent JavaScript file is responsible for managing the logic behind displaying and interacting with a list of ideas in a Salesforce application. It handles data retrieval, pagination, upvoting, downvoting, and sorting of ideas, ensuring a dynamic and responsive user experience.
Properties
-
@api title
: Public property for the title of the datatable, default is 'Most Popular Ideas'. -
@api sourceType
: Public property for filtering ideas based on their source (e.g., 'All', 'CurrentUser'). -
@api sortField
: Public property that defines the field by which the data should be sorted (e.g., 'Total_Votes__c'). -
@api sortOrder
: Public property that determines the order of sorting (e.g., 'ASC' or 'DESC'). -
@api statusFilter
: Public property for filtering ideas based on their status (e.g., 'Active', 'Closed'). -
@track ideas
: Tracks the list of ideas returned by the server, used to render the datatable. -
@track page
: Tracks the current page number for pagination. -
@track pageSize
: Tracks the number of records per page, default is 10. -
@track totalRecords
: Tracks the total number of records returned by the server. -
@track totalPage
: Tracks the total number of pages based on the pageSize and totalRecords. -
wiredIdeasResult
: Stores the result of the @wire service call for data refresh purposes.
Methods
-
wiredIdeas(result)
: A wired method that retrieves the list of ideas from the server. It maps the server data to a more UI-friendly format, handles pagination logic, and updates the UI accordingly. -
updateTotalPages()
: Calculates the total number of pages based on the totalRecords and pageSize. -
isPreviousDisabled()
: A getter that returns a boolean indicating whether the 'Previous' button should be disabled. -
isNextDisabled()
: A getter that returns a boolean indicating whether the 'Next' button should be disabled. -
handlePrevious()
: Navigates to the previous page of ideas. If the current page is the first page, the button is disabled. -
handleNext()
: Navigates to the next page of ideas. If the current page is the last page, the button is disabled. -
handleRowAction(event)
: Handles user interactions with the upvote and downvote buttons within the datatable. It triggers the appropriate method (upvote or downvote) based on the button clicked. -
handleUpVote(ideaId)
: Sends a request to upvote the selected idea. If the user has already upvoted, the vote is removed; otherwise, it is added or changed from a downvote to an upvote. -
handleDownVote(ideaId)
: Sends a request to downvote the selected idea. If the user has already downvoted, the vote is removed; otherwise, it is added or changed from an upvote to a downvote. -
showToast(title, message, variant)
: Displays a toast notification with the provided title, message, and variant (e.g., 'success', 'error').
Usage The IdeaListViewComponent JavaScript file is integral to the functioning of the component, providing essential logic for data manipulation, user interaction, and UI updates. It ensures that the list of ideas is displayed correctly, with appropriate pagination and interactive voting features.