Skip to content

Commit

Permalink
Fixes #37553 - Wait for all plugin JS to load before rendering Column…
Browse files Browse the repository at this point in the history
…Selector
  • Loading branch information
jeremylenz authored and MariaAga committed Jun 13, 2024
1 parent 94b3416 commit 58e8f94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const ColumnSelector = props => {
icon={<ColumnsIcon />}
iconPosition="left"
className="columns-selector"
onClick={() => toggleModal()}
onClick={toggleModal}
title={__('Manage columns')}
>
<span className="columns-selector-text">{__('Manage columns')}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export const ForemanHostsIndexActionsBarContext = forceSingleton(
);

const HostsIndex = () => {
const [allColumns, setAllColumns] = useState(
getColumnData({ tableName: 'hosts' })
);
const [allJsLoaded, setAllJsLoaded] = useState(false);
const {
searchParam: urlSearchQuery = '',
page: urlPage,
Expand Down Expand Up @@ -92,7 +96,16 @@ const HostsIndex = () => {
setAPIOptions: response.setAPIOptions,
});

const allColumns = getColumnData({ tableName: 'hosts' });
useEffect(() => {
const handleLoadJS = () => {
setAllColumns(getColumnData({ tableName: 'hosts' }));
setAllJsLoaded(true);
};
document.addEventListener('loadJS', handleLoadJS);
return () => {
document.removeEventListener('loadJS', handleLoadJS);
};
}, [setAllColumns]);
const {
hasPreference,
columns: userColumns,
Expand Down Expand Up @@ -200,12 +213,12 @@ const HostsIndex = () => {
];

const registeredItems = useSelector(selectKebabItems, shallowEqual);
const pluginToolbarItems = (
const pluginToolbarItems = jsReady => (
<ForemanHostsIndexActionsBarContext.Provider
value={{ ...selectAllOptions, fetchBulkParams }}
>
<ActionKebab items={dropdownItems.concat(registeredItems)} />
<ColumnSelector data={columnSelectData} />
{jsReady && <ColumnSelector data={columnSelectData} />}
</ForemanHostsIndexActionsBarContext.Provider>
);

Expand Down Expand Up @@ -305,7 +318,7 @@ const HostsIndex = () => {
controller="hosts"
creatable={false}
replacementResponse={response}
customToolbarItems={pluginToolbarItems}
customToolbarItems={pluginToolbarItems(allJsLoaded)}
selectionToolbar={selectionToolbar}
updateSearchQuery={updateSearchQuery}
>
Expand Down

0 comments on commit 58e8f94

Please sign in to comment.