-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add status and board filters for scheds page
- Loading branch information
1 parent
0cbbb42
commit edfaac7
Showing
12 changed files
with
287 additions
and
24 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
56 changes: 56 additions & 0 deletions
56
querybook/webapp/components/DataDocScheduleList/DataDocBoardsSelect.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,56 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { IStoreState } from 'redux/store/types'; | ||
import { SimpleField } from 'ui/FormikField/SimpleField'; | ||
import { IBoard } from 'const/board'; | ||
import { IOption } from 'lib/utils/react-select'; | ||
import { OptionTypeBase } from 'react-select'; | ||
|
||
export interface IDataDocBoardsSelectProps { | ||
onChange: (params: OptionTypeBase[]) => void; | ||
value: IOption<number>[]; | ||
label?: string; | ||
name: string; | ||
} | ||
|
||
export const DataDocBoardsSelect: React.FC<IDataDocBoardsSelectProps> = ({ | ||
onChange, | ||
value, | ||
label, | ||
name, | ||
}) => { | ||
const boardById: Record<string, IBoard> = useSelector( | ||
(state: IStoreState) => state.board.boardById | ||
); | ||
|
||
const boardOptions: IOption<number>[] = useMemo(() => { | ||
return Object.values(boardById).map((board) => ({ | ||
value: board.id, | ||
label: board.name, | ||
})); | ||
}, [boardById]); | ||
|
||
const selectedBoards: IOption<number>[] = useMemo( | ||
() => | ||
boardOptions.filter((board) => | ||
value.map((v) => v.value).includes(board.value) | ||
), | ||
[] | ||
); | ||
|
||
return ( | ||
<SimpleField | ||
label={label} | ||
name={name} | ||
value={value} | ||
defaultValue={selectedBoards} | ||
options={boardOptions} | ||
onChange={onChange} | ||
optionSelector={(v: IOption<number>) => v} | ||
closeMenuOnSelect={false} | ||
hideSelectedOptions={false} | ||
isMulti | ||
type="react-select" | ||
/> | ||
); | ||
}; |
87 changes: 87 additions & 0 deletions
87
querybook/webapp/components/DataDocScheduleList/DataDocSchedsFilters.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,87 @@ | ||
import React, { useEffect } from 'react'; | ||
import { Formik } from 'formik'; | ||
import { debounce } from 'lodash'; | ||
import { useDispatch } from 'react-redux'; | ||
import { OptionTypeBase } from 'react-select'; | ||
import { Popover } from 'ui/Popover/Popover'; | ||
import { SimpleField } from 'ui/FormikField/SimpleField'; | ||
import { DataDocBoardsSelect } from './DataDocBoardsSelect'; | ||
import { IScheduledDocFilters } from 'redux/scheduledDataDoc/types'; | ||
import { fetchBoards } from 'redux/board/action'; | ||
import { UpdateFiltersType, StatusType } from 'const/schedFiltersType'; | ||
|
||
const enabledOptions = [ | ||
{ key: 'all', value: 'All' }, | ||
{ key: 'enabled', value: 'Enabled' }, | ||
{ key: 'disabled', value: 'Disabled' }, | ||
]; | ||
|
||
export const DataDocSchedsFilters: React.FC<{ | ||
setShowSearchFilter: (arg: boolean) => void; | ||
updateFilters: (arg: UpdateFiltersType) => void; | ||
filterButton: HTMLAnchorElement | null; | ||
filters: IScheduledDocFilters; | ||
}> = ({ setShowSearchFilter, filters, updateFilters, filterButton }) => { | ||
const dispatch = useDispatch(); | ||
useEffect(() => { | ||
dispatch(fetchBoards()); | ||
}, []); | ||
const handleUpdateStatus = React.useCallback((value: StatusType) => { | ||
updateFilters({ | ||
key: 'status', | ||
value, | ||
}); | ||
}, []); | ||
|
||
const handleUpdateList = React.useCallback( | ||
debounce((params: OptionTypeBase[]) => { | ||
updateFilters({ | ||
key: 'board_ids', | ||
value: params, | ||
}); | ||
}, 500), | ||
[] | ||
); | ||
return ( | ||
<Popover | ||
layout={['bottom', 'right']} | ||
onHide={() => { | ||
setShowSearchFilter(false); | ||
}} | ||
anchor={filterButton} | ||
> | ||
<div className="DataTableNavigatorSearchFilter"> | ||
<div className="DataDocScheduleList_select-wrapper"> | ||
<Formik | ||
initialValues={{ | ||
status: '', | ||
board_ids: [], | ||
}} | ||
onSubmit={() => undefined} // Just for fixing ts | ||
> | ||
{({}) => { | ||
return ( | ||
<> | ||
<SimpleField | ||
label="Status" | ||
type="select" | ||
name="status" | ||
options={enabledOptions} | ||
onChange={handleUpdateStatus} | ||
value={filters.status} | ||
/> | ||
<DataDocBoardsSelect | ||
label="Lists" | ||
name="board_ids" | ||
value={filters.board_ids} | ||
onChange={handleUpdateList} | ||
/> | ||
</> | ||
); | ||
}} | ||
</Formik> | ||
</div> | ||
</div> | ||
</Popover> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface OptionsType { | ||
value: string; | ||
key: string; | ||
hidden?: boolean; | ||
} |
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,8 @@ | ||
import { OptionTypeBase } from 'react-select'; | ||
|
||
export type StatusType = 'all' | 'enabled' | 'disabled'; | ||
|
||
export type UpdateFiltersType = | ||
| { key: 'status'; value: StatusType } | ||
| { key: 'scheduled_only'; value: boolean } | ||
| { key: 'board_ids'; value: OptionTypeBase[] }; |
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
Oops, something went wrong.