-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#27] Initial regex filters structure
- Loading branch information
Showing
6 changed files
with
134 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Frontend/src/components/changes/filters/ChangesFilters.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { Dispatch, SetStateAction, useCallback } from "react"; | ||
import { useId } from "react-id-generator"; | ||
import { Button, Col, Container, Row, UncontrolledCollapse } from "reactstrap"; | ||
import { Filter } from "../../../hooks/useChanges"; | ||
import { ChangeObjectType, ChangeType, ChangeWrapper } from "../../../types/changes"; | ||
import { ChangeFilterSelector } from "./ChangeFilterSelector"; | ||
|
||
type Props = { | ||
changes: ChangeWrapper[]; | ||
filter: Filter; | ||
setFilter: Dispatch<SetStateAction<Filter>>; | ||
}; | ||
|
||
const changeTypes = Object.keys(ChangeType).filter((t) => typeof t === "string"); | ||
const changeObjectTypes = Object.keys(ChangeObjectType).filter((t) => typeof t === "string"); | ||
|
||
export function ChangesFilters({ changes, filter, setFilter }: Props): React.ReactElement { | ||
const [filtersTogglerId] = useId(); | ||
|
||
const useFilterChanged = ( | ||
filterType: keyof Filter, | ||
): ((elements: Map<string | undefined, boolean> | RegExp) => void) => | ||
useCallback( | ||
(filter: Map<string | undefined, boolean> | RegExp) => | ||
setFilter((f) => ({ | ||
...f, | ||
[filterType]: filter, | ||
})), | ||
[filterType], | ||
); | ||
|
||
const onRepositoriesFilterChanged = useFilterChanged("repositories"); | ||
const onUsersFilterChanged = useFilterChanged("users"); | ||
const onTypesFilterChanged = useFilterChanged("types"); | ||
const onObjectTypesFilterChanged = useFilterChanged("objectTypes"); | ||
|
||
const onBranchFilterChanged = useFilterChanged("branch"); | ||
const onTagFilterChanged = useFilterChanged("tag"); | ||
const onCommitFilterChanged = useFilterChanged("commit"); | ||
|
||
return ( | ||
<Container> | ||
<Row> | ||
<Col xs="1"> | ||
<Button id={filtersTogglerId} outline color="info"> | ||
Filters | ||
</Button> | ||
</Col> | ||
<Col> | ||
<UncontrolledCollapse | ||
defaultOpen={true} | ||
toggler={`#${filtersTogglerId}`} | ||
style={{ | ||
borderLeft: "1px solid black", | ||
}} | ||
> | ||
<ChangeFilterSelector | ||
name="Repositories" | ||
changes={changes} | ||
accessor={useCallback((c) => c.repository, [])} | ||
onChanged={onRepositoriesFilterChanged} | ||
/> | ||
<ChangeFilterSelector | ||
name="Users" | ||
changes={changes} | ||
accessor={useCallback((c) => (c.change.user ? c.change.user.name : ""), [])} | ||
textSelector={useCallback((o) => (o === "" ? <i>No user</i> : o), [])} | ||
onChanged={onUsersFilterChanged} | ||
/> | ||
<ChangeFilterSelector | ||
name="Types" | ||
changes={changes} | ||
defaultOptions={changeTypes} | ||
accessor={useCallback((c) => c.change.type, [])} | ||
onChanged={onTypesFilterChanged} | ||
/> | ||
<ChangeFilterSelector | ||
name="Object types" | ||
changes={changes} | ||
defaultOptions={changeObjectTypes} | ||
accessor={useCallback((c) => c.change.objectType, [])} | ||
onChanged={onObjectTypesFilterChanged} | ||
/> | ||
</UncontrolledCollapse> | ||
</Col> | ||
</Row> | ||
</Container> | ||
); | ||
} |
17 changes: 17 additions & 0 deletions
17
Frontend/src/components/changes/filters/CustomFilterCreationModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from "react"; | ||
import { Modal, ModalBody, ModalHeader } from "reactstrap"; | ||
import { ChangeWrapper } from "../../../types/changes"; | ||
|
||
type Props = { | ||
onAddFilter: (accessor: (change: ChangeWrapper) => string, regex: RegExp) => void; | ||
onClose: () => void; | ||
}; | ||
|
||
export default function CustomFilterCreationModal({ onAddFilter, onClose }: Props): React.ReactElement { | ||
return ( | ||
<Modal isOpen={true} toggle={onClose} size="xs"> | ||
<ModalHeader></ModalHeader> | ||
<ModalBody></ModalBody> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters