Skip to content

[Feature Request] getAllRecordsの条件に、ブラウザで開いている画面の状態を自動反映するオプション #40

@the-red

Description

@the-red

対象パッケージ

@kintone/rest-api-client

なぜ

アプリの一覧画面にボタンを設置して、
クリックすると、ビューの絞り込み条件・ソート条件をそのまま使ってデータ取得する
というケースがよくあります。

その際に、こんな風に書くわけですが、

const records = await client.record.getAllRecords<MyRecordType>({
  app: kintone.app.getId(),
  fields: ['foo', 'bar', 'baz'],
  condition: kintone.app.getQueryCondition(),
  orderBy: kintone.app
    .getQuery()
    .replace(/.*order by /i, '')
    .replace(/limit.*/i, ''),
})

fieldsとorderByがなかなか冗長になってしまうので、
「画面の条件を自動反映する」というオプションがあると、とても開発が楽になりそうです。

何を

たとえば、それぞれのプロパティにオブジェクト型も入れられるようにして、
こんな風にすると、アプリの設定を全自動で反映してくれるイメージです。

const records = await client.record.getAllRecords<MyRecordType>({
  app: { type: 'asIs' },
  fields: { type: 'asIs' },
  condition: { type: 'asIs' },
  orderBy: { type: 'asIs' },
})

従来の型と混在も可能

const records = await client.record.getAllRecords<MyRecordType>({
  app: { type: 'asIs' },
  fields: ['foo', 'bar', 'baz'],
})

従来の使いかたをオブジェクトで書くことも可能

  const records = await client.record.getAllRecords<MyRecordType>({
    app: { type: 'toBe', value: kintone.app.getId() },
    fields: { type: 'toBe', value: ['foo', 'bar', 'baz'] },
    condition: { type: 'toBe', value: `foo != ""` },
    orderBy: { type: 'toBe', value: 'foo asc, bar desc' },
  })

もちろん、この通りの仕様で実装してくれなくても良いですが、
何かしらヒントになればと思います!

あるいは、kintone JavaScript API自体にこんな関数が追加されると
これだけでよくなるんですけどね。

const records = await client.record.getAllRecords<MyRecordType>({
  app: kintone.app.getId(),
  fields: kintone.app.getViewFields(), // new!
  condition: kintone.app.getQueryCondition(),
  orderBy: kintone.app.getQueryOrder(), // new!
})

ご検討、よろしくお願いします!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions