Skip to content

Commit

Permalink
Feat UI ddm integration (#17885)
Browse files Browse the repository at this point in the history
relate to #17416

update to uploading, downloading, and deleting ddm profiles.

- [x] Manual QA for all new/changed functionality
  • Loading branch information
ghernandez345 committed Mar 27, 2024
1 parent 0be9f08 commit 88b6ac9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
Expand Up @@ -53,6 +53,21 @@ const ProfileDetails = ({
);
};

const createProfileExtension = (profile: IMdmProfile) => {
if (isDDMProfile(profile)) {
return "json";
}
return profile.platform === "darwin" ? "mobileconfig" : "xml";
};

const createFileContent = async (profile: IMdmProfile) => {
const content = await mdmAPI.downloadProfile(profile.profile_uuid);
if (isDDMProfile(profile)) {
return JSON.stringify(content, null, 2);
}
return content;
};

interface IProfileListItemProps {
isPremium: boolean;
profile: IMdmProfile;
Expand All @@ -68,13 +83,13 @@ const ProfileListItem = ({
onDelete,
setProfileLabelsModalData,
}: IProfileListItemProps) => {
const { created_at, labels, name, platform, profile_uuid } = profile;
const { created_at, labels, name, platform } = profile;
const subClass = "list-item";

const onClickDownload = async () => {
const fileContent = await mdmAPI.downloadProfile(profile_uuid);
const fileContent = await createFileContent(profile);
const formatDate = format(new Date(), "yyyy-MM-dd");
const extension = platform === "darwin" ? "mobileconfig" : "xml";
const extension = createProfileExtension(profile);
const filename = `${formatDate}_${name}.${extension}`;
const file = new File([fileContent], filename);
FileSaver.saveAs(file);
Expand Down
Expand Up @@ -52,7 +52,7 @@ const FileChooser = ({
</label>
</Button>
<input
accept=".mobileconfig,application/x-apple-aspen-config,.xml"
accept=".json,.mobileconfig,application/x-apple-aspen-config,.xml"
id="upload-profile"
type="file"
onChange={(e) => {
Expand Down
Expand Up @@ -78,6 +78,9 @@ export const parseFile = async (file: File): Promise<[string, string]> => {
// }
return [name, "macOS"];
}
case "json": {
return [name, "macOS"];
}
default: {
throw new Error(`Invalid file type: ${ext}`);
}
Expand Down
24 changes: 0 additions & 24 deletions frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx
Expand Up @@ -753,30 +753,6 @@ const HostDetailsPage = ({
name: host?.mdm.macos_setup?.bootstrap_package_name,
};

// TODO: Remove this when API is ready
if (!host.mdm.profiles) {
host.mdm.profiles = [];
} else {
host.mdm.profiles = [
createMockHostMdmProfile({
name: "test.json",
status: "success",
}),
createMockHostMdmProfile({
name: "test2.json",
status: "pending",
}),
createMockHostMdmProfile({
name: "test3.json",
status: "failed",
}),
createMockHostMdmProfile({
name: "test4.json",
status: "acknowledged",
}),
];
}

return (
<MainContent className={baseClass}>
<>
Expand Down

0 comments on commit 88b6ac9

Please sign in to comment.