0

我很难理解如何从 Optro https://github.com/optro-cloud/trello-powerup-full-sample为反应模板构建更多功能。

到目前为止,我的理解是,您在第二行的以下文件中进行 API 调用,这相当于调用 get all cards:

  • src/api/power-up.ts
export async function getBoardNotes(t: Trello.PowerUp.IFrame): Promise<NoteWithCard[]> {
    const cards: Trello.PowerUp.Card[] = await t.cards('all'); // Here's the API call
    const allNotes: NoteWithCard[] = [];
    for(const card of cards) {
        const cardNotes: Note[] = await getCardNotes(t, card.id);
        allNotes.push(...cardNotes.map((note: Note) => ({...note, card: card})));
    }
    return allNotes;
}

这被映射到映射所有响应类型的 TypeScript 声明文件:

  • 类型/power-up.d.ts
  • types/trello.d.ts(我在下面提到的所有代码都位于此文件中)

卡片字段设置为 all 就像在 REST API 的文档中一样:https ://developer.atlassian.com/cloud/trello/rest/api-group-cards/#api-cards-id-get

interface AnonymousHostHandlers {
            requestWithContext(command: string, options: any): PromiseLike<any>;
            getAll(): PromiseLike<any>;
            get(scope: Scope | string, visibility: Visibility, key?: string, defaultValue?: any): PromiseLike<any>;
            set(scope: Scope | string, visibility: Visibility, key: string, defaultValue?: any): PromiseLike<void>;
            set(scope: Scope | string, visibility: Visibility, entries: {
                [ key: string]: any;
            }): PromiseLike<void>;
            remove(scope: Scope | string, visibility: Visibility, key: string): PromiseLike<void>;
            remove(scope: Scope | string, visibility: Visibility, entries: string[]): PromiseLike<void>;
            safe(html: string): string;
            localizeKey(key: string, data?: {
                [key: string]: string;
            }): string;
            localizeKeys(keys: [string | string[]]): string[];
            localizeNode(node: Element): void;
            board(...fields: ['all'] | BoardFields[]): PromiseLike<Board>;
            cards(...fields: ['all'] | CardFields[]): PromiseLike<Card[]>;
            lists(...fields: ['all'] | ListFields[]): PromiseLike<List[]>;
            member(...fields: ['all'] | MemberFields[]): PromiseLike<Member>;
            organization(...fields: ['all'] | OrganizationFields[]): PromiseLike<Organization>;
        }

现在我想我可以在声明文件中添加新的字段映射,以便能够获取目前不存在的数据。一个例子是声明文件已经映射了 customFieldItems ,它在响应中正确返回:

interface Card {
            address: string | null;
            attachments: Attachment[];
            badges: BadgesInfo;
            closed: boolean;
            coordinates: Coordinates | null;
            cover: Attachment | null;
            customFieldItems: CustomField[];
            dateLastActivity: string; // '2019-11-28T15:53:19.709Z'
            desc: string;
            due: string | null; // '2019-11-28T15:53:19.709Z'
            dueComplete: boolean;
            id: string;
            idList: string;
            idShort: number;
            labels: Label[];
            locationName: string | null;
            members: Member[];
            name: string;
            pos: number;
            shortLink: string;
            url: string; // https://trello.com/c/I5nAdteE/9-test
        }

但是,如果我尝试添加映射了“checklist_fields”的“checklists”参数,它不会返回该对象。


type ChecklistFields = keyof Checklist;

interface AnonymousHostHandlers {
            requestWithContext(command: string, options: any): PromiseLike<any>;
            getAll(): PromiseLike<any>;
            get(scope: Scope | string, visibility: Visibility, key?: string, defaultValue?: any): PromiseLike<any>;
            set(scope: Scope | string, visibility: Visibility, key: string, defaultValue?: any): PromiseLike<void>;
            set(scope: Scope | string, visibility: Visibility, entries: {
                [ key: string]: any;
            }): PromiseLike<void>;
            remove(scope: Scope | string, visibility: Visibility, key: string): PromiseLike<void>;
            remove(scope: Scope | string, visibility: Visibility, entries: string[]): PromiseLike<void>;
            safe(html: string): string;
            localizeKey(key: string, data?: {
                [key: string]: string;
            }): string;
            localizeKeys(keys: [string | string[]]): string[];
            localizeNode(node: Element): void;
            board(...fields: ['all'] | BoardFields[]): PromiseLike<Board>;
            cards(...fields: ['all'] | CardFields[]): PromiseLike<Card[]>;
            lists(...fields: ['all'] | ListFields[]): PromiseLike<List[]>;
            member(...fields: ['all'] | MemberFields[]): PromiseLike<Member>;
            checklist(...fields: ['all'] | ChecklistFields[]): PromiseLike<Checklist>;
            organization(...fields: ['all'] | OrganizationFields[]): PromiseLike<Organization>;
        }

interface Card {
            address: string | null;
            attachments: Attachment[];
            badges: BadgesInfo;
            checklists: Checklist[];
            closed: boolean;
            coordinates: Coordinates | null;
            cover: Attachment | null;
            customFieldItems: CustomField[];
            dateLastActivity: string; // '2019-11-28T15:53:19.709Z'
            desc: string;
            due: string | null; // '2019-11-28T15:53:19.709Z'
            dueComplete: boolean;
            id: string;
            idList: string;
            idShort: number;
            labels: Label[];
            locationName: string | null;
            members: Member[];
            name: string;
            pos: number;
            shortLink: string;
            url: string; // https://trello.com/c/I5nAdteE/9-test
        }

        interface Checklist {
            id: string;
            name: string;
            pos: number;
            idBoard: string;
            idCard: string;
        }
4

0 回答 0