-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37293 - Add user columns to hosts index
- add column registry - add plugin documentation - Make breadcrumb a React link - Respect display_fqdn_for_hosts setting
- Loading branch information
1 parent
6cafc68
commit c21ac65
Showing
10 changed files
with
532 additions
and
19 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
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
89 changes: 89 additions & 0 deletions
89
webpack/assets/javascripts/react_app/components/ColumnSelector/helpers.js
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,89 @@ | ||
const getCheckedStateForCategory = (category = { children: [] }) => { | ||
// return true if all children are checked | ||
// return null if some children are checked | ||
// return false if no children are checked | ||
const checked = category.children.map(child => child.checkProps?.checked); | ||
if (checked.every(Boolean)) return true; | ||
if (checked.some(Boolean)) return null; | ||
return false; | ||
}; | ||
|
||
export const categoriesFromFrontendColumnData = ({ | ||
registeredColumns, | ||
userId, | ||
controller = 'hosts', | ||
userColumns = ['name'], | ||
hasPreference = false, | ||
}) => { | ||
// need to build an object like | ||
// { | ||
// "url": "/api/users/4/table_preferences", | ||
// "controller": "hosts", | ||
// "categories": [ | ||
// { | ||
// "name": "General", | ||
// "key": "general", | ||
// "defaultExpanded": true, | ||
// "checkProps": { | ||
// "checked": true | ||
// }, | ||
// "children": [ | ||
// { | ||
// "name": "Power", | ||
// "key": "power_status", | ||
// "checkProps": { | ||
// "disabled": null, | ||
// "checked": true | ||
// } | ||
// }, | ||
// ] | ||
// }, | ||
// ], | ||
// "hasPreference": true | ||
// } | ||
|
||
const result = { | ||
url: userId ? `/api/users/${userId}/table_preferences` : null, | ||
controller, | ||
hasPreference, | ||
}; | ||
|
||
const categories = []; | ||
Object.keys(registeredColumns).forEach(column => { | ||
const { | ||
categoryName, | ||
categoryKey, | ||
tableName, | ||
columnName, | ||
title, | ||
isRequired, | ||
} = registeredColumns[column]; | ||
if (tableName !== controller) return; | ||
const category = categories.find(cat => cat.key === categoryKey); | ||
if (!category) { | ||
categories.push({ | ||
name: categoryName, | ||
key: categoryKey, | ||
defaultExpanded: true, | ||
checkProps: { | ||
checked: false, | ||
}, | ||
children: [], | ||
}); | ||
} | ||
const categoryIndex = categories.findIndex(cat => cat.key === categoryKey); | ||
categories[categoryIndex].children.push({ | ||
name: title, | ||
key: columnName, | ||
checkProps: { | ||
checked: isRequired || userColumns.includes(columnName), | ||
disabled: isRequired ?? null, | ||
}, | ||
}); | ||
}); | ||
categories.forEach(category => { | ||
category.checkProps.checked = getCheckedStateForCategory(category); | ||
}); | ||
result.categories = categories; | ||
return result; | ||
}; |
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.