Browse Source

Merge pull request #3339 from nocodb/fix/gui-v2-row-audit

fix(gui-v2): log audit and reload audit list on row update
pull/3346/head
Pranav C 2 years ago committed by GitHub
parent
commit
f54f0bd3e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/nc-gui-v2/components/smartsheet/Grid.vue
  2. 12
      packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue
  3. 22
      packages/nc-gui-v2/composables/useExpandedFormStore.ts
  4. 7
      packages/nc-gui-v2/composables/useViewData.ts

6
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -218,8 +218,10 @@ const onKeyDown = async (e: KeyboardEvent) => {
break break
/** on delete key press clear cell */ /** on delete key press clear cell */
case 'Delete': case 'Delete':
if (!editEnabled) {
e.preventDefault() e.preventDefault()
await clearCell(selected as { row: number; col: number }) await clearCell(selected as { row: number; col: number })
}
break break
/** on arrow key press navigate through cells */ /** on arrow key press navigate through cells */
case 'ArrowRight': case 'ArrowRight':
@ -243,7 +245,7 @@ const onKeyDown = async (e: KeyboardEvent) => {
const rowObj = data.value[selected.row] const rowObj = data.value[selected.row]
const columnObj = fields.value[selected.col] const columnObj = fields.value[selected.col]
if (e.metaKey || e.ctrlKey) { if ((!editEnabled && e.metaKey) || e.ctrlKey) {
switch (e.keyCode) { switch (e.keyCode) {
// copy - ctrl/cmd +c // copy - ctrl/cmd +c
case 67: case 67:
@ -596,10 +598,12 @@ const onNavigate = (dir: NavigateDir) => {
.nc-row-expand-and-checkbox { .nc-row-expand-and-checkbox {
@apply w-full items-center justify-between; @apply w-full items-center justify-between;
} }
.nc-expand { .nc-expand {
&:not(.nc-comment) { &:not(.nc-comment) {
@apply hidden; @apply hidden;
} }
&.nc-comment { &.nc-comment {
display: flex; display: flex;
} }

12
packages/nc-gui-v2/components/smartsheet/expanded-form/index.vue

@ -105,10 +105,16 @@ export default {
</script> </script>
<template> <template>
<a-drawer v-model:visible="isExpanded" :footer="null" width="min(90vw,1000px)" :body-style="{ padding: 0 }" :closable="false"> <a-drawer
v-model:visible="isExpanded"
:footer="null"
width="min(90vw,1000px)"
:body-style="{ 'padding': 0, 'display': 'flex', 'flex-direction': 'column' }"
:closable="false"
>
<Header @cancel="onClose" /> <Header @cancel="onClose" />
<div class="!bg-gray-100 rounded"> <div class="!bg-gray-100 rounded flex-1">
<div class="flex h-full nc-form-wrapper items-stretch min-h-[70vh]"> <div class="flex h-full nc-form-wrapper items-stretch min-h-[max(70vh,100%)]">
<div class="flex-1 overflow-auto scrollbar-thin-primary"> <div class="flex-1 overflow-auto scrollbar-thin-primary">
<div class="w-[500px] mx-auto"> <div class="w-[500px] mx-auto">
<div v-for="col of fields" :key="col.title" class="mt-2 py-2" :class="`nc-expand-col-${col.title}`"> <div v-for="col of fields" :key="col.title" class="mt-2 py-2" :class="`nc-expand-col-${col.title}`">

22
packages/nc-gui-v2/composables/useExpandedFormStore.ts

@ -96,8 +96,6 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
comment.value = '' comment.value = ''
message.success('Comment added successfully')
await loadCommentsAndLogs() await loadCommentsAndLogs()
} catch (e: any) { } catch (e: any) {
message.error(e.message) message.error(e.message)
@ -125,24 +123,11 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
if (row.value.rowMeta?.new) { if (row.value.rowMeta?.new) {
data = await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, updateOrInsertObj) data = await $api.dbTableRow.create('noco', project.value.title as string, meta.value.title, updateOrInsertObj)
/* todo:
// save hasmany and manytomany relations from local state
if (this.$refs.virtual && Array.isArray(this.$refs.virtual)) {
for (const vcell of this.$refs.virtual) {
if (vcell.save) {
await vcell.save(this.localState);
}
}
} */
Object.assign(row.value, { Object.assign(row.value, {
row: data, row: data,
rowMeta: {}, rowMeta: {},
oldRow: { ...data }, oldRow: { ...data },
}) })
/// todo:
// await this.reload();
} else if (Object.keys(updateOrInsertObj).length) { } else if (Object.keys(updateOrInsertObj).length) {
const id = extractPkFromRow(row.value.row, meta.value.columns as ColumnType[]) const id = extractPkFromRow(row.value.row, meta.value.columns as ColumnType[])
@ -160,7 +145,12 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
value: getHTMLEncodedText(updateOrInsertObj[key]), value: getHTMLEncodedText(updateOrInsertObj[key]),
prev_value: getHTMLEncodedText(row.value.oldRow[key]), prev_value: getHTMLEncodedText(row.value.oldRow[key]),
}) })
.then(() => {}) .then(async () => {
/** load latest comments/audit if right drawer is open */
if (commentsDrawer.value) {
await loadCommentsAndLogs()
}
})
} }
} else { } else {
return message.info('No columns to update') return message.info('No columns to update')

7
packages/nc-gui-v2/composables/useViewData.ts

@ -167,10 +167,7 @@ export function useViewData(
const updateRowProperty = async (toUpdate: Row, property: string) => { const updateRowProperty = async (toUpdate: Row, property: string) => {
try { try {
const id = meta?.value?.columns const id = extractPkFromRow(toUpdate.row, meta.value.columns as ColumnType[])
?.filter((c) => c.pk)
.map((c) => toUpdate.row[c.title as string])
.join('___') as string
const updatedRowData = await $api.dbViewRow.update( const updatedRowData = await $api.dbViewRow.update(
NOCO, NOCO,
@ -195,7 +192,7 @@ export function useViewData(
value: getHTMLEncodedText(toUpdate.row[property]), value: getHTMLEncodedText(toUpdate.row[property]),
prev_value: getHTMLEncodedText(toUpdate.oldRow[property]), prev_value: getHTMLEncodedText(toUpdate.oldRow[property]),
}) })
.catch(() => {}) .then(() => {})
/** update row data(to sync formula and other related columns) */ /** update row data(to sync formula and other related columns) */
Object.assign(toUpdate.row, updatedRowData) Object.assign(toUpdate.row, updatedRowData)

Loading…
Cancel
Save