Skip to content

Commit

Permalink
fix: allow to bulk update record without filter
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Nov 29, 2024
1 parent ed9f8d1 commit 1303e7c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@
})
const updateRecords = async (values: any) => {
if (!filter) {
return
}
const selectedSchema = $table.schema.getMutableSchema(selectedFields)
const validated = await form.validateForm({
update: true,
Expand Down Expand Up @@ -181,7 +177,7 @@
<div class="-mx-4 flex justify-end border-t py-2 pt-4">
<Button
size="sm"
disabled={!filter || !selectedFields.length}
disabled={!selectedFields.length}
class="mr-5"
on:click={() => {
open = true
Expand Down Expand Up @@ -237,8 +233,13 @@
<AlertDialog.Title>{$LL.table.record.bulkUpdate.title()}</AlertDialog.Title>
<AlertDialog.Description>{$LL.table.record.bulkUpdate.description()}</AlertDialog.Description>
</AlertDialog.Header>
{#if !filter}
<Alert.Root class="border-yellow-300 bg-yellow-50 text-yellow-700">
<Alert.Description>{$LL.table.record.bulkUpdate.noFilterAlert()}</Alert.Description>
</Alert.Root>
{/if}
<AlertDialog.Footer>
<AlertDialog.Cancel>{$LL.table.common.cancel()}</AlertDialog.Cancel>
<AlertDialog.Cancel>{$LL.common.cancel()}</AlertDialog.Cancel>
<AlertDialog.Action
on:click={() => {
if (values) {
Expand Down
2 changes: 1 addition & 1 deletion packages/commands/src/bulk-update-records.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class BulkUpdateRecordsCommand extends Command implements IBulkUpdateReco
public readonly tableId?: string
public readonly baseName?: string
public readonly tableName?: string
public readonly filter: IViewFilterGroup
public readonly filter?: IViewFilterGroup
public readonly values: IRecordValues
public readonly isOpenapi?: boolean

Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ const record = {
continue: 'Continue',
noRecordsUpdated: 'No records updated',
recordsUpdated: '{count} records updated successfully',
button: 'Bulk Update'
button: 'Bulk Update',
noFilterAlert: 'No filter, will update all records, please be careful!'
},
reference: {
link: 'Link Records',
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/i18n/es/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ const record = {
continue: 'Continuar',
noRecordsUpdated: 'No hay registros actualizados',
recordsUpdated: '{count} registros actualizados correctamente',
button: 'Actualizar en masa'
button: 'Actualizar en masa',
noFilterAlert: 'No hay filtro, se actualizarán todos los registros, por favor, ten cuidado!'
},
reference: {
link: 'enlace de registro',
Expand Down
8 changes: 8 additions & 0 deletions packages/i18n/src/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,10 @@ type RootTranslation = {
* B​u​l​k​ ​U​p​d​a​t​e
*/
button: string
/**
* N​o​ ​f​i​l​t​e​r​,​ ​w​i​l​l​ ​u​p​d​a​t​e​ ​a​l​l​ ​r​e​c​o​r​d​s​,​ ​p​l​e​a​s​e​ ​b​e​ ​c​a​r​e​f​u​l​!
*/
noFilterAlert: string
}
reference: {
/**
Expand Down Expand Up @@ -3471,6 +3475,10 @@ export type TranslationFunctions = {
* Bulk Update
*/
button: () => LocalizedString
/**
* No filter, will update all records, please be careful!
*/
noFilterAlert: () => LocalizedString
}
reference: {
/**
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/i18n/ja/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ const record = {
continue: '続行',
noRecordsUpdated: 'レコードが更新されません',
recordsUpdated: '{count} 件のレコードが更新に成功しました',
button: '一括更新'
button: '一括更新',
noFilterAlert: 'フィルターがないため、すべてのレコードが更新されます。慎重に操作してください!'
},
noRecord: 'レコードがありません',
reference: {
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/i18n/ko/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ const record = {
continue: '계속',
noRecordsUpdated: '업데이트된 레코드가 없습니다',
recordsUpdated: '{count} 개의 레코드가 성공적으로 업데이트되었습니다',
button: '일괄 업데이트'
button: '일괄 업데이트',
noFilterAlert: '필터가 없습니다. 모든 레코드가 업데이트됩니다. 주의하세요!'
},
reference: {
link: '연결 레코드',
Expand Down
3 changes: 2 additions & 1 deletion packages/i18n/src/i18n/zh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ const record = {
continue: '继续',
noRecordsUpdated: '没有记录更新',
recordsUpdated: '{count} 条记录更新成功',
button: '批量更新'
button: '批量更新',
noFilterAlert: '没有筛选条件, 将会更新所有记录,请谨慎操作!'
},
reference: {
link: '关联记录',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { viewFilterGroup } from "../../../views"
import { recordValues } from "../record-values.vo"

export const bulkUpdateRecordsDTO = z.object({
filter: viewFilterGroup,
filter: viewFilterGroup.optional(),
values: recordValues,
isOpenapi: z.boolean().optional(),
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Some, type Option } from "@undb/domain"
import { None, Some, type Option } from "@undb/domain"
import type { IUniqueTableDTO } from "../../../../dto"
import { withUniqueTable } from "../../../../specifications"
import { getSpec, replaceCondtionFieldNameWithFieldId } from "../../../schema/fields/condition"
Expand All @@ -14,15 +14,11 @@ export async function bulkUpdateRecordsMethod(
const table = (await this.tableRepository.findOne(Some(ts))).expect("Table not found")

let filter = dto.filter
if (dto.isOpenapi) {
if (dto.isOpenapi && filter) {
filter = replaceCondtionFieldNameWithFieldId(filter, table.schema)
}

const spec = getSpec(table.schema, filter) as Option<RecordComositeSpecification>

if (spec.isNone()) {
throw new Error("Invalid fjjilter")
}
const spec = (filter ? getSpec(table.schema, filter) : None) as Option<RecordComositeSpecification>

const records = await this.repo.find(table, spec)
if (records.length === 0) {
Expand Down

0 comments on commit 1303e7c

Please sign in to comment.