forked from podman-desktop/extension-bootc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: details page for disk images (podman-desktop#866)
* feat: details page for disk images Modifies the build logs to have a proper details page for disk images, similar to how Podman Desktop handles Images or Containers. The two tabs are Summary and Build Logs. The summary page is simple for now but could be expanded; the build logs doesn't really match what we typically have in Podman Desktop, but it fits in better here than a standalone page. Fixes podman-desktop#856. Signed-off-by: Tim deBoer <[email protected]> * chore: removing console.log, added util tests Removed unnecessary console.log debugging and added tests for Util. Signed-off-by: Tim deBoer <[email protected]> --------- Signed-off-by: Tim deBoer <[email protected]>
- Loading branch information
1 parent
40be954
commit 7b17a94
Showing
16 changed files
with
378 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
<script lang="ts"> | ||
import { router } from 'tinro'; | ||
import type { BootcBuildInfo } from '/@shared/src/models/bootc'; | ||
export let object: BootcBuildInfo; | ||
function openDetails() { | ||
router.goto(`/details/${btoa(object.id)}/summary`); | ||
} | ||
</script> | ||
|
||
<div class="text-[var(--pd-table-body-text-highlight)] overflow-hidden text-ellipsis"> | ||
{object.image}:{object.tag} | ||
</div> | ||
<button class="hover:cursor-pointer flex flex-col max-w-full" on:click={() => openDetails()}> | ||
<div class="text-[var(--pd-table-body-text-highlight)] max-w-full overflow-hidden text-ellipsis"> | ||
{object.image}:{object.tag} | ||
</div> | ||
</button> |
66 changes: 66 additions & 0 deletions
66
packages/frontend/src/lib/disk-image/DiskImageDetails.spec.ts
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,66 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
import '@testing-library/jest-dom/vitest'; | ||
|
||
import { render, screen } from '@testing-library/svelte'; | ||
import { beforeEach, expect, test, vi } from 'vitest'; | ||
import { bootcClient } from '/@/api/client'; | ||
|
||
import DiskImageDetails from './DiskImageDetails.svelte'; | ||
import type { BootcBuildInfo } from '/@shared/src/models/bootc'; | ||
import { tick } from 'svelte'; | ||
|
||
const image: BootcBuildInfo = { | ||
id: 'id1', | ||
image: 'my-image', | ||
imageId: 'image-id', | ||
tag: 'latest', | ||
engineId: 'podman', | ||
type: ['ami'], | ||
folder: '/bootc', | ||
}; | ||
|
||
vi.mock('/@/api/client', async () => { | ||
return { | ||
bootcClient: { | ||
listHistoryInfo: vi.fn(), | ||
}, | ||
rpcBrowser: { | ||
subscribe: () => { | ||
return { | ||
unsubscribe: () => {}, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test('Confirm renders disk image details', async () => { | ||
vi.mocked(bootcClient.listHistoryInfo).mockResolvedValue([image]); | ||
|
||
render(DiskImageDetails, { id: btoa(image.id) }); | ||
|
||
// allow UI time to update | ||
await tick(); | ||
|
||
expect(screen.getByText(image.image + ':' + image.tag)).toBeInTheDocument(); | ||
}); |
62 changes: 62 additions & 0 deletions
62
packages/frontend/src/lib/disk-image/DiskImageDetails.svelte
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,62 @@ | ||
<script lang="ts"> | ||
import { DetailsPage, Tab } from '@podman-desktop/ui-svelte'; | ||
import { router } from 'tinro'; | ||
import DiskImageIcon from '/@/lib/DiskImageIcon.svelte'; | ||
import DiskImageDetailsBuild from './DiskImageDetailsBuild.svelte'; | ||
import Route from '../Route.svelte'; | ||
import DiskImageDetailsSummary from './DiskImageDetailsSummary.svelte'; | ||
import { onMount } from 'svelte'; | ||
import type { BootcBuildInfo } from '/@shared/src/models/bootc'; | ||
import { getTabUrl, isTabSelected } from '../upstream/Util'; | ||
import { historyInfo } from '/@/stores/historyInfo'; | ||
export let id: string; | ||
let diskImage: BootcBuildInfo; | ||
let detailsPage: DetailsPage; | ||
onMount(() => { | ||
const actualId = atob(id); | ||
return historyInfo.subscribe(value => { | ||
const matchingImage = value.find(image => image.id === actualId); | ||
if (matchingImage) { | ||
try { | ||
diskImage = matchingImage; | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} else if (detailsPage) { | ||
// the disk image has been deleted | ||
goToHomePage(); | ||
} | ||
}); | ||
}); | ||
export function goToHomePage(): void { | ||
router.goto('/'); | ||
} | ||
</script> | ||
|
||
<DetailsPage | ||
bind:this={detailsPage} | ||
title="{diskImage?.image}:{diskImage?.tag}" | ||
breadcrumbLeftPart="Bootable Containers" | ||
breadcrumbRightPart="Disk Image Details" | ||
breadcrumbTitle="Go back to homepage" | ||
onclose={goToHomePage} | ||
onbreadcrumbClick={goToHomePage}> | ||
<DiskImageIcon slot="icon" size="30px" /> | ||
<svelte:fragment slot="tabs"> | ||
<Tab title="Summary" selected={isTabSelected($router.path, 'summary')} url={getTabUrl($router.path, 'summary')} /> | ||
<Tab title="Build Log" selected={isTabSelected($router.path, 'build')} url={getTabUrl($router.path, 'build')} /> | ||
</svelte:fragment> | ||
<svelte:fragment slot="content"> | ||
<Route path="/summary" breadcrumb="Summary"> | ||
<DiskImageDetailsSummary image={diskImage} /> | ||
</Route> | ||
<Route path="/build" breadcrumb="Build Log"> | ||
<DiskImageDetailsBuild folder={diskImage?.folder} /> | ||
</Route> | ||
</svelte:fragment> | ||
</DetailsPage> |
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
59 changes: 59 additions & 0 deletions
59
packages/frontend/src/lib/disk-image/DiskImageDetailsSummary.spec.ts
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,59 @@ | ||
/********************************************************************** | ||
* Copyright (C) 2024 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
***********************************************************************/ | ||
import '@testing-library/jest-dom/vitest'; | ||
|
||
import { render, screen } from '@testing-library/svelte'; | ||
import { beforeEach, expect, test, vi } from 'vitest'; | ||
|
||
import type { BootcBuildInfo } from '/@shared/src/models/bootc'; | ||
import DiskImageDetailsSummary from './DiskImageDetailsSummary.svelte'; | ||
|
||
const image: BootcBuildInfo = { | ||
id: 'id1', | ||
image: 'my-image', | ||
imageId: 'image-id', | ||
tag: 'latest', | ||
engineId: 'podman', | ||
type: ['ami'], | ||
folder: '/bootc', | ||
}; | ||
|
||
vi.mock('/@/api/client', async () => { | ||
return { | ||
rpcBrowser: { | ||
subscribe: () => { | ||
return { | ||
unsubscribe: () => {}, | ||
}; | ||
}, | ||
}, | ||
}; | ||
}); | ||
|
||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
test('Expect to show image summary', async () => { | ||
render(DiskImageDetailsSummary, { image: image }); | ||
|
||
expect(screen.getByText(image.image + ':' + image.tag)).toBeInTheDocument(); | ||
expect(screen.getByText(image.type[0])).toBeInTheDocument(); | ||
expect(screen.getByText(image.folder)).toBeInTheDocument(); | ||
}); |
Oops, something went wrong.