Skip to content
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

feat(RHINENG-8850): add objects name to the modal #763

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/AppConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ export const WORKLOADS_RULES_FILTER_CONFIG = (filters, addParamFunction) => [
];

export const ObjectsTableColumns = {
display_name: 'Name',
object: 'Object ID',
kind: 'Kind',
};
Expand Down
14 changes: 13 additions & 1 deletion src/Components/ObjectsModal/ObjectsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ObjectsModal = ({ isModalOpen, setIsModalOpen, objects }) => {
setIsModalOpen(false);
resetFilters(filters, WORKLOADS_OBJECTS_TABLE_INITIAL_STATE, updateFilters);
};
const objectsWithNames = objects.filter((object) => object.display_name);

return (
<PfModal
Expand All @@ -28,7 +29,10 @@ const ObjectsModal = ({ isModalOpen, setIsModalOpen, objects }) => {
variant={'medium'}
title="Objects"
>
<ObjectsModalTable objects={objects} />
<ObjectsModalTable
objects={objects}
objectsWithNames={objectsWithNames}
/>
</PfModal>
);
};
Expand All @@ -42,6 +46,14 @@ ObjectsModal.propTypes = {
PropTypes.shape({
kind: PropTypes.string,
uid: PropTypes.string,
display_name: PropTypes.string,
})
),
objectsNamesArePresent: PropTypes.arrayOf(
PropTypes.shape({
kind: PropTypes.string,
uid: PropTypes.string,
display_name: PropTypes.string,
})
),
};
36 changes: 30 additions & 6 deletions src/Components/ObjectsModalTable/ObjectsModalTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,38 @@ export const ObjectsModalTable = ({ objects }) => {
placeholder: 'Filter by Object ID',
},
},
{
label: 'Object name',
type: 'text',
filterValues: {
key: 'display_name',
onChange: (_event, value) =>
updateFilters({ ...filters, offset: 0, display_name: value }),
value: filters.display_name,
placeholder: 'Filter by name',
},
},
];

const buildFilterChips = () => {
const localFilters = { ...filters };
delete localFilters.sortIndex;
delete localFilters.sortDirection;
return pruneWorkloadsRulesFilters(localFilters, {
label: 'Object ID',
type: 'text',
title: 'object ID',
urlParam: 'object_id',
});
return pruneWorkloadsRulesFilters(
localFilters,
{
label: 'Object ID',
type: 'text',
title: 'object ID',
urlParam: 'object_id',
},
{
label: 'Object name',
type: 'text',
title: 'object name',
urlParam: 'display_name',
}
);
};

const activeFiltersConfig = {
Expand Down Expand Up @@ -151,13 +171,17 @@ export const ObjectsModalTable = ({ objects }) => {
<Table aria-label="Cell widths" variant="compact">
<Thead>
<Tr>
<Th width={30}>{ObjectsTableColumns.display_name}</Th>
<Th width={60}>{ObjectsTableColumns.object}</Th>
<Th width={30}>{ObjectsTableColumns.kind}</Th>
</Tr>
</Thead>
<Tbody>
{displayedRows?.map((object, index) => (
<Tr key={index}>
<Td dataLabel={ObjectsTableColumns.display_name}>
{object.display_name}
</Td>
<Td dataLabel={ObjectsTableColumns.object}>{object.uid}</Td>
<Td dataLabel={ObjectsTableColumns.kind}>{object.kind}</Td>
</Tr>
Expand Down
1 change: 1 addition & 0 deletions src/Services/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const WORKLOADS_OBJECTS_TABLE_INITIAL_STATE = {
limit: 50,
offset: 0,
object_id: '',
display_name: '',
};

const filtersInitialState = {
Expand Down
24 changes: 21 additions & 3 deletions src/Utilities/Workloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export const pruneWorkloadsRulesFilters = (localFilters, filterCategories) => {
});
}
} else if (
(name === 'description' || name === 'object_id') &&
(name === 'description' ||
name === 'object_id' ||
name === 'display_name') &&
value.trim() !== ''
) {
arr.push({
Expand Down Expand Up @@ -186,12 +188,28 @@ export const flatMapRows = (filteredRows, expandFirst) => {
};

export const passObjectsFilters = (objects, filters) => {
return Object.entries(filters).some(([filterKey, filterValue]) => {
console.log(filters);
const cleanedUpFilters = _.omitBy(_.cloneDeep(filters), _.isEmpty);
return Object.entries(cleanedUpFilters).every(([filterKey, filterValue]) => {
switch (filterKey) {
case 'display_name':
return (
filterValue &&
objects.display_name.toLowerCase().includes(filterValue.toLowerCase())
);
case 'object_id':
return (
filterValue &&
objects.uid.toLowerCase().includes(filterValue.toLowerCase())
);
/* case 'object_id':
return objects.uid.toLowerCase().includes(filterValue.toLowerCase());
case 'display_name':
return objects.display_name
.toLowerCase()
.includes(filterValue.toLowerCase()); */
default:
return false;
return true;
}
});
};
Expand Down