-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/grid filter continued #269
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
Open
santipalenque
wants to merge
10
commits into
main
Choose a base branch
from
feature/grid-filter-continued
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0e198f5
chore: adding operators
santipalenque 35e4731
chore: add new value inputs
santipalenque 81bcc63
v5.0.36-beta.0
santipalenque e5a526a
chore: add setFilters functionality for saved filters
santipalenque 8da042e
chore: update version
santipalenque 8e9ab20
chore: consolidate pagination accross all tables and add bulkedittable
santipalenque e1d7e08
v5.0.36-beta.2
santipalenque 86891bb
chore: first round of PR review
santipalenque 63c61a1
chore: PR review round 2
santipalenque bf4db8a
v5.0.37-beta.0
santipalenque File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,163 @@ | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * */ | ||
|
|
||
| import React, { useEffect, useRef, useState } from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import T from "i18n-react/dist/i18n-react"; | ||
| import Autocomplete from "@mui/material/Autocomplete"; | ||
| import TextField from "@mui/material/TextField"; | ||
| import CircularProgress from "@mui/material/CircularProgress"; | ||
| import { DEBOUNCE_WAIT_250 } from "../../utils/constants"; | ||
|
|
||
| const defaultFormatOption = (item) => ({ | ||
| value: item.id, | ||
| label: item.name | ||
| }); | ||
|
|
||
| const optionShape = PropTypes.shape({ | ||
| value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), | ||
| label: PropTypes.string, | ||
| raw: PropTypes.object | ||
| }); | ||
|
|
||
| const AsyncSelectInput = ({ | ||
| id, | ||
| value, | ||
| label, | ||
| placeholder, | ||
| disabled, | ||
| multiple, | ||
| queryFunction, | ||
| formatOption, | ||
| debounceWait, | ||
| minSearchLength, | ||
| onChange, | ||
| ...rest | ||
| }) => { | ||
| const [options, setOptions] = useState([]); | ||
| const [loading, setLoading] = useState(false); | ||
| const debounceRef = useRef(null); | ||
| const mountedRef = useRef(false); | ||
| const requestIdRef = useRef(0); | ||
|
|
||
| // Filter.jsx passes `options` generically to every ValueInput type (meant | ||
| // for the sync `select` type); this type fetches its own, so it's stripped | ||
| // out here rather than spread onto the Autocomplete below. | ||
| const { options: _staleOptions, ...autocompleteProps } = rest; | ||
|
|
||
| const fetchOptions = (searchTerm) => { | ||
| if (minSearchLength > 0 && (!searchTerm || searchTerm.length < minSearchLength)) { | ||
| setOptions([]); | ||
| return; | ||
| } | ||
| // Capture the ID for this request so the callback can discard stale ones. | ||
| requestIdRef.current += 1; | ||
| const thisRequestId = requestIdRef.current; | ||
| setLoading(true); | ||
| queryFunction(searchTerm, (rawResults) => { | ||
| if (!mountedRef.current || thisRequestId !== requestIdRef.current) return; | ||
| setOptions((rawResults || []).map((item) => ({ ...formatOption(item), raw: item }))); | ||
| setLoading(false); | ||
| }); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
|
santipalenque marked this conversation as resolved.
|
||
| mountedRef.current = true; | ||
| fetchOptions(""); | ||
| return () => { | ||
| mountedRef.current = false; | ||
| if (debounceRef.current) clearTimeout(debounceRef.current); | ||
| }; | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
|
santipalenque marked this conversation as resolved.
|
||
|
|
||
| const handleInputChange = (event, newInputValue, reason) => { | ||
| if (reason !== "input") return; | ||
| if (debounceRef.current) clearTimeout(debounceRef.current); | ||
| debounceRef.current = setTimeout(() => fetchOptions(newInputValue), debounceWait); | ||
| }; | ||
|
|
||
| const handleChange = (event, selected) => { | ||
| onChange({ target: { value: multiple ? selected || [] : selected || null } }); | ||
| }; | ||
|
|
||
| // Filter.jsx's single-value default is "" (not null); treat it as empty. | ||
| const normalizedValue = multiple ? value || [] : value || null; | ||
| const finalPlaceholder = | ||
| placeholder || T.translate("placeholders.async"); | ||
|
|
||
| return ( | ||
| <Autocomplete | ||
| id={id} | ||
| options={options} | ||
| value={normalizedValue} | ||
| onChange={handleChange} | ||
| onInputChange={handleInputChange} | ||
| loading={loading} | ||
| multiple={multiple} | ||
| disabled={disabled} | ||
| fullWidth | ||
| size="small" | ||
| getOptionLabel={(option) => option?.label || ""} | ||
| isOptionEqualToValue={(option, val) => option.value === val.value} | ||
| renderInput={(params) => ( | ||
| <TextField | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...params} | ||
| label={label} | ||
| placeholder={finalPlaceholder} | ||
| slotProps={{ | ||
| input: { | ||
| ...params.InputProps, | ||
| endAdornment: ( | ||
| <> | ||
| {loading && <CircularProgress color="inherit" size={16} />} | ||
| {params.InputProps?.endAdornment} | ||
| </> | ||
| ) | ||
| } | ||
| }} | ||
| /> | ||
| )} | ||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||
| {...autocompleteProps} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| AsyncSelectInput.propTypes = { | ||
| id: PropTypes.string.isRequired, | ||
| value: PropTypes.oneOfType([optionShape, PropTypes.arrayOf(optionShape), PropTypes.string]), | ||
| label: PropTypes.string, | ||
| placeholder: PropTypes.string, | ||
| disabled: PropTypes.bool, | ||
| multiple: PropTypes.bool, | ||
| queryFunction: PropTypes.func.isRequired, | ||
| formatOption: PropTypes.func, | ||
| debounceWait: PropTypes.number, | ||
| minSearchLength: PropTypes.number, | ||
| onChange: PropTypes.func.isRequired | ||
| }; | ||
|
|
||
| AsyncSelectInput.defaultProps = { | ||
| value: null, | ||
| label: "", | ||
| placeholder: "", | ||
| disabled: false, | ||
| multiple: false, | ||
| formatOption: defaultFormatOption, | ||
| debounceWait: DEBOUNCE_WAIT_250, | ||
| minSearchLength: 0 | ||
| }; | ||
|
|
||
| export default AsyncSelectInput; | ||
This file contains hidden or 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,179 @@ | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * */ | ||
|
|
||
| import React, { useEffect } from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import Box from "@mui/material/Box"; | ||
|
santipalenque marked this conversation as resolved.
|
||
| import Paper from "@mui/material/Paper"; | ||
| import Table from "@mui/material/Table"; | ||
| import TableBody from "@mui/material/TableBody"; | ||
| import TableCell from "@mui/material/TableCell"; | ||
| import TableContainer from "@mui/material/TableContainer"; | ||
| import TableHead from "@mui/material/TableHead"; | ||
| import TableRow from "@mui/material/TableRow"; | ||
| import Checkbox from "@mui/material/Checkbox"; | ||
| import Toolbar from "./components/Toolbar"; | ||
| import Heading from "./components/Heading"; | ||
| import Row from "./components/Row"; | ||
| import useRowSelection from "./hooks/useRowSelection"; | ||
| import styles from "./BulkEditTable.module.less"; | ||
| import CustomTablePagination from "../table/CustomTablePagination"; | ||
|
|
||
| const BulkEditTable = ({ options, columns, data, onSort, onUpdate, totalRows, perPage, currentPage, onPageChange, onPerPageChange, idKey }) => { | ||
| const { | ||
| selectedRows, | ||
| isSelected, | ||
| toggleRow, | ||
| isAllSelected, | ||
| toggleAll, | ||
| editField, | ||
| editEnabled, | ||
| enterEditMode, | ||
| cancel, | ||
| reset | ||
| } = useRowSelection(idKey); | ||
|
|
||
| const dataIds = data.map((row) => row[idKey]).join(","); | ||
|
|
||
| // reset selection/edit state whenever the set of rows shown changes | ||
| // (pagination, filtering, sorting, search, etc.) | ||
| useEffect(() => { | ||
| reset(); | ||
| }, [dataIds]); | ||
|
|
||
| const getSortDir = (columnKey) => | ||
| columnKey === options.sortCol ? options.sortDir : null; | ||
|
|
||
| const handleUpdateEvents = (evt) => { | ||
| evt.stopPropagation(); | ||
| evt.preventDefault(); | ||
|
santipalenque marked this conversation as resolved.
|
||
| Promise.resolve(onUpdate(selectedRows)) | ||
| .then(() => reset()) | ||
| .catch((error) => { | ||
| console.error("Error updating events:", error); | ||
| }); | ||
| }; | ||
|
santipalenque marked this conversation as resolved.
|
||
|
|
||
| return ( | ||
| <Box sx={{ width: "100%" }}> | ||
| <Toolbar | ||
| editEnabled={editEnabled} | ||
| hasSelection={selectedRows.length > 0} | ||
| onEdit={enterEditMode} | ||
| onApply={handleUpdateEvents} | ||
| onCancel={cancel} | ||
| /> | ||
| <Paper elevation={0} sx={{ width: "100%", mb: 2 }}> | ||
| <TableContainer | ||
| component={Paper} | ||
| className={styles.tableWrapper} | ||
| sx={{ borderRadius: 0, boxShadow: "none" }} | ||
| > | ||
| <Table> | ||
| <TableHead sx={{ backgroundColor: "#EAEDF4" }}> | ||
| <TableRow> | ||
| <TableCell | ||
| align="center" | ||
| className={styles.checkColumn} | ||
| sx={{ backgroundColor: "#EAEDF4" }} | ||
| > | ||
| <Checkbox | ||
| checked={isAllSelected(data)} | ||
| onChange={() => toggleAll(data)} | ||
| slotProps={{ input: { "aria-label": "select all" } }} | ||
| /> | ||
| </TableCell> | ||
| {columns.map((col, i) => { | ||
| const sortable = !!col.sortable; | ||
| const colWidth = col.width ?? ""; | ||
|
|
||
| return ( | ||
| <Heading | ||
| editEnabled={editEnabled} | ||
| onSort={onSort} | ||
| sortDir={getSortDir(col.columnKey)} | ||
| sortable={sortable} | ||
| columnIndex={i} | ||
| columnKey={col.columnKey} | ||
| width={colWidth} | ||
| key={`heading_${col.columnKey}`} | ||
| > | ||
| {col.header ?? col.label ?? col.value} | ||
| </Heading> | ||
| ); | ||
| })} | ||
| {(options.actions?.edit || options.actions?.delete) && ( | ||
| <TableCell | ||
| align="center" | ||
| className={styles.actionColumn} | ||
| sx={{ backgroundColor: "#EAEDF4" }} | ||
| > | ||
| {options.actionsHeader || " "} | ||
| </TableCell> | ||
| )} | ||
| </TableRow> | ||
| </TableHead> | ||
| <TableBody> | ||
| {columns.length > 0 && | ||
| data.map((row) => ( | ||
| <Row | ||
| key={`row_${row[idKey]}`} | ||
| row={row} | ||
| idKey={idKey} | ||
| editEnabled={editEnabled} | ||
| isSelected={isSelected(row[idKey])} | ||
| editRow={selectedRows.find((r) => r[idKey] === row[idKey]) || row} | ||
| onToggle={() => toggleRow(row)} | ||
| onFieldChange={(key, value) => | ||
| editField(row[idKey], key, value) | ||
| } | ||
| columns={columns} | ||
| actions={options.actions} | ||
| /> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
| </TableContainer> | ||
| {perPage && currentPage && onPageChange && ( | ||
| <CustomTablePagination | ||
| totalRows={totalRows} | ||
| perPage={perPage} | ||
| currentPage={currentPage} | ||
| onPageChange={onPageChange} | ||
| onPerPageChange={onPerPageChange} | ||
| /> | ||
| )} | ||
| </Paper> | ||
| </Box> | ||
| ); | ||
| }; | ||
|
|
||
| BulkEditTable.propTypes = { | ||
| options: PropTypes.object.isRequired, | ||
| columns: PropTypes.array.isRequired, | ||
| data: PropTypes.array.isRequired, | ||
| onSort: PropTypes.func.isRequired, | ||
| onUpdate: PropTypes.func.isRequired, | ||
| idKey: PropTypes.string, | ||
| totalRows: PropTypes.number, | ||
| perPage: PropTypes.number, | ||
| currentPage: PropTypes.number, | ||
| onPageChange: PropTypes.func, | ||
| onPerPageChange: PropTypes.func | ||
| }; | ||
|
|
||
| BulkEditTable.defaultProps = { | ||
| idKey: "id" | ||
| }; | ||
|
|
||
| export default BulkEditTable; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.