-
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
Merged
+2,563
−223
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
730927f
chore: adding operators
santipalenque 95e431f
chore: add new value inputs
santipalenque 5b5d374
v5.0.36-beta.0
santipalenque e794d55
chore: add setFilters functionality for saved filters
santipalenque f79e1e3
chore: update version
santipalenque c9ceda6
chore: consolidate pagination accross all tables and add bulkedittable
santipalenque b5fd606
v5.0.36-beta.2
santipalenque fa6eed1
chore: first round of PR review
santipalenque c839eb8
chore: PR review round 2
santipalenque f5d59f2
v5.0.37-beta.0
santipalenque 74f0eae
chore: pr review part 1
santipalenque 0160c21
chore: pr review part 2
santipalenque c1bce53
chore: move delete prompt to table
santipalenque 3135187
v5.0.37-beta.1
santipalenque 3ea5bd5
chore: bug fixes
santipalenque 6257b4a
v5.0.37-beta.2
santipalenque fd085ee
chore: pr review fixes
santipalenque d97c2fe
chore: pr review part 2
santipalenque d5bdd02
fix: literal placeholder
santipalenque 7baf9d4
fix: missing propTypes
santipalenque 6a40fdf
Merge branch 'main' into feature/grid-filter-continued
smarcet 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| /** | ||
| * 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 { ASYNC_SELECT_SAFETY_TIMEOUT, 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); | ||
| // Backstops a queryFunction whose callback never fires (e.g. a non-404 | ||
| // HTTP error swallowed upstream) so the spinner doesn't spin forever. | ||
| const safetyTimeoutRef = useRef(null); | ||
|
|
||
| // 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); | ||
|
|
||
| if (safetyTimeoutRef.current) clearTimeout(safetyTimeoutRef.current); | ||
| safetyTimeoutRef.current = setTimeout(() => { | ||
| if (mountedRef.current && thisRequestId === requestIdRef.current) { | ||
| setLoading(false); | ||
| } | ||
| }, ASYNC_SELECT_SAFETY_TIMEOUT); | ||
|
|
||
| queryFunction(searchTerm, (rawResults) => { | ||
|
santipalenque marked this conversation as resolved.
|
||
| if (!mountedRef.current || thisRequestId !== requestIdRef.current) return; | ||
| clearTimeout(safetyTimeoutRef.current); | ||
| // queryFunction implementations may invoke the callback with something | ||
| // other than an array (e.g. an Error on auth failure), so guard here | ||
| // rather than assume the shape. | ||
| const items = Array.isArray(rawResults) ? rawResults : []; | ||
| setOptions(items.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); | ||
| if (safetyTimeoutRef.current) clearTimeout(safetyTimeoutRef.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; | ||
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.