Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #34169 - Support bulk removing versions (#9899)
- Loading branch information
1 parent
b65c9e4
commit 197688c
Showing
28 changed files
with
4,891 additions
and
208 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
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
58 changes: 58 additions & 0 deletions
58
webpack/scenes/ContentViews/Details/Versions/BulkDelete/ActionSummary.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,58 @@ | ||
import React from 'react'; | ||
import { PropTypes } from 'prop-types'; | ||
import { | ||
Flex, | ||
FlexItem, | ||
Label, | ||
Text, | ||
} from '@patternfly/react-core'; | ||
import { ExclamationTriangleIcon } from '@patternfly/react-icons'; | ||
import { | ||
global_warning_color_100 as warningColor, | ||
} from '@patternfly/react-tokens'; | ||
|
||
const ActionSummary = ({ title, text, selectedEnv: { name, id } }) => ( | ||
<div> | ||
{title && | ||
<h3 style={{ margin: '8px 0' }}><b>{title}</b></h3> | ||
} | ||
{text && | ||
<Flex> | ||
<FlexItem style={{ marginRight: '8px' }}> | ||
<ExclamationTriangleIcon color={warningColor.value} /> | ||
</FlexItem> | ||
<FlexItem style={{ marginRight: '8px' }}> | ||
<Text>{text}</Text> | ||
</FlexItem> | ||
{name && id && | ||
<FlexItem> | ||
<Label isTruncated color="purple" href={`/lifecycle_environments/${id}`}>{name}</Label> | ||
</FlexItem> | ||
} | ||
</Flex> | ||
} | ||
</div>); | ||
|
||
|
||
ActionSummary.propTypes = { | ||
title: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.object, // React component | ||
]), | ||
text: PropTypes.oneOfType([ | ||
PropTypes.string, | ||
PropTypes.object, // React component | ||
]), | ||
selectedEnv: PropTypes.shape({ | ||
id: PropTypes.number, | ||
name: PropTypes.string, | ||
}), | ||
}; | ||
|
||
ActionSummary.defaultProps = { | ||
title: undefined, | ||
text: undefined, | ||
selectedEnv: {}, | ||
}; | ||
|
||
export default ActionSummary; |
45 changes: 45 additions & 0 deletions
45
webpack/scenes/ContentViews/Details/Versions/BulkDelete/BulkDeleteContextWrapper.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,45 @@ | ||
import React, { | ||
createContext, | ||
useState, | ||
} from 'react'; | ||
|
||
import { PropTypes } from 'prop-types'; | ||
|
||
export const BulkDeleteContext = createContext({}); | ||
|
||
const BulkDeleteContextWrapper = ({ | ||
children, versions, onClose, | ||
}) => { | ||
const [selectedEnvForAK, setSelectedEnvForAK] = useState([]); | ||
const [selectedCVForAK, setSelectedCVForAK] = useState(null); | ||
const [selectedEnvForHosts, setSelectedEnvForHosts] = useState([]); | ||
const [selectedCVForHosts, setSelectedCVForHosts] = useState(null); | ||
const [currentStep, setCurrentStep] = useState(1); | ||
|
||
return ( | ||
<BulkDeleteContext.Provider value={{ | ||
onClose, | ||
versions, | ||
selectedEnvForAK, | ||
setSelectedEnvForAK, | ||
selectedCVForAK, | ||
setSelectedCVForAK, | ||
selectedEnvForHosts, | ||
setSelectedEnvForHosts, | ||
selectedCVForHosts, | ||
setSelectedCVForHosts, | ||
currentStep, | ||
setCurrentStep, | ||
}} | ||
> | ||
{children} | ||
</BulkDeleteContext.Provider>); | ||
}; | ||
|
||
BulkDeleteContextWrapper.propTypes = { | ||
versions: PropTypes.arrayOf(PropTypes.shape({})).isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
children: PropTypes.element.isRequired, | ||
}; | ||
|
||
export default BulkDeleteContextWrapper; |
30 changes: 30 additions & 0 deletions
30
webpack/scenes/ContentViews/Details/Versions/BulkDelete/BulkDeleteHelpers.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,30 @@ | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { sum } from 'lodash'; | ||
|
||
export const getNumberOfActivationKeys = versions => | ||
sum(versions.map(({ environments }) => | ||
sum(environments.map(({ activation_key_count: akCount }) => akCount)))); | ||
|
||
export const getNumberOfHosts = versions => | ||
sum(versions.map(({ environments }) => | ||
sum(environments.map(({ host_count: hostCount }) => hostCount)))); | ||
|
||
// Gets a non-duplicated list of environments from within a given set of versions | ||
export const getEnvironmentList = (versions) => { | ||
const envIds = []; | ||
const environmentList = []; | ||
versions.forEach(({ environments }) => environments.forEach((env) => { | ||
if (!envIds.includes(env.id)) { | ||
environmentList.push(env); | ||
envIds.push(env.id); | ||
} | ||
})); | ||
return environmentList; | ||
}; | ||
|
||
export const getNumberOfEnvironments = versions => getEnvironmentList(versions).length; | ||
|
||
// Creates a string from a list of versions: '3.0' or '3.0 and 2.0' or '3.0, 2.0 and 1.0' etc. | ||
export const getVersionListString = versions => versions.map(({ version }, index) => | ||
`${index > 0 && index === (versions.length - 1) ? | ||
__(' and') : ''} ${version}${versions.length - index > 2 ? ',' : ''}`).join(''); |
56 changes: 56 additions & 0 deletions
56
webpack/scenes/ContentViews/Details/Versions/BulkDelete/BulkDeleteModal.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,56 @@ | ||
import React, { useContext } from 'react'; | ||
|
||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { PropTypes } from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import { Wizard } from '@patternfly/react-core'; | ||
|
||
import BulkDeleteContextWrapper, { | ||
BulkDeleteContext, | ||
} from './BulkDeleteContextWrapper'; | ||
import { | ||
getVersionListString, | ||
} from './BulkDeleteHelpers'; | ||
import bulkDeleteSteps from './bulkDeleteSteps'; | ||
|
||
const BulkDeleteModal = ({ versions, onClose }) => { | ||
const WizardWithContext = () => { | ||
const context = useContext(BulkDeleteContext); | ||
const versionList = getVersionListString(versions); | ||
const description = | ||
(<FormattedMessage | ||
id="bulk-delete-modal-title" | ||
values={{ versionList }} | ||
defaultMessage={versions.length === 1 ? | ||
__('Deleting version {versionList}') : | ||
__('Deleting versions: {versionList}')} | ||
/>); | ||
|
||
return ( | ||
<Wizard | ||
title={versions.length === 1 ? | ||
__('Delete version') : | ||
__('Delete versions')} | ||
description={description} | ||
steps={bulkDeleteSteps(context)} | ||
onGoToStep={({ id }) => context.setCurrentStep(id)} | ||
onNext={({ id }) => context.setCurrentStep(id)} | ||
onBack={({ id }) => context.setCurrentStep(id)} | ||
onClose={onClose} | ||
isOpen | ||
/>); | ||
}; | ||
|
||
return ( | ||
<BulkDeleteContextWrapper {...{ versions, onClose }}> | ||
<WizardWithContext /> | ||
</BulkDeleteContextWrapper> | ||
); | ||
}; | ||
|
||
BulkDeleteModal.propTypes = { | ||
versions: PropTypes.arrayOf(PropTypes.shape({})).isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
}; | ||
export default BulkDeleteModal; |
Oops, something went wrong.