Merged PR 78: fix:BUG553 ルックアップのキー重複許可する際エラーの処理

fix:BUG553 ルックアップのキー重複許可する際エラーの処理
ルックアップのキー重複許可する時、エラーメッセージを表示するように対応しました。

Related work items: #553
This commit is contained in:
Shohtetsu Ma
2024-08-07 08:33:01 +00:00
committed by Takuto Yoshida(タクト)
2 changed files with 81 additions and 38 deletions

File diff suppressed because one or more lines are too long

View File

@@ -9,7 +9,7 @@ import {
import { actionAddins } from ".";
import type { Record} from "@kintone/rest-api-client/lib/src/client/types";
import { KintoneRestAPIClient} from "@kintone/rest-api-client";
import { KintoneAllRecordsError, KintoneRestAPIClient} from "@kintone/rest-api-client";
import "./auto-lookup.scss";
import "bootstrap/js/dist/modal";
// import "bootstrap/js/dist/spinner";
@@ -130,9 +130,12 @@ export class AutoLookUpAction implements IAction {
const updateRecords = this.convertForLookup(targetRecords,lookUpField,key);
console.log("updateRecords", updateRecords);
this.showSpinnerModel(this.props.lookupField.app);
await this.updateLookupTarget(updateRecords);
this.showResult(this.props.lookupField.app,updateRecords.length);
const updateResult = await this.updateLookupTarget(updateRecords);
if(updateResult){
this.showResult(this.props.lookupField.app,updateRecords.length);
}
} catch (error) {
this.closeDialog();
context.errors.handleError(error,actionNode,"ルックアップ更新中例外が発生しました");
result.canNext = false;
}
@@ -186,18 +189,29 @@ export class AutoLookUpAction implements IAction {
* ルックアップ先を更新する
* @param updateRecords
*/
updateLookupTarget = async (updateRecords:Array<any>)=>{
updateLookupTarget = async (updateRecords:Array<any>):Promise<boolean>=>{
if (updateRecords && updateRecords.length > 0) {
const client=new KintoneRestAPIClient();
client.record.updateAllRecords({
app:this.props.lookupField.app.id,
records:updateRecords
});
try{
const client=new KintoneRestAPIClient();
const result = await client.record.updateAllRecords({
app:this.props.lookupField.app.id,
records:updateRecords
});
return true;
}catch(error ){
if(error instanceof KintoneAllRecordsError){
this.showError(this.props.lookupField.app,error as KintoneAllRecordsError,updateRecords.length);
return false;
}else{
throw error;
}
}
// await kintone.api(kintone.api.url("/k/v1/records.json", true), "PUT", {
// app: this.props.lookupField.app.id,
// records: updateRecords
// });
}
return false;
}
/**
@@ -257,6 +271,31 @@ export class AutoLookUpAction implements IAction {
dialogBody.html(html);
}
/**
* 更新結果を表示する
* @param app  更新先アプリ情報
* @param count 更新件数
*/
showError=(app:App,error:KintoneAllRecordsError,allCount:Number)=>{
const message=error.error.message;
const proRecords = error.numOfProcessedRecords;
const allRecords=error.numOfAllRecords;
const dialogBody=$(`#alcLookupModal .modal-body #app${app.id}`);
const html=`<div class="col-1 text-danger">✖</div>
<div class="col">${app.name}</div>
<div class="col">更新件数:${proRecords}/${allRecords}</div>
<div class="row text-danger">${message}<div>`;
dialogBody.html(html);
}
/**
* ダイアログ画面を閉じる
*/
closeDialog=()=>{
const dialog = $("#alcLookupModal");
Modal.getOrCreateInstance(dialog.get()[0]).dispose();
$("#alcLookupModal").parent().remove();
}
register(): void {
actionAddins[this.name] = this;
}