@patternfly/react-core#Backdrop JavaScript Examples
The following examples show how to use
@patternfly/react-core#Backdrop.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddDeviceModal.js From edge-frontend with Apache License 2.0 | 5 votes |
AddDeviceModal = ({
isModalOpen,
setIsModalOpen,
setIsCreateGroupModalOpen,
reloadData,
deviceIds,
}) => {
const dispatch = useDispatch();
const [response] = useApi({ api: getGroups });
const { data, isLoading } = response;
const handleAddDevices = (values) => {
const { group } = values;
const statusMessages = {
onSuccess: {
title: 'Success',
description: `Device(s) have been added to ${group.toString()} successfully`,
},
onError: { title: 'Error', description: 'Failed to add device to group' },
};
apiWithToast(
dispatch,
() => addDevicesToGroup(parseInt(group.groupId), deviceIds),
statusMessages
);
};
return isLoading ? (
<Backdrop>
<Bullseye>
<Spinner isSVG diameter="100px" />
</Bullseye>
</Backdrop>
) : (
<Modal
isOpen={isModalOpen}
openModal={() => setIsModalOpen(false)}
title="Add to group"
submitLabel="Add"
additionalMappers={{
'search-input': {
component: SearchInput,
defaultOptions: data?.data || [],
},
'create-group-btn': {
component: CreateGroupButton,
openModal: () => {
setIsCreateGroupModalOpen(true);
setIsModalOpen(false);
},
},
}}
schema={createSchema(deviceIds)}
onSubmit={handleAddDevices}
reloadData={reloadData}
/>
);
}
Example #2
Source File: UpdateImageModal.js From edge-frontend with Apache License 2.0 | 4 votes |
UpdateImageModal = ({ updateCveModal, setUpdateCveModal, setReload }) => {
const dispatch = useDispatch();
const { getRegistry } = useContext(RegistryContext);
const { data } = useSelector(
({ imageDetailReducer }) => ({
data: imageDetailReducer?.data || null,
}),
shallowEqual
);
useEffect(() => {
const registered = getRegistry().register({
imageDetailReducer,
});
updateCveModal?.imageId &&
loadImageDetail(dispatch, updateCveModal?.imageId);
return () => registered();
}, [dispatch]);
const handleUpdateModal = () => {
const payload = {
Id: data?.image?.ID,
description: data?.image?.Description,
name: data?.image?.Name,
version: data?.image?.Version + 1,
architecture: 'x86_64',
credentials: data?.image?.Installer.SshKey,
username: data?.image?.Installer.Username,
imageType: data?.image?.OutputTypes,
'selected-packages': data?.image?.Packages?.map((pack) => ({
name: pack.Name,
})),
release: data?.image?.Distribution,
};
handleClose();
setReload(true);
createNewImage(dispatch, payload, (resp) => {
dispatch({
...addNotification({
variant: 'info',
title: 'Update image',
description: `${resp.value.Name} image was added to the queue.`,
}),
meta: {
polling: {
id: `FETCH_IMAGE_${resp.value.ID}_BUILD_STATUS`,
fetcher: () => getEdgeImageStatus(resp.value.ID),
condition: (resp) => {
switch (resp.Status) {
case 'BUILDING':
return [true, ''];
case 'ERROR':
return [false, 'failure'];
default:
return [false, 'success'];
}
},
onEvent: {
failure: [
(dispatch) =>
dispatch(
addNotification({
variant: 'danger',
title: 'Image build failed',
description: `${resp.value.Name} image build is completed unsuccessfully`,
})
),
],
success: [
(dispatch) =>
dispatch(
addNotification({
variant: 'success',
title: 'Image is ready',
description: `${resp.value.Name} image build is completed`,
})
),
(dispatch) => loadEdgeImageSets(dispatch),
],
},
},
},
});
loadEdgeImageSets(dispatch);
dispatch(
addImageToPoll({ name: data?.image?.Name, id: data?.image?.ID })
);
});
};
const handleClose = () => {
setUpdateCveModal((prevState) => ({ ...prevState, isOpen: false }));
};
return data ? (
<Modal
variant="medium"
title={`Update image: ${data?.image?.Name}`}
description="Review the information and click Create image to start the build process"
isOpen={updateCveModal.isOpen}
onClose={handleClose}
//onSubmit={handleUpdateModal}
actions={[
<Button key="confirm" variant="primary" onClick={handleUpdateModal}>
Create Image
</Button>,
<Button key="cancel" variant="link" onClick={handleClose}>
Cancel
</Button>,
]}
>
<TextContent>
<TextListItem component={TextVariants.h3}>
<Text component={'b'}>Details</Text>
</TextListItem>
<TextList component={TextListVariants.dl}>
<TextListItem component={TextListItemVariants.dt}>Name</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{data?.image?.Name}
</TextListItem>
<TextListItem component={TextListItemVariants.dt}>
Version
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{data?.image?.Version + 1}
</TextListItem>
<TextListItem component={TextListItemVariants.dt}>
Description
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{data?.image?.Description}
</TextListItem>
</TextList>
<TextListItem component={TextVariants.h3}>
<Text component={'b'}>Output</Text>
</TextListItem>
<TextList component={TextListVariants.dl}>
<TextListItem component={TextListItemVariants.dt}>
Release
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{releaseMapper[data?.image?.Distribution]}
</TextListItem>
<TextListItem component={TextListItemVariants.dt}>
Output type
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{imageTypeMapper[data?.image?.ImageType]}
</TextListItem>
</TextList>
<TextListItem component={TextVariants.h3}>
<Text component={'b'}>Packages</Text>
</TextListItem>
<TextList component={TextListVariants.dl}>
<TextListItem component={TextListItemVariants.dt}>
Updated
</TextListItem>
<TextListItem
className="pf-u-pl-lg"
component={TextListItemVariants.dd}
>
{updateCveModal?.cveCount}
</TextListItem>
</TextList>
</TextContent>
</Modal>
) : (
<Backdrop>
<Bullseye>
<Spinner isSVG diameter="100px" />
</Bullseye>
</Backdrop>
);
}
Example #3
Source File: UpdateDeviceModal.js From edge-frontend with Apache License 2.0 | 4 votes |
UpdateDeviceModal = ({ updateModal, setUpdateModal, refreshTable }) => {
const [imageData, setImageData] = useState(null);
const dispatch = useDispatch();
const isMultiple = updateModal.deviceData.length > 1;
const deviceId = updateModal.deviceData.map((device) => device.id);
const deviceName = isMultiple
? updateModal.deviceData.map((device) => device.display_name)
: updateModal?.deviceData[0]?.display_name;
useEffect(() => {
updateModal?.imageSetId
? getImageSet({
id: updateModal.imageSetId,
q: {
limit: 1,
sort_by: '-created_at',
status: 'SUCCESS',
},
}).then((data) => setImageData(data.Data.images[0]))
: getImageData(updateModal.imageId).then((data) =>
setImageData(data.Data.images[0])
);
}, []);
const handleUpdateModal = async () => {
try {
await updateDeviceLatestImage({
DevicesUUID: deviceId,
});
dispatch({
...addNotification({
variant: 'info',
title: 'Updating device',
description: isMultiple
? ` ${deviceName.length} systems were added to the queue.`
: ` ${deviceName} was added to the queue.`,
}),
});
} catch (err) {
dispatch({
...addNotification({
variant: 'danger',
title: 'Updating a device was unsuccessful',
description: `Response: ${err.statusText}`,
}),
});
}
handleClose();
refreshTable ? refreshTable() : null;
};
const handleClose = () => {
setUpdateModal((prevState) => {
return {
...prevState,
isOpen: false,
};
});
};
const WarningText = () => (
<TextContent className="pf-u-pt-md">
<Text
style={{ color: 'var(--pf-global--palette--gold-500)' }}
component="small"
>
<ExclamationTriangleIcon /> After the update is installed, the device
will apply the changes.
</Text>
</TextContent>
);
const Description = () => (
<TextContent>
<Text>
Update{' '}
<span className="pf-u-font-weight-bold pf-u-font-size-md">
{isMultiple ? `${deviceName.length} systems` : deviceName}
</span>{' '}
to latest version of the image linked to it.
</Text>
</TextContent>
);
const updateToDetails = {
title: `Update to version ${imageData?.image.Version}`,
rows: [
{ title: 'Image Name', value: imageData?.image.Name },
{ title: 'Version', value: imageData?.image.Version },
{
title: 'Created',
value: <DateFormat date={imageData?.image.CreatedAt} />,
},
{
title: 'Release',
value: distributionMapper[imageData?.image.Distribution],
},
],
};
const packageDetails = {
title: `Changes from version ${imageData?.image.Version - 1}`,
rows: [
{ title: 'Added', value: imageData?.update_added || 0 },
{ title: 'Removed', value: imageData?.update_removed || 0 },
{ title: 'Updated', value: imageData?.update_updated || 0 },
],
};
const updateSchema = {
fields: [
{
component: componentTypes.PLAIN_TEXT,
name: 'description',
label: Description(),
},
{
component: componentTypes.PLAIN_TEXT,
name: 'update-details',
label: BuildModalReview({
reviewObject: updateToDetails,
key: 'update-details',
}),
},
{
component: componentTypes.PLAIN_TEXT,
name: 'package-details',
label: BuildModalReview({
reviewObject: packageDetails,
key: 'package-details',
}),
},
{
component: componentTypes.PLAIN_TEXT,
name: 'warning-text',
label: WarningText(),
},
],
};
return (
<>
{imageData ? (
<Modal
size="medium"
title={`Update system${
isMultiple ? 's' : ''
} to latest image version`}
isOpen={updateModal.isOpen}
openModal={() =>
setUpdateModal((prevState) => ({ ...prevState, isOpen: false }))
}
submitLabel="Update Device"
schema={updateSchema}
onSubmit={handleUpdateModal}
reloadData={refreshTable}
/>
) : (
<Backdrop>
<Bullseye>
<Spinner isSVG diameter="100px" />
</Bullseye>
</Backdrop>
)}
</>
);
}
Example #4
Source File: UpdateImageWizard.js From edge-frontend with Apache License 2.0 | 4 votes |
UpdateImage = ({ navigateBack, updateImageID, reload }) => {
const [user, setUser] = useState();
const dispatch = useDispatch();
const closeAction = () => {
navigateBack();
reload && reload();
};
const customRepoFlag = useFeatureFlags('fleet-management.custom-repos');
const temporaryReleasesFlag = useFeatureFlags(
'fleet-management.temporary-releases'
);
const { getRegistry } = useContext(RegistryContext);
const { data } = useSelector(
({ imageDetailReducer }) => ({
data: imageDetailReducer?.data || null,
}),
shallowEqual
);
useEffect(() => {
const registered = getRegistry().register({
imageDetailReducer,
});
updateImageID && loadImageDetail(dispatch, updateImageID);
return () => registered();
}, [dispatch]);
useEffect(() => {
(async () => {
insights?.chrome?.auth
?.getUser()
.then((result) => setUser(result != undefined ? result : {}));
})();
}, []);
return user && data ? (
<ImageCreator
onClose={closeAction}
customComponentMapper={{
review: ReviewStep,
}}
onSubmit={({ values, setIsSaving }) => {
setIsSaving(() => true);
const payload = {
...values,
Id: data?.image?.ID,
name: data?.image?.Name,
version: data?.image?.Version + 1,
architecture: 'x86_64',
credentials: values.credentials
? values.credentials
: data?.image?.Installer.SshKey,
username: values.username
? values.username
: data?.image?.Installer.Username,
};
createNewImage(dispatch, payload, (resp) => {
dispatch({
...addNotification({
variant: 'info',
title: 'Update image',
description: `${resp.value.Name} image was added to the queue.`,
}),
meta: {
polling: {
id: `FETCH_IMAGE_${resp.value.ID}_BUILD_STATUS`,
fetcher: () => getEdgeImageStatus(resp.value.ID),
condition: (resp) => {
switch (resp.Status) {
case 'BUILDING':
return [true, ''];
case 'ERROR':
return [false, 'failure'];
default:
return [false, 'success'];
}
},
onEvent: {
failure: [
(dispatch) =>
dispatch(
addNotification({
variant: 'danger',
title: 'Image build failed',
description: `${resp.value.Name} image build is completed unsuccessfully`,
})
),
],
success: [
(dispatch) =>
dispatch(
addNotification({
variant: 'success',
title: 'Image is ready',
description: `${resp.value.Name} image build is completed`,
})
),
],
},
},
},
});
closeAction();
dispatch(
addImageToPoll({ name: data.value.Name, id: data.value.ID })
);
});
}}
defaultArch="x86_64"
initialValues={{
imageID: data?.image.ID,
name: data?.image?.Name,
isUpdate: true,
description: data?.image?.Description,
credentials: data?.image?.Installer.SshKey,
username: data?.image?.Installer.Username,
version: data?.image?.Version,
release: data?.image?.Distribution,
release_options: temporaryReleasesFlag
? getReleases(data?.image?.Distribution, [
...supportedReleases,
...temporaryReleases,
])
: getReleases(data?.image?.Distribution),
imageType: ['rhel-edge-commit'],
includesCustomRepos: customRepoFlag,
'selected-packages': data?.image?.Packages?.map((pkg) => ({
...pkg,
name: pkg.Name,
})),
'third-party-repositories': data?.image?.ThirdPartyRepositories?.map(
(repo) => ({
id: repo.ID,
name: repo.Name,
...repo,
})
),
'initial-custom-repositories': data?.image?.ThirdPartyRepositories?.map(
(repo) => ({
id: repo.ID,
name: repo.Name,
...repo,
})
),
'custom-packages': data?.image?.CustomPackages?.map((pkg) => ({
...pkg,
name: pkg.Name,
})),
}}
test=""
schema={{
fields: [
{
component: componentTypes.WIZARD,
name: 'image-builder-wizard',
className: 'image-builder',
isDynamic: true,
inModal: true,
buttonLabels: {
submit: 'Create image',
},
showTitles: true,
title: `Update image: ${data?.image?.Name}`,
crossroads: [
'target-environment',
'release',
'imageType',
'third-party-repositories',
],
// order in this array does not reflect order in wizard nav, this order is managed inside
// of each step by `nextStep` property!
fields: [
updateDetails,
imageOutput,
registration,
repositories,
packages,
repositories,
review,
customPackages,
],
},
],
}}
/>
) : (
<Backdrop>
<Bullseye>
<Spinner isSVG diameter="100px" />
</Bullseye>
</Backdrop>
);
}