Skip to content

chore: fix type errors#311

Merged
kmendell merged 5 commits into1.0.0from
chore/fix-type-errors
Jun 21, 2025
Merged

chore: fix type errors#311
kmendell merged 5 commits into1.0.0from
chore/fix-type-errors

Conversation

@kmendell
Copy link
Member

@kmendell kmendell commented Jun 21, 2025

Summary by CodeRabbit

  • New Features
    • Added the ability to download remote templates and save them locally via the user interface.
    • Sidebar improvements: Environments now have a dedicated section with clearer labeling and updated icons.
  • Enhancements
    • Improved environment switching with updated dropdown labeling and clearer display of Docker socket paths.
    • More precise type definitions and API responses for user, environment, and OIDC-related services.
    • Service and network details on stack and image pages now display more accurate and detailed information.
  • Bug Fixes
    • Fixed label and architecture/OS display for images, ensuring correct data sources are used.
  • Refactor
    • Cleaned up and unified state management and conditional logic in several settings and security pages.
    • Removed legacy or redundant code and comments for improved maintainability.
  • Style
    • Updated sidebar and environment switcher icons for better clarity.
  • Documentation
    • Improved type documentation and interface definitions for better developer clarity.
  • Chores
    • Removed page title blocks from several pages to streamline document title management.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

📝 Walkthrough

Walkthrough

This update introduces a new backend API route and handler for downloading remote templates, along with corresponding frontend integration. It also refactors and improves type safety in several frontend services and components, updates UI logic for environment and settings management, and streamlines state handling and page metadata across multiple Svelte pages.

Changes

Files / Areas Change Summary
backend/internal/api/routes.go, template_handler.go, services/template_service.go Added POST /templates/:id/download route, handler method DownloadTemplate in handler and service to support downloading remote templates as local ones.
frontend/src/lib/services/api/template-api-service.ts Added download(id) method to call new backend route; removed legacy comments.
frontend/src/lib/components/dialogs/template-selection-dialog.svelte Simplified download result check and error toast message.
frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte, sidebar.svelte Updated environment icon and text logic; separated "Environments" from "Settings" in sidebar; replaced agent switcher with environment switcher.
frontend/src/lib/models/stack.type.ts Added NetworkSettings interface; extended StackService with optional networkSettings.
frontend/src/lib/services/api/environment-api-service.ts Improved type specificity for container/stack stats methods; updated method signatures and response casting.
frontend/src/lib/services/api/oidc-api-service.ts Inlined OidcUserInfo interface; removed external import.
frontend/src/lib/services/api/settings-api-service.ts Removed all OIDC config/user methods except getOidcStatus; updated types and imports accordingly.
frontend/src/lib/services/api/user-api-service.ts Added UsersResponse interface; all methods now explicitly cast API responses to expected types.
frontend/src/lib/stores/environment.store.ts Made setEnvironment async; triggers navigation invalidation on environment change.
frontend/src/lib/types/settings.type.ts Updated/added interfaces: OidcStatusInfo, RegistryCredential, TemplateRegistryConfig; changed types for several fields; removed unused interfaces.
frontend/src/routes/+page.svelte Added type assertion for imagePruneMode prop.
frontend/src/routes/compose/[composeId]/+page.svelte Refined service/port URL logic; simplified network settings null check.
frontend/src/routes/environments/+page.svelte, [id]/+page.svelte, settings/general/+page.svelte, settings/rbac/+page.svelte, settings/users/+page.svelte, settings/docker/+page.svelte, settings/security/+page.svelte Removed <svelte:head> blocks setting page titles.
frontend/src/routes/images/[imageId]/+page.svelte Refactored image property extraction; improved safety and accuracy for displayed data.
frontend/src/routes/onboarding/settings/+page.svelte Removed Docker Host configuration from onboarding; changed timestamp to numeric.
frontend/src/routes/settings/+layout.svelte Removed unused pageTitle variable.
frontend/src/routes/settings/docker/+page.svelte Changed import path for FormInput; simplified input state initialization; removed page title head block.
frontend/src/routes/settings/security/+page.svelte Consolidated OIDC state management; simplified conditionals; removed legacy UI and page title.
frontend/src/routes/volumes/+page.ts Added CreatedAt property to EnhancedVolumeInfo type.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f34166b and ea03579.

📒 Files selected for processing (27)
  • backend/internal/api/routes.go (1 hunks)
  • backend/internal/api/template_handler.go (1 hunks)
  • backend/internal/services/template_service.go (1 hunks)
  • frontend/src/lib/components/dialogs/template-selection-dialog.svelte (1 hunks)
  • frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte (4 hunks)
  • frontend/src/lib/components/sidebar/sidebar.svelte (4 hunks)
  • frontend/src/lib/models/stack.type.ts (2 hunks)
  • frontend/src/lib/services/api/environment-api-service.ts (3 hunks)
  • frontend/src/lib/services/api/oidc-api-service.ts (1 hunks)
  • frontend/src/lib/services/api/settings-api-service.ts (2 hunks)
  • frontend/src/lib/services/api/template-api-service.ts (1 hunks)
  • frontend/src/lib/services/api/user-api-service.ts (1 hunks)
  • frontend/src/lib/stores/environment.store.ts (3 hunks)
  • frontend/src/lib/types/settings.type.ts (2 hunks)
  • frontend/src/routes/+page.svelte (1 hunks)
  • frontend/src/routes/compose/[composeId]/+page.svelte (2 hunks)
  • frontend/src/routes/environments/+page.svelte (0 hunks)
  • frontend/src/routes/environments/[id]/+page.svelte (0 hunks)
  • frontend/src/routes/images/[imageId]/+page.svelte (4 hunks)
  • frontend/src/routes/onboarding/settings/+page.svelte (1 hunks)
  • frontend/src/routes/settings/+layout.svelte (0 hunks)
  • frontend/src/routes/settings/docker/+page.svelte (2 hunks)
  • frontend/src/routes/settings/general/+page.svelte (0 hunks)
  • frontend/src/routes/settings/rbac/+page.svelte (0 hunks)
  • frontend/src/routes/settings/security/+page.svelte (4 hunks)
  • frontend/src/routes/settings/users/+page.svelte (0 hunks)
  • frontend/src/routes/volumes/+page.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • frontend/src/routes/environments/[id]/+page.svelte
  • frontend/src/routes/environments/+page.svelte
  • frontend/src/routes/settings/rbac/+page.svelte
  • frontend/src/routes/settings/users/+page.svelte
  • frontend/src/routes/settings/+layout.svelte
  • frontend/src/routes/settings/general/+page.svelte
🔇 Additional comments (40)
frontend/src/routes/settings/docker/+page.svelte (2)

3-3: Verify the type definition exists at the new import path.

The import path for FormInputType was changed from $lib/types/form.type to $lib/utils/form.utils. Ensure this type definition exists at the new location and maintains compatibility.

#!/bin/bash
# Description: Verify the FormInput type exists at the new location and check for any remaining references to the old path.

# Check if the type exists at the new location
echo "Checking for FormInput type in form.utils:"
fd "form.utils" --type f | xargs rg -l "FormInput" 2>/dev/null || echo "No FormInput found in form.utils files"

# Check for any remaining imports from the old path
echo -e "\nChecking for remaining imports from old path:"
rg "from.*form\.type" --type ts --type js --type svelte

# Check the actual type definition
echo -e "\nFormInput type definition:"
rg -A 10 -B 2 "export.*FormInput" frontend/src/lib/utils/ 2>/dev/null || echo "Type definition not found"

51-69: To confirm the shape of FormInput in your utils (and whether it still expects valid, touched, or errors), let’s locate and dump its definition:

#!/bin/bash
# 1. Find the utils file that defines FormInput
utils_file=$(fd -g "form.utils.*" -t f frontend/src)
echo "▶️ Found: $utils_file"

# 2. Show lines around any FormInput export
echo -e "\n🔍 Exported FormInput definition:"
rg -n "export .*FormInput" -C5 "$utils_file" || echo "(no direct export found)"

# 3. Show the first 200 lines of the file for context
echo -e "\n📄 Top of $utils_file:"
head -n 200 "$utils_file"
frontend/src/lib/models/stack.type.ts (2)

18-27: Well-structured NetworkSettings interface.

The new NetworkSettings interface follows TypeScript best practices with proper typing for network configurations. The use of Record<string, {...}> provides type safety while the index signature [key: string]: any allows for extensibility.


40-40: Good integration of network settings into StackService.

The optional networkSettings property is properly typed and maintains backward compatibility. This aligns well with the frontend usage patterns shown in the compose page component.

frontend/src/routes/compose/[composeId]/+page.svelte (2)

93-93: Improved null safety with optional chaining.

The change from explicit null checking to optional chaining (service?.networkSettings?.Networks) is a good improvement that makes the code more concise and follows modern JavaScript/TypeScript patterns.


297-298: ```shell
#!/bin/bash

Search for StackService type or interface definitions in .ts files

rg -n "StackService" -g "*.ts" -A 5 -B 5


</details>
<details>
<summary>frontend/src/routes/volumes/+page.ts (1)</summary>

`7-7`: ```shell
#!/bin/bash
# Display the environment API service to inspect getVolumes implementation
echo "=== Contents of environment-api-service.ts ==="
sed -n '1,200p' frontend/src/lib/services/api/environment-api-service.ts

echo "=== getVolumes method details ==="
grep -R -n "getVolumes" -C 5 frontend/src/lib/services/api/environment-api-service.ts
frontend/src/lib/components/dialogs/template-selection-dialog.svelte (1)

70-73: Verify API response structure for download functionality.

The change from result.success to just result suggests a modification in the API response structure. This could be problematic if the API returns falsy values on success or if the response format changed.

#!/bin/bash
# Description: Check the template API service download method implementation
# Expected: Find the download method and verify what it returns

# Find the template API service implementation
fd "template.*api.*service" --type f --exec cat {}

# Search for download method specifically
ast-grep --pattern $'download($$$) {
  $$$
}'

# Also check the backend handler to understand response format
ast-grep --pattern $'DownloadTemplate($$$) {
  $$$
}'
backend/internal/api/routes.go (1)

331-331: Well-structured route addition.

The new download template route follows RESTful conventions and is properly placed within the authenticated template group. The endpoint pattern /:id/download is consistent with other action-based routes in the codebase.

frontend/src/routes/+page.svelte (1)

714-714: LGTM! Type assertion correctly enforces strict typing.

The explicit type assertion ensures compatibility with the PruneConfirmationDialog component's expected prop type, addressing the type safety requirements mentioned in the PR objectives.

frontend/src/lib/components/sidebar/sidebar.svelte (2)

14-14: LGTM! Logical separation of environments from settings.

Moving the "Environments" item from the settings group to its own dedicated group improves the sidebar organization and makes environment management more prominent.

Also applies to: 30-36


51-51: LGTM! Consistent component updates for environment switcher.

The changes properly replace the agent switcher with the environment switcher and add the corresponding sidebar group. The import and usage are correctly aligned.

Also applies to: 79-79, 84-84

frontend/src/lib/components/sidebar/sidebar-env-switcher.svelte (3)

4-4: LGTM! Improved UX with conditional environment label.

Adding the "Environment" label when the sidebar is open provides better context for users, improving the overall user experience.

Also applies to: 43-45


8-8: LGTM! More semantically appropriate icon choice.

Replacing GalleryVerticalEndIcon with GlobeIcon for non-local environments is more intuitive and semantically correct for representing remote/network environments.

Also applies to: 56-56, 96-96


64-64: LGTM! More informative local environment labeling.

Showing the explicit socket path "unix:///var/run/docker.sock" instead of "Local Docker" provides users with clearer technical information about the connection type.

Also applies to: 102-102

frontend/src/routes/onboarding/settings/+page.svelte (1)

37-37: LGTM! Improved timestamp format for onboarding completion.

Using Date.now() (numeric timestamp) instead of an ISO string is more efficient for storage and aligns with common JavaScript timestamp handling practices.

frontend/src/lib/services/api/oidc-api-service.ts (1)

2-2: LGTM! Well-structured local OIDC interface definition.

Moving the OidcUserInfo interface to a local definition reduces external dependencies and makes the required vs optional properties explicit. The interface correctly follows OIDC standard claims with appropriate typing.

Also applies to: 4-13

backend/internal/api/template_handler.go (1)

511-552: Well-implemented download handler with proper validation and error handling.

The DownloadTemplate handler follows established patterns in the codebase with appropriate:

  • Input validation for template ID
  • Template existence verification
  • Business logic validation (remote template check)
  • Proper HTTP status codes for different error scenarios
  • Consistent JSON response structure

The implementation correctly prevents downloading already local templates and provides clear error messages.

frontend/src/lib/stores/environment.store.ts (2)

3-3: Good addition for navigation invalidation.

Adding invalidateAll import enables proper SvelteKit navigation invalidation when environment changes.


108-122: Properly implemented async environment switching with navigation invalidation.

The async setEnvironment method correctly:

  • Checks if the environment actually changed before updating
  • Persists the selection to localStorage in browser environments
  • Triggers navigation invalidation to ensure UI components update accordingly

This follows SvelteKit best practices for handling navigation state changes.

frontend/src/lib/services/api/template-api-service.ts (1)

49-52: Clean implementation of the download API method.

The download method correctly sends a POST request to the backend endpoint and returns the downloaded template. The implementation is consistent with other API methods in the class.

frontend/src/routes/images/[imageId]/+page.svelte (4)

27-27: Good defensive programming with optional chaining.

Adding optional chaining (?.) prevents runtime errors when image.Id might be undefined and provides a sensible fallback value.


28-28: Improved timestamp handling with explicit ISO conversion.

Converting the timestamp to ISO string before formatting ensures consistent date parsing and prevents potential timezone issues.


30-31: Appropriate data structure adjustment for platform information.

Accessing platform data from image.Manifests[0].ImageData.Platform instead of top-level properties aligns with the actual data structure and includes proper fallbacks.


166-177: Consistent label data sourcing.

Switching from image.Config.Labels to image.Labels ensures consistent label data access throughout the component and aligns with the actual data structure.

frontend/src/routes/settings/security/+page.svelte (2)

19-54: Good consolidation of state management.

The refactored state declarations and effect block improve code organization by:

  • Consolidating related state variables
  • Using a single effect block for state synchronization
  • Making the component's state management more predictable

This cleanup enhances maintainability without changing functionality.


186-214: Simplified OIDC status handling with structured data.

Using data.oidcStatus properties like envForced, effectivelyEnabled, and envConfigured provides clearer, more readable conditional logic compared to complex boolean expressions. This improves code maintainability and reduces the likelihood of logic errors.

frontend/src/lib/services/api/environment-api-service.ts (3)

4-4: LGTM: Enhanced import for better type specificity.

Adding ContainerStats to the dockerode import improves type safety for container statistics operations.


42-46: LGTM: Improved type safety with explicit return type and assertion.

The explicit Promise<ContainerStats> return type and type assertion ensure proper typing for container statistics API responses.


261-264: LGTM: Consistent typing for stack statistics.

The explicit Promise<ContainerStats[]> return type and type assertion maintain consistency with the container stats method and ensure proper typing.

frontend/src/lib/services/api/user-api-service.ts (2)

11-13: LGTM: Well-defined response interface.

Adding the UsersResponse interface provides better structure for API response handling and improves type safety.


17-103: LGTM: Systematic type assertion improvements.

The explicit type assertions throughout all methods enhance type safety and resolve type compatibility issues. This follows a consistent pattern across the service methods.

backend/internal/services/template_service.go (1)

337-381: LGTM: Well-implemented template download functionality.

The DownloadTemplate method is well-structured with proper:

  • Input validation ensuring the template is remote
  • Content fetching using existing FetchTemplateContent method
  • Local template creation with appropriate field mapping
  • Metadata preservation from the remote template
  • Database persistence with error handling

The implementation follows Go best practices and integrates well with the existing codebase.

frontend/src/lib/services/api/settings-api-service.ts (2)

2-2: LGTM: Added proper type import.

Adding OidcStatusInfo to the imports improves type safety for the OIDC status method.


38-40: ```shell
#!/bin/bash

Re-run search for removed OIDC methods across all files without relying on ripgrep file types

rg -n "settingsAPI.(getOidcSettings|updateOidcSettings|resetOidcSettings|testOidcConnection)"


</details>
<details>
<summary>frontend/src/lib/types/settings.type.ts (5)</summary>

`20-27`: **LGTM: Well-structured OIDC status interface.**

The `OidcStatusInfo` interface provides comprehensive typing for OIDC configuration status with clear boolean flags for different configuration states.

---

`29-41`: **LGTM: Clean interface definitions.**

The `RegistryCredential` and `TemplateRegistryConfig` interfaces are well-defined with appropriate field types and optional properties.

---

`45-45`: **LGTM: Consistent timestamp type.**

Changing `completedAt` from `string` to `number` aligns with standard JavaScript timestamp handling using numeric values.

---

`54-70`: **LGTM: Enhanced Settings interface.**

The additions of `id`, `dockerTLSCert`, `createdAt`, and `updatedAt` fields, along with making `pruneMode` optional, improve the interface structure and align with typical database entity patterns.

---

`5-5`: **Verify the passwordPolicy type change.**

The change from specific string literals to a generic `string` type reduces type safety. Ensure this change is intentional and aligns with the actual usage patterns.


```shell
#!/bin/bash
# Search for passwordPolicy usage to understand the expected values
rg -A 5 -B 5 "passwordPolicy" --type ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@kmendell kmendell marked this pull request as ready for review June 21, 2025 17:50
@kmendell
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kmendell kmendell merged commit 08eef46 into 1.0.0 Jun 21, 2025
1 check passed
@kmendell kmendell deleted the chore/fix-type-errors branch June 21, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant