Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | 5x 5x 5x 4x 4x 2x 2x 5x 3x | import { Link, useSearchParams } from "react-router-dom"; import { format } from "date-fns"; import { Row, Col, MainTable, Icon, Notification, Button, } from "@canonical/react-components"; import { useValidationSets } from "../../hooks"; import type { ValidationSet } from "../../types"; function ValidationSets(): JSX.Element { const { status, data: validationSets } = useValidationSets(); const [searchParams, setSearchParams] = useSearchParams(); const filteredValidationSets: ValidationSet[] = validationSets && validationSets.length ? validationSets.filter((validationSet: ValidationSet) => { const query = searchParams.get("filter"); if (!query) { return true; } return validationSet.name.includes(query); }) : []; return ( <> <h1 className="p-heading--4">My validation sets</h1> <Row> <Col size={6}> <div className="p-search-box"> <label className="u-off-screen" htmlFor="search"> Search validation sets </label> <input required type="search" id="search" name="search" className="p-search-box__input" placeholder="Search validation sets" autoComplete="off" value={searchParams.get("filter") || ""} onChange={(e) => { if (e.target.value) { setSearchParams({ filter: e.target.value }); } else { setSearchParams(); } }} /> <Button type="reset" className="p-search-box__reset" onClick={() => { setSearchParams(); }} > <Icon name="close">Clear filter</Icon> </Button> <Button type="submit" className="p-search-box__button"> <Icon name="search">Search</Icon> </Button> </div> </Col> </Row> {status === "loading" && ( <p> <Icon name="spinner" className="u-animation--spin" /> Fetching validation sets </p> )} {status === "success" && filteredValidationSets.length === 0 && ( <Notification severity="information"> There are no validation sets to display </Notification> )} {status === "error" && ( <Notification severity="negative"> Unable to load validation sets </Notification> )} {status === "success" && filteredValidationSets.length > 0 && ( <MainTable sortable headers={[ { content: `Name (${filteredValidationSets.length})`, sortKey: "name", }, { content: "Revision", className: "u-align--right", sortKey: "revision", }, { content: "Sequence", className: "u-align--right", sortKey: "sequence", }, { content: "Referenced snaps", className: "u-align--right", sortKey: "snaps", }, { content: "Last updated", className: "u-align--right", sortKey: "updated", }, ]} rows={filteredValidationSets.map((validationSet: ValidationSet) => { return { columns: [ { content: ( <Link to={`/validation-sets/${validationSet.name}`}> {validationSet.name} </Link> ), }, { content: validationSet.revision || "-", className: "u-align--right", }, { content: validationSet.sequence || "-", className: "u-align--right", }, { content: validationSet.snaps.length, className: "u-align--right", }, { content: format( new Date(validationSet.timestamp), "dd/MM/yyyy", ), className: "u-align--right", }, ], sortData: { name: validationSet.name, revision: validationSet.revision, sequence: validationSet.sequence, snaps: validationSet.snaps.length, updated: validationSet.timestamp, }, }; })} /> )} </> ); } export default ValidationSets; |