Skip to content
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

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

Open
the-red opened this issue Aug 1, 2023 · 4 comments
Labels
feature request Feature request

Comments

@the-red
Copy link

the-red commented Aug 1, 2023

対象パッケージ

@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!
})

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

@the-red the-red added the feature request Feature request label Aug 1, 2023
@the-red
Copy link
Author

the-red commented Nov 2, 2023

こちら、どなたか確認して頂けたでしょうか・・・?
何かしらリアクションもらえると有り難いです 😢

@hung-cybo
Copy link
Contributor

@the-red

Sorry, we missed this issue.
We will check and respond to you soon.
Thank you for your patience.

@tasshi-me
Copy link
Member

@the-red
フィードバックありがとうございます!

確かにブラウザ上での利用の場合、画面のアプリID, フィールド絞り込み, クエリをそのまま利用するケースは少なくなさそうですね!
※若干の懸念点としてはfieldsについては画面に依存することで未定義プロパティアクセスの実行時エラーを引き起こしやすくなる可能性がありますね。

すでに kintone.app.getQueryCondition() があるので、理想としてはfieldsorder byについてもJS APIがある方が良さそうに思います。

rest-api-clientでも一覧設定取得APIfields, filterCond, sortが取得できるので実現できそうですね。

JS APIについては社内にフィードバック、rest-api-clientでの対応はインターフェースも含めて検討させていただきます。

@the-red
Copy link
Author

the-red commented Nov 16, 2023

@mshrtsr コメントありかとうございます!
また動きあったら教えてくださいませ〜。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Feature request
Projects
None yet
Development

No branches or pull requests

3 participants