Skip to content

Commit

Permalink
comments added
Browse files Browse the repository at this point in the history
  • Loading branch information
MelanieSarrouy committed Jan 4, 2022
1 parent 4a28061 commit 6e6634a
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ const TableWithSortingandFilters = (props) => {
const [entries, setEntries] = useState(10)
const [page, setPage] = useState(1)

// array of employees list
const listArr = Array.from(props.list)

// employees list with values concatenated
const listArrValues = listArr.map((el) => {
const valuesWithoutId = { ...el }
delete valuesWithoutId.id
Expand All @@ -41,36 +43,47 @@ const TableWithSortingandFilters = (props) => {
return concat
})

// Correspondence's search result between the employees list and the entered search
let listMatchSearch = []

// if a search is entered
for (let i = 0; i < listArrValues.length; i++) {
if (listArrValues[i].includes(search)) {
listMatchSearch.push(listArr[i])
}
}

// if no search is entered
if (search === '') {
listMatchSearch = props.list
}

// number of entries to display
const length = listMatchSearch.length
const division = listMatchSearch.length / entries
// the last data that can be displayed on the page
const lastDataOnPage = page * entries
// the first data that can be displayed on the page
const firstDataOnPage = lastDataOnPage - entries
// number of full pages
const fullPages = Math.trunc(division)
// number of pages
const pageCount = Math.ceil(division)

// array of number of pages
let pageCountRange = []
for (let i = 0; i < pageCount; i++) {
pageCountRange.push(i)
}

// employees list to display on current page
const listToDisplay = listMatchSearch.slice(firstDataOnPage, lastDataOnPage)

// when a search is made
const handleChangeSearch = (e) => {
const value = standardizeAndLowerCase(e.target.value)
setPage(1)
setSearch(value)
}
// when number of entries to display is selected
const handleChangeEntries = (e) => {
setEntries(e.target.value)
setPage(1)
Expand Down

0 comments on commit 6e6634a

Please sign in to comment.