Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat UI ddm integration #17885

Merged
merged 2 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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