1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00

Add id to each individual action

This commit is contained in:
Adria Navarro 2024-07-11 15:32:25 +02:00
parent 65d7656097
commit 3bcbb57baa
4 changed files with 33 additions and 7 deletions

View file

@ -90,7 +90,12 @@ describe("/rowsActions", () => {
expect(res).toEqual({
_id: `${tableId}_row_actions`,
_rev: expect.stringMatching(/^1-\w+/),
actions: [{ name: rowAction.name }],
actions: [
{
id: expect.any(String),
name: rowAction.name,
},
],
tableId: tableId,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
@ -107,7 +112,10 @@ describe("/rowsActions", () => {
expect(res).toEqual({
_id: `${tableId}_row_actions`,
_rev: expect.stringMatching(/^3-\w+/),
actions: rowActions,
actions: rowActions.map(a => ({
id: expect.any(String),
...a,
})),
tableId: tableId,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
@ -129,7 +137,12 @@ describe("/rowsActions", () => {
expect(res1).toEqual({
_id: `${tableId}_row_actions`,
_rev: expect.stringMatching(/^1-\w+/),
actions: [rowAction1],
actions: [
{
id: expect.any(String),
...rowAction1,
},
],
tableId: tableId,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
@ -138,7 +151,12 @@ describe("/rowsActions", () => {
expect(res2).toEqual({
_id: `${otherTableId}_row_actions`,
_rev: expect.stringMatching(/^1-\w+/),
actions: [rowAction2],
actions: [
{
id: expect.any(String),
...rowAction2,
},
],
tableId: otherTableId,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
@ -178,7 +196,10 @@ describe("/rowsActions", () => {
expect(response).toEqual(
expect.objectContaining({
tableId,
actions: rowActions,
actions: rowActions.map(a => ({
id: expect.any(String),
...a,
})),
})
)
})

View file

@ -1,4 +1,4 @@
import { context } from "@budibase/backend-core"
import { context, utils } from "@budibase/backend-core"
import { generateRowActionsID } from "../../db/utils"
import { TableRowActions } from "@budibase/types"
@ -17,7 +17,10 @@ export async function create(tableId: string, rowAction: { name: string }) {
doc = { _id: rowActionsId, actions: [] }
}
doc.actions.push(rowAction)
doc.actions.push({
id: utils.newid(),
...rowAction,
})
await db.put(doc)
return await get(tableId)

View file

@ -5,6 +5,7 @@ export interface CreateRowActionRequest {
export interface RowActionsResponse {
tableId: string
actions: {
id: string
name: string
}[]
}

View file

@ -3,6 +3,7 @@ import { Document } from "../document"
export interface TableRowActions extends Document {
_id: string
actions: {
id: string
name: string
}[]
}