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

Results data table #193

Closed
Closed
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e85b067
remove unneeded files
acharliekelly Oct 15, 2021
b3c2fdf
add info icon, new types to info-tooltip
acharliekelly Oct 15, 2021
339e368
more mock data
acharliekelly Oct 15, 2021
a1067b7
export mock data
acharliekelly Oct 15, 2021
009f512
saved-table types and column defs
acharliekelly Oct 15, 2021
9990f8e
update column head
acharliekelly Oct 15, 2021
50e3d3d
export search-results component
acharliekelly Oct 15, 2021
48a2244
make mock-data optional
acharliekelly Oct 15, 2021
da680f5
update saved resource stories
acharliekelly Oct 15, 2021
d13df02
simplify - can only view current user
acharliekelly Oct 15, 2021
94fe01d
update search results, closer to design
acharliekelly Oct 15, 2021
1347b60
search results component
acharliekelly Oct 15, 2021
bcdd2aa
export files
acharliekelly Oct 15, 2021
4fadfe0
replace results table component
acharliekelly Oct 15, 2021
843c7f3
make results table look better
acharliekelly Oct 15, 2021
e14a501
make pagination less squished
acharliekelly Oct 15, 2021
7038034
update snapshots
acharliekelly Oct 15, 2021
0e58147
run prettier
acharliekelly Oct 15, 2021
09194fe
remove unneeded files
acharliekelly Oct 15, 2021
9e3df2c
add info icon, new types to info-tooltip
acharliekelly Oct 15, 2021
f3f6ea0
more mock data
acharliekelly Oct 15, 2021
3b4bb2b
export mock data
acharliekelly Oct 15, 2021
eb4c70e
saved-table types and column defs
acharliekelly Oct 15, 2021
0f392fd
update column head
acharliekelly Oct 15, 2021
4551c07
export search-results component
acharliekelly Oct 15, 2021
034208b
make mock-data optional
acharliekelly Oct 15, 2021
f3693f7
update saved resource stories
acharliekelly Oct 15, 2021
6d6d6ed
simplify - can only view current user
acharliekelly Oct 15, 2021
4eeed9c
update search results, closer to design
acharliekelly Oct 15, 2021
2bb809b
search results component
acharliekelly Oct 15, 2021
4657d0a
export files
acharliekelly Oct 15, 2021
9cda008
replace results table component
acharliekelly Oct 15, 2021
d8d33c0
make results table look better
acharliekelly Oct 15, 2021
f026018
make pagination less squished
acharliekelly Oct 15, 2021
140d4ce
update snapshots
acharliekelly Oct 15, 2021
190a85c
run prettier
acharliekelly Oct 15, 2021
f871fb0
Merge branch 'results-data-table' of github.com:acharliekelly/police-…
acharliekelly Oct 15, 2021
71624fe
update search page snapshot
acharliekelly Oct 15, 2021
fa5ba30
make pagination look more like picture
acharliekelly Oct 15, 2021
8a6c397
update snapshot
acharliekelly Oct 15, 2021
e3e9ede
run prettier
acharliekelly Oct 15, 2021
20e5e22
fix tests
alexjball Oct 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/compositions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ProfileType from "./profile-type"
import EditProfileInfo from "./profile-edit"
import SavedResults from "./profile-saved-tables/saved-results"
import SavedSearches from "./profile-saved-tables/saved-searches"
import SearchResultsTable from "./search-results"
import LandingPage from "./landingpage/landing"

export {
Expand All @@ -28,6 +29,7 @@ export {
ProfileInfo,
EditProfileInfo,
ProfileType,
SearchResultsTable,
SavedResults,
SavedSearches,
LandingPage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"
import { ComponentMeta } from "@storybook/react"
import SavedResults from "./saved-results"
import { mockSavedResults } from "../../models/mock-data"

export default {
title: "Compositions/Saved Results",
component: SavedResults
} as ComponentMeta<typeof SavedResults>

export const Default = <SavedResults data={mockSavedResults} />
14 changes: 8 additions & 6 deletions frontend/compositions/profile-saved-tables/saved-results.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import SavedTable from "./saved-table"
import { faAngleRight } from "@fortawesome/free-solid-svg-icons"

import { resultsColumns } from "../../models/search-meta"
import { savedResultsData } from "../../models/mock-data"
import { SavedResultsType, resultsColumns } from "../../models/saved-table"
import { mockSavedResults } from "../../models/mock-data"

// TODO: retrieve user saved results from API
interface SavedResultsProps {
data?: Array<SavedResultsType>
}

export default function SavedResults() {
export default function SavedResults({ data = mockSavedResults }: SavedResultsProps) {
return SavedTable({
itemTitle: "Results",
tableColumns: resultsColumns,
tableData: savedResultsData,
rowIdName: "recordId",
tableData: data,
rowIdName: "id",
expandIcon: faAngleRight
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react"
import { ComponentMeta } from "@storybook/react"
import SavedSearches from "./saved-searches"
// import { mockSavedSearches } from "../../models/mock-data"

export default {
title: "Compositions/Saved Searches",
component: SavedSearches
} as ComponentMeta<typeof SavedSearches>

export const Default = <SavedSearches />
12 changes: 8 additions & 4 deletions frontend/compositions/profile-saved-tables/saved-searches.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import SavedTable from "./saved-table"
import { faCaretRight } from "@fortawesome/free-solid-svg-icons"

import { searchesColumns } from "../../models/search-meta"
import { savedSearchData } from "../../models/mock-data"
import { searchesColumns, SavedSearchType } from "../../models/saved-table"
import { mockSavedSearches } from "../../models/mock-data"

// TODO: retrieve user saved searches from API

export default function SavedSearches() {
interface SavedSearchProps {
data?: Array<SavedSearchType>
}

export default function SavedSearches({ data = mockSavedSearches }: SavedSearchProps) {
return SavedTable({
itemTitle: "Searches",
tableColumns: searchesColumns,
tableData: savedSearchData,
tableData: data,
rowIdName: "results",
expandIcon: faCaretRight
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ComponentStory, ComponentMeta } from "@storybook/react"
import SavedTable from "./saved-table"
import { faAngleRight, faCaretRight } from "@fortawesome/free-solid-svg-icons"

import { resultsColumns, searchesColumns } from "../../models/search-meta"
import { savedResultsData, savedSearchData } from "../../models/mock-data"
import { resultsColumns, searchesColumns } from "../../models/saved-table"
import { mockSavedSearches, mockSavedResults } from "../../models/mock-data"

export default {
title: "Compositions/Saved Table",
Expand All @@ -17,7 +17,7 @@ export const SavedResultsTable = Template.bind({})
SavedResultsTable.args = {
itemTitle: "Results",
tableColumns: resultsColumns,
tableData: savedResultsData,
tableData: mockSavedResults,
rowIdName: "recordId",
expandIcon: faAngleRight
}
Expand All @@ -26,7 +26,7 @@ export const SavedSearchTable = Template.bind({})
SavedSearchTable.args = {
itemTitle: "Searches",
tableColumns: searchesColumns,
tableData: savedSearchData,
tableData: mockSavedSearches,
rowIdName: "results",
expandIcon: faCaretRight
}
87 changes: 54 additions & 33 deletions frontend/compositions/profile-saved-tables/saved-table.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { IconDefinition } from "@fortawesome/fontawesome-svg-core"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import {
faArrowUp,
faArrowDown,
faAngleRight,
faAngleLeft,
faAngleDoubleRight,
faAngleDoubleLeft
} from "@fortawesome/free-solid-svg-icons"
import * as React from "react"
import { useTable, usePagination, Column } from "react-table"

Expand Down Expand Up @@ -28,7 +36,12 @@ export default function SavedTable(props: SavedTableProps) {
dataFooter,
dataRowPage,
dataRows,
expandRecordButton
pageBtn,
actionBtn,
sortArrow,
recordCount,
pageCnt,
goto
} = styles

const data = useMemo(() => tableData, [tableData])
Expand Down Expand Up @@ -103,12 +116,11 @@ export default function SavedTable(props: SavedTableProps) {
// eslint-disable-next-line react/jsx-key
<tr {...row.getRowProps()} className={dataRows}>
{row.cells.map((cell) => {
const { id } = cell.column
if (id === rowIdName) {
if (cell.column.id === rowIdName) {
return (
<td>
<FontAwesomeIcon
className={expandRecordButton}
className={actionBtn}
icon={expandIcon}
onClick={() => viewRecord(cell.value)}
/>
Expand All @@ -124,36 +136,45 @@ export default function SavedTable(props: SavedTableProps) {
)
})}
</tbody>
<tfoot className={dataFooter}>
<tr>
<td>{data.length.toLocaleString()} records found</td>
<td colSpan={4}></td>
<td>
Show{" "}
<input
className={dataRowPage}
min={1}
max={10}
onBlur={handleBlur}
onChange={handleChange}
type="number"
value={pageSizeValue}
/>{" "}
rows
</td>
<td>
{" "}
<button onClick={() => previousPage()} disabled={!canPreviousPage}>
{"<"}
</button>{" "}
{pageIndex + 1} of {pageOptions.length}{" "}
<button onClick={() => nextPage()} disabled={!canNextPage}>
{">"}
</button>{" "}
</td>
</tr>
</tfoot>
</table>
<div className={dataFooter}>
<span className={recordCount}>Found {data.length.toLocaleString()} records</span>
<button className={pageBtn} onClick={() => gotoPage(0)} disabled={!canPreviousPage}>
<FontAwesomeIcon icon={faAngleDoubleLeft} />
</button>
<button className={pageBtn} onClick={() => previousPage()} disabled={!canPreviousPage}>
<FontAwesomeIcon icon={faAngleLeft} />
</button>
<span className={pageCnt}>
Page <strong>{pageIndex + 1}</strong> of <strong>{pageOptions.length}</strong>{" "}
</span>
<button className={styles.pageBtn} onClick={() => nextPage()} disabled={!canNextPage}>
<FontAwesomeIcon icon={faAngleRight} />
</button>
<button className={pageBtn} onClick={() => gotoPage(pageCount - 1)} disabled={!canNextPage}>
<FontAwesomeIcon icon={faAngleDoubleRight} />
</button>
<span className={goto}>
Go to page:{" "}
<input
type="number"
className={dataRowPage}
defaultValue={pageIndex + 1}
onChange={(e) => {
const page = e.target.value ? Number(e.target.value) - 1 : 0
gotoPage(page)
}}
style={{ width: "50px", textAlign: "right" }}
/>
</span>{" "}
<select value={pageSize} onChange={(e) => setPageSize(Number(e.target.value))}>
{[10, 20, 30, 40, 50].map((pageSize) => (
<option key={pageSize} value={pageSize}>
Show {pageSize}
</option>
))}
</select>
</div>
</div>
)
}
12 changes: 12 additions & 0 deletions frontend/compositions/profile-saved-tables/saved.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,15 @@
-webkit-appearance: none;
margin: 0;
}

.actionBtn {
cursor: pointer;
}

.sortArrow {
margin-left: 0.3rem;
}

.pageBtn {
margin: 0 1rem;
}
11 changes: 1 addition & 10 deletions frontend/compositions/profile-type/profile-type.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react"
import { ComponentStory, ComponentMeta } from "@storybook/react"
import ProfileType from "."
import users from "../../models/mock-data/users.json"

export default {
title: "Compositions/Profile Type",
Expand All @@ -10,12 +9,4 @@ export default {

const Template: ComponentStory<typeof ProfileType> = (args) => <ProfileType {...args} />

export const PublicProfile = Template.bind({})
PublicProfile.args = {
userData: users[0]
}

export const PassportProfile = Template.bind({})
PassportProfile.args = {
userData: users[1]
}
export const Default = Template.bind({})
Loading