Repository navigation
release: @makeplane/plane-node-sdk 0.3.2 #69
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
Merged
+1,894
−22
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9e94afd
fix: name the field errors in a v2 error's message (#67)
akhil-vamshi-konam 0c15c79
[PAI-2083] feat: dashboards and dashboard widgets on the v2 client (#61)
gurusainath baf10f0
feat: change a workspace member's role (v1 and v2) (#66)
akhil-vamshi-konam 0ff5b35
[PAI-2161] feat(v2): work item subscribers (#70)
akhil-vamshi-konam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,202 @@ | ||
| import { Page } from "../../../models/v2/common"; | ||
| import { | ||
| CreateWidget, | ||
| StoredWidgetChartType, | ||
| UpdateWidget, | ||
| Widget, | ||
| WidgetChart, | ||
| WidgetChartModel, | ||
| WidgetChartParams, | ||
| WidgetChartResult, | ||
| } from "../../../models/v2/Widget"; | ||
| import { FIELDS, ORDER_BY } from "../generated/constants"; | ||
| import { AnyOperationId, V2Resource } from "../kernel/resource"; | ||
|
|
||
| export type WidgetField = (typeof FIELDS)["widgets_list"][number]; | ||
| export type WidgetOrderBy = (typeof ORDER_BY)["widgets_list"][number]; | ||
|
|
||
| export interface ListWidgetsParams { | ||
| fields?: readonly WidgetField[]; | ||
| chart_type?: StoredWidgetChartType; | ||
| chart_model?: WidgetChartModel; | ||
| /** Match on name. */ | ||
| search?: string; | ||
| order_by?: WidgetOrderBy; | ||
| offset?: number; | ||
| per_page?: number; | ||
| /** Set to `"cursor"` to opt into the cursor envelope — see `ListStatesParams.paginate`. */ | ||
| paginate?: "cursor"; | ||
| /** Resume a cursor-paginated walk from a `next_cursor` an earlier page answered with. */ | ||
| cursor?: string; | ||
| count?: boolean; | ||
| } | ||
|
|
||
| /** `?fields=` on a single-row read or write. The golden declares no `?expand=` on this family. */ | ||
| export interface WidgetShapeParams { | ||
| fields?: readonly WidgetField[]; | ||
| } | ||
|
|
||
| /** Query parameters of {@link Widgets.charts}. */ | ||
| export interface WidgetChartsParams { | ||
| /** | ||
| * Only these widgets (sent comma-separated). Ids not on the dashboard are skipped. Omit it | ||
| * for every widget; an empty array resolves to `[]` without a request. | ||
| */ | ||
| widget_ids?: readonly string[]; | ||
| } | ||
|
|
||
| /** | ||
| * The widgets on a dashboard — CRUD plus their chart data. | ||
| * | ||
| * Reached flat — `v2.workspaces.dashboards.widgets.list(slug, dashboard)` — or from a | ||
| * fetched dashboard: `dashboard.widgets.list()`. A widget row holds its settings only; the | ||
| * data it draws comes from {@link chart} (one widget, pageable) or {@link charts} (every | ||
| * widget at its first page, in layout order). | ||
| */ | ||
| export class Widgets extends V2Resource<Widget, CreateWidget, UpdateWidget> { | ||
| protected path = "/workspaces/{slug}/dashboards/{dashboard_id}/widgets/"; | ||
| protected extraPaths = { | ||
| chart: "/workspaces/{slug}/dashboards/{dashboard_id}/widgets/{widget_id}/chart/", | ||
| charts: "/workspaces/{slug}/dashboards/{dashboard_id}/widgets/charts/", | ||
| }; | ||
| protected operations: Record<string, AnyOperationId> = { | ||
| list: "widgets_list", | ||
| retrieve: "widgets_retrieve", | ||
| create: "widgets_create", | ||
| update: "widgets_partial_update", | ||
| delete: "widgets_destroy", | ||
| chart: "widgets_chart", | ||
| charts: "widgets_charts", | ||
| }; | ||
|
|
||
| private _at(slug: string, dashboard: string, widget?: string): Record<string, string> { | ||
| const params: Record<string, string> = { slug, dashboard_id: dashboard }; | ||
| if (widget !== undefined) params.pk = widget; | ||
| return params; | ||
| } | ||
|
|
||
| /** | ||
| * One page of `Widget` rows. Use `iterate` to follow pages automatically. | ||
| * | ||
| * @remarks The row shape returned when `fields` is a literal tuple. `id` is always present. | ||
| */ | ||
| list<F extends Exclude<WidgetField, "all"> & keyof Widget>( | ||
| slug: string, | ||
| dashboard: string, | ||
| params: ListWidgetsParams & { fields: readonly F[] } | ||
| ): Promise<Page<Pick<Widget, F | "id">>>; | ||
| /** One page of `Widget` rows. Use `iterate` to follow pages automatically. */ | ||
| list(slug: string, dashboard: string, params?: ListWidgetsParams): Promise<Page<Widget>>; | ||
| list(slug: string, dashboard: string, params?: ListWidgetsParams): Promise<Page<Widget>> { | ||
| return this.doList(this._at(slug, dashboard), params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** Every widget on the dashboard, following pages automatically. */ | ||
| iterate<F extends Exclude<WidgetField, "all"> & keyof Widget>( | ||
| slug: string, | ||
| dashboard: string, | ||
| params: Omit<ListWidgetsParams, "offset" | "count"> & { fields: readonly F[] } | ||
| ): AsyncGenerator<Pick<Widget, F | "id">>; | ||
| /** Every widget on the dashboard, following pages automatically. */ | ||
| iterate( | ||
| slug: string, | ||
| dashboard: string, | ||
| params?: Omit<ListWidgetsParams, "offset" | "count"> | ||
| ): AsyncGenerator<Widget>; | ||
| iterate( | ||
| slug: string, | ||
| dashboard: string, | ||
| params?: Omit<ListWidgetsParams, "offset" | "count"> | ||
| ): AsyncGenerator<Widget> { | ||
| return this.doIterate(this._at(slug, dashboard), params as Record<string, unknown>); | ||
| } | ||
|
|
||
| retrieve<F extends Exclude<WidgetField, "all"> & keyof Widget>( | ||
| slug: string, | ||
| dashboard: string, | ||
| widget: string, | ||
| params: { fields: readonly F[] } | ||
| ): Promise<Pick<Widget, F | "id">>; | ||
| retrieve(slug: string, dashboard: string, widget: string, params?: WidgetShapeParams): Promise<Widget>; | ||
| retrieve(slug: string, dashboard: string, widget: string, params?: WidgetShapeParams): Promise<Widget> { | ||
| return this.doRetrieve(this._at(slug, dashboard, widget), params as Record<string, unknown>); | ||
| } | ||
|
|
||
| /** Add a widget. The API checks it against its chart type first and refuses (400) one it could not draw. */ | ||
| create<F extends Exclude<WidgetField, "all"> & keyof Widget>( | ||
| slug: string, | ||
| dashboard: string, | ||
| data: CreateWidget, | ||
| params: WidgetShapeParams & { fields: readonly F[] } | ||
| ): Promise<Pick<Widget, F | "id">>; | ||
| /** Add a widget. The API checks it against its chart type first and refuses (400) one it could not draw. */ | ||
| create(slug: string, dashboard: string, data: CreateWidget, params?: WidgetShapeParams): Promise<Widget>; | ||
| create(slug: string, dashboard: string, data: CreateWidget, params?: WidgetShapeParams): Promise<Widget> { | ||
| return this.doCreate(data, this._at(slug, dashboard), params as Record<string, unknown>); | ||
| } | ||
|
|
||
| update<F extends Exclude<WidgetField, "all"> & keyof Widget>( | ||
| slug: string, | ||
| dashboard: string, | ||
| widget: string, | ||
| data: UpdateWidget, | ||
| params: WidgetShapeParams & { fields: readonly F[] } | ||
| ): Promise<Pick<Widget, F | "id">>; | ||
| update( | ||
| slug: string, | ||
| dashboard: string, | ||
| widget: string, | ||
| data: UpdateWidget, | ||
| params?: WidgetShapeParams | ||
| ): Promise<Widget>; | ||
| update( | ||
| slug: string, | ||
| dashboard: string, | ||
| widget: string, | ||
| data: UpdateWidget, | ||
| params?: WidgetShapeParams | ||
| ): Promise<Widget> { | ||
| return this.doUpdate(data, this._at(slug, dashboard, widget), params as Record<string, unknown>); | ||
| } | ||
|
|
||
| delete(slug: string, dashboard: string, widget: string): Promise<void> { | ||
| return this.doDelete(this._at(slug, dashboard, widget)); | ||
| } | ||
|
|
||
| /** | ||
| * The data one widget draws, computed from the dashboard's current work items with both | ||
| * the dashboard's and the widget's filters applied. The widget filter is its `filters` when | ||
| * `last_used_filter` is `rich_filters` (the default) and `pql_filters.stripped` when it is | ||
| * `pql_filters`; `rich_filters` is never read. The shape depends on the widget's | ||
| * `chart_type`. `row_ids` is sent as the JSON array the API expects. | ||
| */ | ||
| chart(slug: string, dashboard: string, widget: string, params?: WidgetChartParams): Promise<WidgetChart> { | ||
| const { row_ids, ...rest } = params ?? {}; | ||
| return this.doCustomAction<WidgetChart>("chart", { | ||
| method: "GET", | ||
| pathParams: { slug, dashboard_id: dashboard, widget_id: widget }, | ||
| params: { ...rest, row_ids: row_ids === undefined ? undefined : JSON.stringify(row_ids) }, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Every widget's chart data in one call, in layout order, each at its first page, with the | ||
| * same filters as {@link chart}. Resolves to the response's `data` array: one entry per | ||
| * widget, each carrying its own `status` and either `chart` or `error`. A widget that | ||
| * cannot be charted (400, 402, 500) fails only its own entry; the call itself still rejects | ||
| * for anything about the dashboard (401/403, 404 for a dashboard the caller cannot see, | ||
| * 402 when the plan has no dashboards, 400 when more than 50 widgets are selected: pass | ||
| * `widget_ids` to chart a larger dashboard in batches). An empty `widget_ids` resolves to `[]` | ||
| * without a request. | ||
| */ | ||
| async charts(slug: string, dashboard: string, params?: WidgetChartsParams): Promise<WidgetChartResult[]> { | ||
| // `?widget_ids=` with nothing after it is an empty selection, so skip the round trip. | ||
| if (params?.widget_ids !== undefined && params.widget_ids.length === 0) return []; | ||
| const response = await this.doCustomAction<{ data: WidgetChartResult[] }>("charts", { | ||
| method: "GET", | ||
| pathParams: { slug, dashboard_id: dashboard }, | ||
| params: params as Record<string, unknown>, | ||
| }); | ||
| return response.data; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.