Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openstack-uicore-foundation",
"version": "5.0.34",
"version": "5.0.36-beta.1",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missing @mui/x-date-pickers in peerDependencies.

The new DateTimeInput component uses DateTimePicker from @mui/x-date-pickers, but this package is only listed in devDependencies (line 30), not in peerDependencies. Since this is a component library that exports GridFilter to consuming applications, @mui/x-date-pickers must be declared as a peer dependency.

Without this declaration, consuming applications that use GridFilter with the new datetime value type will encounter runtime errors when DateTimeInput attempts to import DateTimePicker, and developers won't receive clear guidance from package.json about the missing dependency.

📦 Proposed fix to add missing peer dependency
     "peerDependencies": {
         "`@emotion/react`": "^11.11.4",
         "`@emotion/styled`": "^11.11.5",
         "`@mui/icons-material`": "^6.4.3",
         "`@mui/material`": "^6.4.3",
+        "`@mui/x-date-pickers`": "^7.26.0",
         "`@react-pdf/renderer`": "^3.1.11",
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@package.json` at line 3, The `@mui/x-date-pickers` package is currently listed
only in devDependencies but needs to be added to peerDependencies as well, since
the new DateTimeInput component (which uses DateTimePicker from this package) is
exported as part of the GridFilter component library. Add `@mui/x-date-pickers` to
the peerDependencies section in package.json with the same version constraint as
what is currently specified in devDependencies, so that consuming applications
receive clear guidance about this required dependency when using GridFilter with
the datetime value type.

"description": "ui reactjs components for openstack marketing site",
"main": "lib/openstack-uicore-foundation.js",
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions src/components/mui/Dropdown/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Dropdown.propTypes = {
label: PropTypes.string.isRequired,
disabled: PropTypes.bool
})
).isRequired,
),
label: PropTypes.string,
placeholder: PropTypes.string,
onChange: PropTypes.func.isRequired
Expand All @@ -95,7 +95,8 @@ Dropdown.propTypes = {
Dropdown.defaultProps = {
value: null,
label: "",
placeholder: ""
placeholder: "",
options: null
};

export default Dropdown;
15 changes: 11 additions & 4 deletions src/components/mui/GridFilter/GridFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Filter from "./components/Filter";
import FilterButton from "./components/FilterButton";
import { saveFilters } from "./actions/filter-actions";
import useGridFilter from "./hooks/useGridFilter";
import { JOIN_OPERATORS, OPERATORS, EMPTY_FILTER } from "./utils";
import { JOIN_OPERATORS, OPERATORS, EMPTY_FILTER, ASYNC_VALUE_TYPES } from "./utils";

const OPERATOR_VALUES = Object.values(OPERATORS).map((op) => op.value);

Expand All @@ -55,14 +55,21 @@ const GridFilter = ({ id, criterias, hideJoinOperators = false, onApply, saveFil
}, [valuesString, joinOperator, openModal]);

const parseFilter = (filter) => {
const parser = criterias.find(
({ key }) => key === filter.criteria
)?.customParser;
const criteria = criterias.find(({ key }) => key === filter.criteria);
const parser = criteria?.customParser;

if (!parser && ASYNC_VALUE_TYPES.includes(criteria?.values?.type)) {
console.error(
`GridFilter: criteria "${filter.criteria}" uses async value type "${criteria.values.type}" but defines no customParser — its value will not serialize into the API filter string correctly.`
);
}

if (parser) {
return parser(filter);
}

// TODO: use escapeFilterValue

const value = Array.isArray(filter.value)
? filter.value.join("||")
: filter.value;
Expand Down
57 changes: 31 additions & 26 deletions src/components/mui/GridFilter/components/Filter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,37 @@ const Filter = ({ id, value, criterias, onChange, onAdd, onDelete }) => {
<Grid2 container spacing={2} sx={{ alignItems: "center", mb: 2 }}>
<Grid2 size={11}>
<Box sx={{ display: "flex", alignItems: "center", gap: "14px" }}>
<Dropdown
id={`${id}-column`}
value={value?.criteria || ""}
placeholder={T.translate("grid_filter.select_criteria")}
options={criteriaOptions}
onChange={handleChangeCriteria}
/>
<Dropdown
id={`${id}-operator`}
value={value?.operator || ""}
placeholder={T.translate("grid_filter.select_operator")}
options={operatorOptions}
disabled={!value?.criteria}
onChange={handleChangeOperator}
/>
<ValueInput
id={`${id}-value`}
value={value?.value ?? defaultValue}
type={valueSettings.type}
placeholder={T.translate("grid_filter.select_values")}
disabled={!value?.criteria}
// eslint-disable-next-line react/jsx-props-no-spreading
{...valueSettings.props}
options={valueOptions}
onChange={handleChangeValue}
/>
<Box sx={{ flex: "0 0 220px" }}>
<Dropdown
id={`${id}-column`}
value={value?.criteria || ""}
placeholder={T.translate("grid_filter.select_criteria")}
options={criteriaOptions}
onChange={handleChangeCriteria}
/>
</Box>
<Box sx={{ flex: "0 0 220px" }}>
<Dropdown
id={`${id}-operator`}
value={value?.operator || ""}
placeholder={T.translate("grid_filter.select_operator")}
options={operatorOptions}
disabled={!value?.criteria}
onChange={handleChangeOperator}
/>
</Box>
<Box sx={{ flex: "1 1 auto", minWidth: 0 }}>
<ValueInput
id={`${id}-value`}
value={value?.value ?? defaultValue}
type={valueSettings.type}
disabled={!value?.criteria}
// eslint-disable-next-line react/jsx-props-no-spreading
{...valueSettings.props}
options={valueOptions}
onChange={handleChangeValue}
/>
</Box>
</Box>
</Grid2>
<Grid2 size={1}>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/**
* 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);

// 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 (searchTerm && searchTerm.length < minSearchLength) {
setOptions([]);
return;
}
setLoading(true);
queryFunction(searchTerm, (rawResults) => {
setOptions((rawResults || []).map((item) => ({ ...formatOption(item), raw: item })));
setLoading(false);
});
};

useEffect(() => {
fetchOptions("");
return () => {
if (debounceRef.current) clearTimeout(debounceRef.current);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Comment on lines +56 to +74

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard against stale/out-of-order async responses when typing quickly.

fetchOptions accepts every callback result, so slower earlier requests can overwrite newer results, and callbacks can still update state after unmount. Track a request id + mounted flag so only the latest active request mutates state.

💡 Suggested fix
@@
   const [options, setOptions] = useState([]);
   const [loading, setLoading] = useState(false);
   const debounceRef = useRef(null);
+  const lastRequestIdRef = useRef(0);
+  const isMountedRef = useRef(true);
@@
   const fetchOptions = (searchTerm) => {
+    const requestId = ++lastRequestIdRef.current;
     if (searchTerm && searchTerm.length < minSearchLength) {
       setOptions([]);
+      setLoading(false);
       return;
     }
     setLoading(true);
     queryFunction(searchTerm, (rawResults) => {
+      if (!isMountedRef.current || requestId !== lastRequestIdRef.current) return;
       setOptions((rawResults || []).map((item) => ({ ...formatOption(item), raw: item })));
       setLoading(false);
     });
   };
@@
   useEffect(() => {
     fetchOptions("");
     return () => {
+      isMountedRef.current = false;
       if (debounceRef.current) clearTimeout(debounceRef.current);
     };

Also applies to: 76-80

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/mui/GridFilter/components/ValueInput/AsyncSelectInput.jsx`
around lines 56 - 74, The fetchOptions function has a race condition where
slower earlier requests can overwrite newer results when the user types quickly,
and callbacks can also update state after unmount. Add a ref to track the
mounted status and another ref to track the current request ID. In the
useEffect, set mounted to true and clear it in the cleanup function. Modify
fetchOptions to generate a unique request ID for each call and pass it to the
queryFunction callback. In the callback, before calling setOptions and
setLoading, check that the request ID matches the current request ID stored in
the ref and that the component is still mounted. This ensures only the latest
active request mutates state and prevents updates after unmount.


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("grid_filter.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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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 from "react";
import PropTypes from "prop-types";
import T from "i18n-react/dist/i18n-react";
import AsyncSelectInput from "./AsyncSelectInput";
import { queryCompanies } from "../../../../../utils/query-actions";

const defaultFormatOption = (company) => ({
value: company.id,
label: company.name
});

const CompanySelectInput = ({ queryFunction, placeholder, ...rest }) => (
<AsyncSelectInput
queryFunction={queryFunction || queryCompanies}
placeholder={placeholder || T.translate("grid_filter.placeholders.company")}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
);

CompanySelectInput.propTypes = {
queryFunction: PropTypes.func,
placeholder: PropTypes.string
};

CompanySelectInput.defaultProps = {
queryFunction: null,
formatOption: defaultFormatOption
};

export default CompanySelectInput;
Loading
Loading