Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ type DB interface {
DeleteProjectAccessRequest(ctx context.Context, id string) error

FindBookmarks(ctx context.Context, projectID, resourceKind, resourceName, userID string) ([]*Bookmark, error)
FindBookmarksForProject(ctx context.Context, projectID, userID, afterID string, limit int) ([]*Bookmark, error)
FindBookmark(ctx context.Context, bookmarkID string) (*Bookmark, error)
FindDefaultBookmark(ctx context.Context, projectID, resourceKind, resourceName string) (*Bookmark, error)
InsertBookmark(ctx context.Context, opts *InsertBookmarkOptions) (*Bookmark, error)
Expand Down
23 changes: 23 additions & 0 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,29 @@ func (c *connection) FindBookmarks(ctx context.Context, projectID, resourceKind,
return res, nil
}

func (c *connection) FindBookmarksForProject(ctx context.Context, projectID, userID, afterID string, limit int) ([]*database.Bookmark, error) {
var res []*database.Bookmark

var err error
if afterID != "" {
err = c.getDB(ctx).SelectContext(ctx, &res, `
SELECT * FROM bookmarks
WHERE project_id = $1 AND (user_id = $2 or shared = true or "default" = true) AND id > $3
ORDER BY id LIMIT $4
`, projectID, userID, afterID, limit)
} else {
err = c.getDB(ctx).SelectContext(ctx, &res, `
SELECT * FROM bookmarks
WHERE project_id = $1 AND (user_id = $2 or shared = true or "default" = true)
ORDER BY id LIMIT $3
`, projectID, userID, limit)
}
if err != nil {
return nil, parseErr("bookmarks", err)
}
return res, nil
}

// FindBookmark returns a bookmark for given bookmark id
func (c *connection) FindBookmark(ctx context.Context, bookmarkID string) (*database.Bookmark, error) {
res := &database.Bookmark{}
Expand Down
23 changes: 21 additions & 2 deletions admin/server/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,37 @@ func (s *Server) ListBookmarks(ctx context.Context, req *adminv1.ListBookmarksRe
return nil, status.Error(codes.Unauthenticated, "not authenticated as a user")
}

bookmarks, err := s.admin.DB.FindBookmarks(ctx, req.ProjectId, req.ResourceKind, req.ResourceName, claims.OwnerID())
var bookmarks []*database.Bookmark
var err error

token, err := unmarshalPageToken(req.PageToken)
if err != nil {
return nil, err
}
pageSize := validPageSize(req.PageSize)

if req.ResourceName != "" {
bookmarks, err = s.admin.DB.FindBookmarks(ctx, req.ProjectId, req.ResourceKind, req.ResourceName, claims.OwnerID())
} else {
bookmarks, err = s.admin.DB.FindBookmarksForProject(ctx, req.ProjectId, claims.OwnerID(), token.Val, pageSize)
}
if err != nil {
return nil, err
}

nextToken := ""
if len(bookmarks) >= pageSize {
nextToken = marshalPageToken(bookmarks[len(bookmarks)-1].ID)
}

dtos := make([]*adminv1.Bookmark, len(bookmarks))
for i, bookmark := range bookmarks {
dtos[i] = bookmarkToPB(bookmark)
}

return &adminv1.ListBookmarksResponse{
Bookmarks: dtos,
Bookmarks: dtos,
NextPageToken: nextToken,
}, nil
}

Expand Down
11 changes: 11 additions & 0 deletions proto/gen/rill/admin/v1/admin.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4640,6 +4640,15 @@ paths:
in: query
required: false
type: string
- name: pageSize
in: query
required: false
type: integer
format: int64
- name: pageToken
in: query
required: false
type: string
post:
summary: CreateBookmark creates a bookmark for the given user or for all users for the dashboard
operationId: AdminService_CreateBookmark
Expand Down Expand Up @@ -5842,6 +5851,8 @@ definitions:
items:
type: object
$ref: '#/definitions/v1Bookmark'
nextPageToken:
type: string
v1ListDeploymentsResponse:
type: object
properties:
Expand Down
7,282 changes: 3,657 additions & 3,625 deletions proto/gen/rill/admin/v1/api.pb.go

Large diffs are not rendered by default.

30 changes: 29 additions & 1 deletion proto/gen/rill/admin/v1/api.pb.validate.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions proto/gen/rill/admin/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ components:
items:
$ref: '#/components/schemas/v1Bookmark'
type: array
nextPageToken:
type: string
type: object
v1ListDeploymentsResponse:
properties:
Expand Down Expand Up @@ -8134,6 +8136,15 @@ paths:
name: resourceName
schema:
type: string
- in: query
name: pageSize
schema:
format: int64
type: integer
- in: query
name: pageToken
schema:
type: string
responses:
"200":
content:
Expand Down
2 changes: 2 additions & 0 deletions proto/gen/rill/admin/v1/public.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ components:
items:
$ref: '#/components/schemas/v1Bookmark'
type: array
nextPageToken:
type: string
type: object
v1ListDeploymentsResponse:
properties:
Expand Down
5 changes: 4 additions & 1 deletion proto/rill/admin/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2640,13 +2640,16 @@ message RevokeCurrentAuthTokenResponse {
}

message ListBookmarksRequest {
string project_id = 1;
string project_id = 1 [(validate.rules).string.min_len = 1];
string resource_kind = 2;
string resource_name = 3;
uint32 page_size = 4 [(validate.rules).uint32 = {ignore_empty: true, lte: 1000}];
string page_token = 5;
}

message ListBookmarksResponse {
repeated Bookmark bookmarks = 1;
string next_page_token = 2;
}

message GetBookmarkRequest {
Expand Down
7 changes: 7 additions & 0 deletions web-admin/orval.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ export default defineConfig({
useInfiniteQueryParam: "pageToken",
},
},
AdminService_ListBookmarks: {
query: {
useQuery: true,
useInfinite: true,
useInfiniteQueryParam: "pageToken",
},
},
},
},
},
Expand Down
107 changes: 107 additions & 0 deletions web-admin/src/client/gen/default/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16371,12 +16371,119 @@ export const adminServiceListBookmarks = (
});
};

export const getAdminServiceListBookmarksInfiniteQueryKey = (
params?: AdminServiceListBookmarksParams,
) => {
return [
"infinite",
`/v1/users/bookmarks`,
...(params ? [params] : []),
] as const;
};

export const getAdminServiceListBookmarksQueryKey = (
params?: AdminServiceListBookmarksParams,
) => {
return [`/v1/users/bookmarks`, ...(params ? [params] : [])] as const;
};

export const getAdminServiceListBookmarksInfiniteQueryOptions = <
TData = InfiniteData<
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
AdminServiceListBookmarksParams["pageToken"]
>,
TError = RpcStatus,
>(
params?: AdminServiceListBookmarksParams,
options?: {
query?: Partial<
CreateInfiniteQueryOptions<
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
TError,
TData,
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
QueryKey,
AdminServiceListBookmarksParams["pageToken"]
>
>;
},
) => {
const { query: queryOptions } = options ?? {};

const queryKey =
queryOptions?.queryKey ??
getAdminServiceListBookmarksInfiniteQueryKey(params);

const queryFn: QueryFunction<
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
QueryKey,
AdminServiceListBookmarksParams["pageToken"]
> = ({ signal, pageParam }) =>
adminServiceListBookmarks(
{ ...params, pageToken: pageParam || params?.["pageToken"] },
signal,
);

return { queryKey, queryFn, ...queryOptions } as CreateInfiniteQueryOptions<
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
TError,
TData,
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
QueryKey,
AdminServiceListBookmarksParams["pageToken"]
> & { queryKey: DataTag<QueryKey, TData, TError> };
};

export type AdminServiceListBookmarksInfiniteQueryResult = NonNullable<
Awaited<ReturnType<typeof adminServiceListBookmarks>>
>;
export type AdminServiceListBookmarksInfiniteQueryError = RpcStatus;

/**
* @summary ListBookmarks lists all the bookmarks for the user and global ones for dashboard
*/

export function createAdminServiceListBookmarksInfinite<
TData = InfiniteData<
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
AdminServiceListBookmarksParams["pageToken"]
>,
TError = RpcStatus,
>(
params?: AdminServiceListBookmarksParams,
options?: {
query?: Partial<
CreateInfiniteQueryOptions<
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
TError,
TData,
Awaited<ReturnType<typeof adminServiceListBookmarks>>,
QueryKey,
AdminServiceListBookmarksParams["pageToken"]
>
>;
},
queryClient?: QueryClient,
): CreateInfiniteQueryResult<TData, TError> & {
queryKey: DataTag<QueryKey, TData, TError>;
} {
const queryOptions = getAdminServiceListBookmarksInfiniteQueryOptions(
params,
options,
);

const query = createInfiniteQuery(
queryOptions,
queryClient,
) as CreateInfiniteQueryResult<TData, TError> & {
queryKey: DataTag<QueryKey, TData, TError>;
};

query.queryKey = queryOptions.queryKey;

return query;
}

export const getAdminServiceListBookmarksQueryOptions = <
TData = Awaited<ReturnType<typeof adminServiceListBookmarks>>,
TError = RpcStatus,
Expand Down
3 changes: 3 additions & 0 deletions web-admin/src/client/gen/index.schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ export interface V1LeaveOrganizationResponse {

export interface V1ListBookmarksResponse {
bookmarks?: V1Bookmark[];
nextPageToken?: string;
}

export interface V1ListDeploymentsResponse {
Expand Down Expand Up @@ -2495,6 +2496,8 @@ export type AdminServiceListBookmarksParams = {
projectId?: string;
resourceKind?: string;
resourceName?: string;
pageSize?: number;
pageToken?: string;
};

export type AdminServiceSearchUsersParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ export function createExploreBookmarkLegacyDataTransformer(
},
);
}
//
// export function createExploreBookmarkLegacyDataTransformerV2(
// client: RuntimeClient,
// exploreName: string,
// ) {
// const validSpecQuery = createQuery(
// getExploreValidSpecQueryOptions(client, exploreNameStore),
// );
// const timeRangeQuery = createQuery(
// getMetricsViewTimeRangeFromExploreQueryOptions(client, exploreNameStore),
// );
// }

export function exploreBookmarkDataTransformer({
data,
Expand Down
Loading
Loading