feat(admin): add view configuration client infrastructure (#13186)

This is part of stacked PRs to add a view configuration feature which will allow users to customize the columns seen in tables in the Medusa Admin dashboard.

**What**
- Adds client providers, sdk methods and hooks for interacting with the views api.
This commit is contained in:
Sebastian Rindom
2025-09-01 09:20:37 +00:00
committed by GitHub
parent 72675c59ec
commit fa10c78ed3
6 changed files with 446 additions and 1 deletions
+6
View File
@@ -42,6 +42,7 @@ import { TaxRate } from "./tax-rate"
import { TaxRegion } from "./tax-region"
import { Upload } from "./upload"
import { User } from "./user"
import { Views } from "./views"
import { WorkflowExecution } from "./workflow-execution"
import { ShippingOptionType } from "./shipping-option-type"
@@ -226,6 +227,10 @@ export class Admin {
* @tags plugin
*/
public plugin: Plugin
/**
* @tags views
*/
public views: Views
constructor(client: Client) {
this.invite = new Invite(client)
@@ -273,5 +278,6 @@ export class Admin {
this.campaign = new Campaign(client)
this.plugin = new Plugin(client)
this.taxProvider = new TaxProvider(client)
this.views = new Views(client)
}
}
+125
View File
@@ -0,0 +1,125 @@
import { HttpTypes, SelectParams } from "@medusajs/types"
import { Client } from "../client"
import { ClientHeaders } from "../types"
export class Views {
constructor(private client: Client) {}
// Generic method to get columns for any entity
async columns(
entity: string,
query?: SelectParams,
headers?: ClientHeaders
): Promise<HttpTypes.AdminViewsEntityColumnsResponse> {
return await this.client.fetch(`/admin/views/${entity}/columns`, {
method: "GET",
headers,
query,
})
}
// View configurations
async listConfigurations(
entity: string,
query?: HttpTypes.AdminGetViewConfigurationsParams,
headers?: ClientHeaders
): Promise<HttpTypes.AdminViewConfigurationListResponse> {
return await this.client.fetch(`/admin/views/${entity}/configurations`, {
method: "GET",
headers,
query,
})
}
async createConfiguration(
entity: string,
body: HttpTypes.AdminCreateViewConfiguration,
headers?: ClientHeaders
): Promise<HttpTypes.AdminViewConfigurationResponse> {
return await this.client.fetch(`/admin/views/${entity}/configurations`, {
method: "POST",
headers,
body,
})
}
async retrieveConfiguration(
entity: string,
id: string,
query?: SelectParams,
headers?: ClientHeaders
): Promise<HttpTypes.AdminViewConfigurationResponse> {
return await this.client.fetch(
`/admin/views/${entity}/configurations/${id}`,
{
method: "GET",
headers,
query,
}
)
}
async updateConfiguration(
entity: string,
id: string,
body: HttpTypes.AdminUpdateViewConfiguration,
headers?: ClientHeaders
): Promise<HttpTypes.AdminViewConfigurationResponse> {
return await this.client.fetch(
`/admin/views/${entity}/configurations/${id}`,
{
method: "POST",
headers,
body,
}
)
}
async deleteConfiguration(
entity: string,
id: string,
headers?: ClientHeaders
): Promise<HttpTypes.AdminViewConfigurationDeleteResponse> {
return await this.client.fetch(
`/admin/views/${entity}/configurations/${id}`,
{
method: "DELETE",
headers,
}
)
}
async retrieveActiveConfiguration(
entity: string,
headers?: ClientHeaders
): Promise<
HttpTypes.AdminViewConfigurationResponse & {
active_view_configuration_id?: string | null
}
> {
return await this.client.fetch(
`/admin/views/${entity}/configurations/active`,
{
method: "GET",
headers,
}
)
}
async setActiveConfiguration(
entity: string,
body: { view_configuration_id: string | null },
headers?: ClientHeaders
): Promise<{ success: boolean }> {
return await this.client.fetch(
`/admin/views/${entity}/configurations/active`,
{
method: "POST",
headers,
body,
}
)
}
}