Skip to content

Commit

Permalink
Add generic picker API
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchLillie committed Sep 26, 2024
1 parent 9fe9d56 commit f037cd9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/ui-extensions/src/surfaces/admin/api/picker/picker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {Tone} from "../../components/shared";

interface Picker {
update: (options: PickerOptions) => Promise<void>;
selectedItems: Item[];
}

interface PickerOptions {
heading?: string;
description?: string;
multiple?: boolean | number;
loading?: boolean;
items: Item[];
onSelect?(event: any): void;
onCancel?(): void;
}

interface Item {
thumbnail?: {url: string};
heading?: string;
subheading?: string;
action?: {
content: string;
tone?: Tone;
}
tags?: {
content: string;
}[];
data?: [string] | [string, string] | [string, string, string];
items?: NestedItem[];
}

interface NestedItem extends Pick<Item, 'thumbnail' | 'heading' | 'data' | 'items'> {
}

export type PickerApi = (options: PickerOptions) => Promise<Picker>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {I18n} from '../../../../api';
import {ApiVersion} from '../../../../shared';
import type {ExtensionTarget as AnyExtensionTarget} from '../../extension-targets';
import {PickerApi} from '../picker/picker';

export interface Intents {
/**
Expand Down Expand Up @@ -49,4 +50,9 @@ export interface StandardApi<ExtensionTarget extends AnyExtensionTarget> {
query: string,
options?: {variables?: Variables; version?: Omit<ApiVersion, '2023-04'>},
) => Promise<{data?: Data; errors?: GraphQLError[]}>;

/**
* Renders the [Picker](/docs/api/app-bridge-library/apis/picker), allowing users to select a resource for the extension to use as part of its flow.
*/
picker: PickerApi;
}

0 comments on commit f037cd9

Please sign in to comment.