Skip to content

UpdateFragment/ ListFragments - add visibility parameter #321

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
merged 10 commits into from
Jul 16, 2024
Merged
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
35 changes: 28 additions & 7 deletions src/app/app-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
PackageType,
type PackageTypeMap,
} from '../gen/app/packages/v1/packages_pb';
import type { FragmentVisibilityMap } from '../gen/app/v1/app_pb';

/**
* Creates an Authorization object from auth details.
Expand Down Expand Up @@ -1019,15 +1020,26 @@ export class AppClient {
* Lists all fragments within an organization.
*
* @param orgId The ID of the organization to list fragments for
* @param publicOnly Optional boolean, if true then only public fragments will
* be listed. Defaults to true.
* @param publicOnly Optional, deprecated boolean. Use fragmentVisibilities
* instead. If true then only public fragments will be listed. Defaults to
* true
* @param fragmentVisibilities Optional list of fragment visibilities to
* include in returned list. An empty fragmentVisibilities list defaults to
* normal publicOnly behavior (discludes unlisted public fragments)
* Otherwise, fragment visibilities should contain one of the three
* visibilities and takes precendence over the publicOnly field
* @returns The list of fragment objects
*/
async listFragments(orgId: string, publicOnly = true) {
async listFragments(
orgId: string,
publicOnly = true,
fragmentVisibilities: FragmentVisibilityMap[keyof FragmentVisibilityMap][] = []
) {
const { service } = this;
const req = new pb.ListFragmentsRequest();
req.setOrganizationId(orgId);
req.setShowPublic(publicOnly);
req.setFragmentVisibilityList(fragmentVisibilities);

const response = await promisify<
pb.ListFragmentsRequest,
Expand Down Expand Up @@ -1082,16 +1094,22 @@ export class AppClient {
* @param id The ID of the fragment to update
* @param name The name to update the fragment to
* @param config The config to update the fragment to
* @param makePublic Optional boolean specifying whether the fragment should
* be public or not. If not passed the visibility will be unchanged.
* Fragments are private by default when created
* @param makePublic Optional, deprecated boolean specifying whether the
* fragment should be public or not. If not passed, the visibility will be
* unchanged. Fragments are private by default when created
* @param visibility Optional FragmentVisibility specifying the updated
* fragment visibility. If not passed, the visibility will be unchanged. If
* visibility is not set and makePublic is set, makePublic takes effect. If
* makePublic and visibility are set, they must not be conflicting. If
* neither is set, the fragment visibility will remain unchanged.
* @returns The updated fragment
*/
async updateFragment(
id: string,
name: string,
config: StructType,
makePublic?: boolean
makePublic?: boolean,
visibility?: keyof pb.FragmentVisibilityMap
) {
const { service } = this;
const req = new pb.UpdateFragmentRequest();
Expand All @@ -1101,6 +1119,9 @@ export class AppClient {
if (makePublic !== undefined) {
req.setPublic(makePublic);
}
if (visibility !== undefined) {
req.setVisibility(pb.FragmentVisibility[visibility]);
}

const response = await promisify<
pb.UpdateFragmentRequest,
Expand Down