feat(HMS-3687): Add blueprints exporting
This commit is contained in:
parent
d52358edde
commit
669e3c07e3
3 changed files with 47 additions and 3 deletions
|
|
@ -6,7 +6,7 @@ const config: ConfigFile = {
|
||||||
apiImport: 'emptyImageBuilderApi',
|
apiImport: 'emptyImageBuilderApi',
|
||||||
outputFile: '../../src/store/imageBuilderApi.ts',
|
outputFile: '../../src/store/imageBuilderApi.ts',
|
||||||
exportName: 'imageBuilderApi',
|
exportName: 'imageBuilderApi',
|
||||||
hooks: true,
|
hooks: { queries: true, lazyQueries: true, mutations: true },
|
||||||
filterEndpoints: [
|
filterEndpoints: [
|
||||||
'cloneCompose',
|
'cloneCompose',
|
||||||
'composeImage',
|
'composeImage',
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,12 @@ import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { selectSelectedBlueprintId } from '../../store/BlueprintSlice';
|
import { selectSelectedBlueprintId } from '../../store/BlueprintSlice';
|
||||||
import { useAppSelector } from '../../store/hooks';
|
import { useAppSelector } from '../../store/hooks';
|
||||||
|
import {
|
||||||
|
BlueprintResponse,
|
||||||
|
useLazyGetBlueprintQuery,
|
||||||
|
} from '../../store/imageBuilderApi';
|
||||||
import { resolveRelPath } from '../../Utilities/path';
|
import { resolveRelPath } from '../../Utilities/path';
|
||||||
|
import BetaLabel from '../sharedComponents/BetaLabel';
|
||||||
|
|
||||||
interface BlueprintActionsMenuProps {
|
interface BlueprintActionsMenuProps {
|
||||||
setShowDeleteModal: React.Dispatch<React.SetStateAction<boolean>>;
|
setShowDeleteModal: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
|
|
@ -27,10 +32,21 @@ export const BlueprintActionsMenu: React.FunctionComponent<
|
||||||
const onSelect = () => {
|
const onSelect = () => {
|
||||||
setShowBlueprintActionsMenu(!showBlueprintActionsMenu);
|
setShowBlueprintActionsMenu(!showBlueprintActionsMenu);
|
||||||
};
|
};
|
||||||
const selectedBlueprintId = useAppSelector(selectSelectedBlueprintId);
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const importExportFlag = useFlag('image-builder.import.enabled');
|
const importExportFlag = useFlag('image-builder.import.enabled');
|
||||||
|
|
||||||
|
const [trigger] = useLazyGetBlueprintQuery();
|
||||||
|
const selectedBlueprintId = useAppSelector(selectSelectedBlueprintId);
|
||||||
|
if (selectedBlueprintId === undefined) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const handleClick = () => {
|
||||||
|
trigger({ id: selectedBlueprintId })
|
||||||
|
.unwrap()
|
||||||
|
.then((response: BlueprintResponse) => {
|
||||||
|
handleExportBlueprint(response.name, response);
|
||||||
|
});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
ouiaId={`blueprints-dropdown`}
|
ouiaId={`blueprints-dropdown`}
|
||||||
|
|
@ -63,7 +79,9 @@ export const BlueprintActionsMenu: React.FunctionComponent<
|
||||||
Edit details
|
Edit details
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
{importExportFlag && (
|
{importExportFlag && (
|
||||||
<DropdownItem>Download blueprint (.json)</DropdownItem>
|
<DropdownItem onClick={handleClick}>
|
||||||
|
Download blueprint (.json) <BetaLabel />
|
||||||
|
</DropdownItem>
|
||||||
)}
|
)}
|
||||||
<DropdownItem onClick={() => setShowDeleteModal(true)}>
|
<DropdownItem onClick={() => setShowDeleteModal(true)}>
|
||||||
Delete blueprint
|
Delete blueprint
|
||||||
|
|
@ -72,3 +90,18 @@ export const BlueprintActionsMenu: React.FunctionComponent<
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
async function handleExportBlueprint(
|
||||||
|
blueprintName: string,
|
||||||
|
blueprint: BlueprintResponse
|
||||||
|
) {
|
||||||
|
const jsonData = JSON.stringify(blueprint, null, 2);
|
||||||
|
const blob = new Blob([jsonData], { type: 'application/json' });
|
||||||
|
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = blueprintName.replace(/\s/g, '_').toLowerCase() + '.json';
|
||||||
|
link.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -806,20 +806,31 @@ export type BlueprintResponse = {
|
||||||
};
|
};
|
||||||
export const {
|
export const {
|
||||||
useGetArchitecturesQuery,
|
useGetArchitecturesQuery,
|
||||||
|
useLazyGetArchitecturesQuery,
|
||||||
useGetComposesQuery,
|
useGetComposesQuery,
|
||||||
|
useLazyGetComposesQuery,
|
||||||
useGetComposeStatusQuery,
|
useGetComposeStatusQuery,
|
||||||
|
useLazyGetComposeStatusQuery,
|
||||||
useCloneComposeMutation,
|
useCloneComposeMutation,
|
||||||
useGetComposeClonesQuery,
|
useGetComposeClonesQuery,
|
||||||
|
useLazyGetComposeClonesQuery,
|
||||||
useGetCloneStatusQuery,
|
useGetCloneStatusQuery,
|
||||||
|
useLazyGetCloneStatusQuery,
|
||||||
useComposeImageMutation,
|
useComposeImageMutation,
|
||||||
useGetPackagesQuery,
|
useGetPackagesQuery,
|
||||||
|
useLazyGetPackagesQuery,
|
||||||
useGetOscapProfilesQuery,
|
useGetOscapProfilesQuery,
|
||||||
|
useLazyGetOscapProfilesQuery,
|
||||||
useGetOscapCustomizationsQuery,
|
useGetOscapCustomizationsQuery,
|
||||||
|
useLazyGetOscapCustomizationsQuery,
|
||||||
useGetBlueprintsQuery,
|
useGetBlueprintsQuery,
|
||||||
|
useLazyGetBlueprintsQuery,
|
||||||
useCreateBlueprintMutation,
|
useCreateBlueprintMutation,
|
||||||
useUpdateBlueprintMutation,
|
useUpdateBlueprintMutation,
|
||||||
useGetBlueprintQuery,
|
useGetBlueprintQuery,
|
||||||
|
useLazyGetBlueprintQuery,
|
||||||
useDeleteBlueprintMutation,
|
useDeleteBlueprintMutation,
|
||||||
useComposeBlueprintMutation,
|
useComposeBlueprintMutation,
|
||||||
useGetBlueprintComposesQuery,
|
useGetBlueprintComposesQuery,
|
||||||
|
useLazyGetBlueprintComposesQuery,
|
||||||
} = injectedRtkApi;
|
} = injectedRtkApi;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue