Skip to content

Commit

Permalink
refactor(HMS 4849): Remove/update features to support new content tem…
Browse files Browse the repository at this point in the history
…plates (#1208)

* chore(deps): Updating FEC and related packages

* Feedback from review

* HMS 4849: Remove/update features to support new content templates

* Add content/templates redirect
  • Loading branch information
Andrewgdewar authored Nov 12, 2024
1 parent e4e70f6 commit 55cd68f
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 144 deletions.
34 changes: 21 additions & 13 deletions src/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ const PackageDetail = lazy(() =>
)
);

const Templates = lazy(() =>
import(
/* webpackChunkName: "Templates" */ './SmartComponents/PatchSet/PatchSet'
)
);

const TemplateDetail = lazy(() =>
import(
/* webpackChunkName: "TemplateDetail" */ './SmartComponents/PatchSetDetail/PatchSetDetail'
)
);
// const Templates = lazy(() =>
// import(
// /* webpackChunkName: "Templates" */ './SmartComponents/PatchSet/PatchSet'
// )
// );

// const TemplateDetail = lazy(() =>
// import(
// /* webpackChunkName: "TemplateDetail" */ './SmartComponents/PatchSetDetail/PatchSetDetail'
// )
// );

const PatchRoutes = () => {
const generalPermissions = ['patch:*:*', 'patch:*:read'];
Expand Down Expand Up @@ -121,8 +121,16 @@ const PatchRoutes = () => {
<Route path='/packages/:packageName' element={<PackageDetail />} />
<Route path='/packages/:packageName/:inventoryId'
element={<NavigateToSystem />} />
<Route path='/templates' element={<Templates />} />
<Route path='/templates/:templateName' element={<TemplateDetail />} />
<Route path='/templates' >
<Route path='' element={
<Navigate relative="route" to={'/insights/content/templates'} replace />
} />
<Route path='*' element={
<Navigate relative="route" to={'/insights/content/templates'} replace /> }
/>
</Route>
{/* <Route path='/templates' element={<Templates />} />
<Route path='/templates/:templateName' element={<TemplateDetail />} /> */}
<Route path='*' element={<Navigate to="advisories" />} />
</Route>
</Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ const AdvisorySystemsTable = ({
}}
getEntities={getEntites}
tableProps={{
actionResolver: (row) => systemsRowActions(activateRemediationModal, undefined, undefined, row),
actionResolver: (row) => systemsRowActions(activateRemediationModal, row),
canSelectAll: false,
variant: TableVariant.compact, className: 'patchCompactInventory', isStickyHeader: true
}}
Expand Down
2 changes: 1 addition & 1 deletion src/SmartComponents/Modals/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const filterChosenSystems = (urlFilter, systemsIDs, fetchBatched, totalItems) =>
};

export const filterSystemsWithoutSets = (systemsIDs, fetchBatched, totalItems) => {
const urlFilter = { 'filter[baseline_name]': 'neq:' };
const urlFilter = { 'filter[template_name]': 'neq:' };
return filterChosenSystems(urlFilter, systemsIDs, fetchBatched, totalItems);
};

Expand Down
2 changes: 1 addition & 1 deletion src/SmartComponents/PatchSetWizard/WizardAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const reviewSystemColumns = [{
transforms: [sortable]
},
{
key: 'baseline_name',
key: 'template_name',
title: 'Template',
props: {
width: 20
Expand Down
42 changes: 21 additions & 21 deletions src/SmartComponents/SystemDetail/InventoryDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ import { useParams } from 'react-router-dom';
import SystemDetail from './SystemDetail';
import { useChrome } from '@redhat-cloud-services/frontend-components/useChrome';
import { InsightsLink } from '@redhat-cloud-services/frontend-components/InsightsLink';
import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook';

const InventoryDetail = () => {
const { inventoryId } = useParams();
const store = useStore();
const dispatch = useDispatch();

const { hasThirdPartyRepo, satelliteManaged, patchSetName, patchSetId } = useSelector(
const { hasThirdPartyRepo, satelliteManaged, patchSetName, templateUUID } = useSelector(
({ SystemDetailStore }) => SystemDetailStore
);

const { display_name: displayName } = useSelector(
({ entityDetails }) => entityDetails?.entity ?? {}
);

const { patchSetState, setPatchSetState, openAssignSystemsModal, openUnassignSystemsModal } = usePatchSetState();
const { patchSetState, setPatchSetState /*,openAssignSystemsModal, openUnassignSystemsModal */ } = usePatchSetState();

useEffect(() => {
dispatch(fetchSystemDetailsAction(inventoryId));
Expand All @@ -53,10 +52,10 @@ const InventoryDetail = () => {
displayName && chrome.updateDocumentTitle(`${displayName} - Systems - Patch | RHEL`, true);
}, [chrome, displayName]);

const { hasAccess: hasTemplateAccess } = usePermissionsWithContext([
'patch:*:*',
'patch:template:write'
]);
// const { hasAccess: hasTemplateAccess } = usePermissionsWithContext([
// 'patch:*:*',
// 'patch:template:write'
// ]);

return (
<DetailWrapper
Expand Down Expand Up @@ -89,27 +88,28 @@ const InventoryDetail = () => {
showTags
inventoryId={inventoryId}
actions={[
{
title: intl.formatMessage(messages.titlesTemplateAssign),
key: 'assign-to-template',
isDisabled: !hasTemplateAccess || satelliteManaged,
onClick: () => openAssignSystemsModal({ [inventoryId]: true })
},
{
title: intl.formatMessage(messages.titlesTemplateRemoveMultipleButton),
key: 'remove-from-template',
isDisabled: !hasTemplateAccess || !patchSetName || satelliteManaged,
onClick: () => openUnassignSystemsModal([inventoryId])
}]}
// {
// title: intl.formatMessage(messages.titlesTemplateAssign),
// key: 'assign-to-template',
// isDisabled: !hasTemplateAccess || satelliteManaged,
// onClick: () => openAssignSystemsModal({ [inventoryId]: true })
// },
// {
// title: intl.formatMessage(messages.titlesTemplateRemoveMultipleButton),
// key: 'remove-from-template',
// isDisabled: !hasTemplateAccess || !patchSetName || satelliteManaged,
// onClick: () => openUnassignSystemsModal([inventoryId])
// }
]}
//FIXME: remove this prop after inventory detail gets rid of activeApps in redux
appList={[]}
>
<Grid>
{patchSetName && <GridItem>
<TextContent>
<Text>
{intl.formatMessage(messages.labelsColumnsTemplate)}:
<InsightsLink to={`/templates/${patchSetId}`} className="pf-v5-u-ml-xs">
{intl.formatMessage(messages.labelsColumnsTemplate)}:{' '}
<InsightsLink app="content" to={{ pathname: `/templates/${templateUUID}/details` }}>
{patchSetName}
</InsightsLink>
</Text>
Expand Down
2 changes: 1 addition & 1 deletion src/SmartComponents/Systems/SystemListAssets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('SystemListAssets.js', () => {
});
it('Should disable "Apply all applicable advisories" action when there is no applicable advisories ', () => {
const testRow = { applicable_advisories: [0, 0, 0, 0] };
const actions = systemsRowActions(null, null, null, testRow);
const actions = systemsRowActions(null, testRow);
expect(actions).toEqual(
[{ isDisabled: true, onClick: expect.any(Function), title: 'Apply all applicable advisories' }]
);
Expand Down
60 changes: 30 additions & 30 deletions src/SmartComponents/Systems/SystemTable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,36 +181,36 @@ describe('SystemsTable', () => {
));
});

it('should provide actions config', async () => {
await renderComponent(mockState);
expect(InventoryTable).toHaveBeenCalledWith(
expect.objectContaining({
actionsConfig: {
actions: [
//Remdiation button
expect.anything(),
{
key: 'assign-multiple-systems',
label: 'Assign to a template',
onClick: expect.any(Function),
props: {
isDisabled: true
}
},
{
key: 'remove-multiple-systems',
label: 'Remove from a template',
onClick: expect.any(Function),
props: {
isDisabled: true
}
}
]
}
}),
{}
);
});
// it('should provide actions config', async () => {
// await renderComponent(mockState);
// expect(InventoryTable).toHaveBeenCalledWith(
// expect.objectContaining({
// actionsConfig: {
// actions: [
// //Remdiation button
// expect.anything(),
// {
// key: 'assign-multiple-systems',
// label: 'Assign to a template',
// onClick: expect.any(Function),
// props: {
// isDisabled: true
// }
// },
// {
// key: 'remove-multiple-systems',
// label: 'Remove from a template',
// onClick: expect.any(Function),
// props: {
// isDisabled: true
// }
// }
// ]
// }
// }),
// {}
// );
// });

it('should provide activeFilters config', async () => {
await renderComponent(mockState);
Expand Down
64 changes: 35 additions & 29 deletions src/SmartComponents/Systems/SystemsListAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ export const systemsListColumns = () => [
}
},
{
key: 'baseline_name',
key: 'template_name',
title: 'Template',
renderFunc: (value, _, row) =>
row.satellite_managed
? <ManagedBySatelliteCell />
: value
? <InsightsLink to={{ pathname: `/templates/${row.baseline_id}` }}>{value}</InsightsLink>
? <InsightsLink app="content" to={{ pathname: `/templates/${row.template_uuid}/details` }}>
{value}
</InsightsLink>
: 'No template',
props: {
width: 5
Expand Down Expand Up @@ -71,13 +73,15 @@ export const advisorySystemsColumns = () => [
}
},
{
key: 'baseline_name',
key: 'template_name',
title: 'Template',
renderFunc: (value, _, row) =>
row.satellite_managed
? <ManagedBySatelliteCell />
: value
? <InsightsLink to={{ pathname: `/templates/${row.baseline_id}` }}>{value}</InsightsLink>
? <InsightsLink app="content" to={{ pathname: `/templates/${row.template_uuid}/details` }}>
{value}
</InsightsLink>
: 'No template',
props: {
width: 5
Expand All @@ -104,13 +108,15 @@ export const packageSystemsColumns = [
}
},
{
key: 'baseline_name',
key: 'template_name',
title: 'Template',
renderFunc: (value, _, row) =>
row.satellite_managed
? <ManagedBySatelliteCell />
: value
? <InsightsLink to={{ pathname: `/templates/${row.baseline_id}` }}>{value}</InsightsLink>
? <InsightsLink app="content" to={{ pathname: `/templates/${row.template_uuid}/details` }}>
{value}
</InsightsLink>
: 'No template',
props: {
width: 5
Expand Down Expand Up @@ -147,10 +153,10 @@ const isRemediationDisabled = (row) => {
return (applicableAdvisories && applicableAdvisories.every(typeSum => typeSum === 0)) || (status === 'Applicable');
};

const isPatchSetRemovalDisabled = (row) => {
const { baseline_name: baselineName } = row || {};
return !baselineName || (typeof baselineName === 'string' && baselineName === '');
};
// const isPatchSetRemovalDisabled = (row) => {
// const { template_name: templateName } = row || {};
// return !templateName || (typeof templateName === 'string' && templateName === '');
// };

export const useActivateRemediationModal = (setRemediationIssues, setRemediationOpen) => {
const { fetchBatched } = useFetchBatched();
Expand Down Expand Up @@ -190,10 +196,10 @@ export const useActivateRemediationModal = (setRemediationIssues, setRemediation

export const systemsRowActions = (
activateRemediationModal,
showTemplateAssignSystemsModal,
openUnassignSystemsModal,
row,
hasTemplateAccess
// showTemplateAssignSystemsModal,
// openUnassignSystemsModal,
row
// hasTemplateAccess
) => {
return [
{
Expand All @@ -202,22 +208,22 @@ export const systemsRowActions = (
onClick: (event, rowId, rowData) => {
activateRemediationModal(rowData);
}
},
...(showTemplateAssignSystemsModal ? [{
title: 'Assign to a template',
isDisabled: !hasTemplateAccess || row.satellite_managed,
onClick: (event, rowId, rowData) => {
showTemplateAssignSystemsModal({ [rowData.id]: true });
}
},
{
title: 'Remove from a template',
isDisabled: !hasTemplateAccess || isPatchSetRemovalDisabled(row) || row.satellite_managed,
onClick: (event, rowId, rowData) => {
openUnassignSystemsModal([rowData.id]);
}
}
] : [])
// ...(showTemplateAssignSystemsModal ? [{
// title: 'Assign to a template',
// isDisabled: !hasTemplateAccess || row.satellite_managed,
// onClick: (event, rowId, rowData) => {
// showTemplateAssignSystemsModal({ [rowData.id]: true });
// }
// },
// {
// title: 'Remove from a template',
// isDisabled: !hasTemplateAccess || isPatchSetRemovalDisabled(row) || row.satellite_managed,
// onClick: (event, rowId, rowData) => {
// openUnassignSystemsModal([rowData.id]);
// }
// }
// ] : [])
];
};

6 changes: 3 additions & 3 deletions src/SmartComponents/Systems/SystemsMainContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const SystemsMainContent = () => {
}, []);

const {
patchSetState, setPatchSetState, openUnassignSystemsModal, openAssignSystemsModal
patchSetState, setPatchSetState// openUnassignSystemsModal, openAssignSystemsModal
} = usePatchSetState(selectedRows);

const activateRemediationModal = useActivateRemediationModal(
Expand Down Expand Up @@ -75,8 +75,8 @@ const SystemsMainContent = () => {
<SystemsTable
apply={apply}
patchSetState={patchSetState}
openAssignSystemsModal={openAssignSystemsModal}
openUnassignSystemsModal={openUnassignSystemsModal}
// openAssignSystemsModal={openAssignSystemsModal}
// openUnassignSystemsModal={openUnassignSystemsModal}
setSearchParams={setSearchParams}
activateRemediationModal={activateRemediationModal}
decodedParams={decodeQueryparams}
Expand Down
Loading

0 comments on commit 55cd68f

Please sign in to comment.