Skip to content

Commit

Permalink
fix: various small issues
Browse files Browse the repository at this point in the history
Signed-off-by: mertmit <mertmit99@gmail.com>
  • Loading branch information
mertmit committed Feb 29, 2024
1 parent 61b86b8 commit a701def
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 101 deletions.
77 changes: 61 additions & 16 deletions packages/nc-gui/app.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { message } from 'ant-design-vue'
import { extractSdkResponseErrorMsg } from './utils'
import { applyNonSelectable, computed, isEeUI, isMac, useCommandPalette, useRouter, useTheme } from '#imports'
import type { CommandPaletteType } from '~/lib'
Expand Down Expand Up @@ -96,27 +98,70 @@ onMounted(() => {
refreshCommandPalette()
})
})
let errorCount = 0
const handleError = async (error, clearError) => {
console.error('UI ERROR', error.value)
// if error is api error, show toast message with error message
if (error.value?.response) {
message.warn(await extractSdkResponseErrorMsg(error.value))
} else {
// else show generic error message
message.warn('Something went wrong. Please reload the page if page is not functioning properly.')
}
clearError()
// if error count is more than 3 within 3 second, navigate to home
// since it's likely endless loop of errors due to some UI issue in certain page
errorCount++
if (errorCount > 3) {
router.push('/')
}
// reset error count after 1 second
setTimeout(() => {
errorCount = 0
}, 3000)
}
</script>

<template>
<a-config-provider>
<NuxtLayout :name="disableBaseLayout ? false : 'base'">
<NuxtPage :key="key" :transition="false" />
<NuxtErrorBoundary>
<NuxtPage :key="key" :transition="false" />

<!-- on error, clear error and show toast message -->
<template #error="{ error, clearError }">
{{ handleError(error, clearError) }}
</template>
</NuxtErrorBoundary>
</NuxtLayout>
</a-config-provider>
<!-- Command Menu -->
<CmdK
ref="commandPalette"
v-model:open="cmdK"
:scope="activeScope.scope"
:data="cmdData"
:placeholder="cmdPlaceholder"
:load-temporary-scope="loadTemporaryScope"
:set-active-cmd-view="setActiveCmdView"
@scope="onScope"
/>
<!-- Recent Views. Cycles through recently visited Views -->
<CmdL v-model:open="cmdL" :set-active-cmd-view="setActiveCmdView" />
<!-- Documentation. Integrated NocoDB Docs directlt inside the Product -->
<CmdJ />

<NuxtErrorBoundary>
<div>
<!-- Command Menu -->
<CmdK
ref="commandPalette"
v-model:open="cmdK"
:scope="activeScope.scope"
:data="cmdData"
:placeholder="cmdPlaceholder"
:load-temporary-scope="loadTemporaryScope"
:set-active-cmd-view="setActiveCmdView"
@scope="onScope"
/>
<!-- Recent Views. Cycles through recently visited Views -->
<CmdL v-model:open="cmdL" :set-active-cmd-view="setActiveCmdView" />
<!-- Documentation. Integrated NocoDB Docs directly inside the Product -->
<CmdJ />
</div>

<!-- on error, clear error and show toast message -->
<template #error="{ error, clearError }">
{{ handleError(error, clearError) }}
</template>
</NuxtErrorBoundary>
</template>
78 changes: 6 additions & 72 deletions packages/nocodb-sdk/src/lib/formulaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 3,
type: FormulaDataTypes.DATE,
},
custom: (_argTypes: FormulaDataTypes[], parsedTree: any) => {
if (parsedTree.arguments[0].type === JSEPNode.LITERAL) {
Expand Down Expand Up @@ -378,7 +379,6 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 1,
type: FormulaDataTypes.DATE,
},
},
syntax: 'DATESTR(date | datetime)',
Expand All @@ -390,7 +390,6 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 1,
type: FormulaDataTypes.DATE,
},
},
syntax: 'DAY(date | datetime)',
Expand All @@ -402,7 +401,6 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 1,
type: FormulaDataTypes.DATE,
},
},
syntax: 'MONTH(date | datetime)',
Expand All @@ -414,7 +412,6 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 1,
type: FormulaDataTypes.DATE,
},
},
syntax: 'DAY(time | datetime)',
Expand All @@ -430,6 +427,7 @@ export const formulas: Record<string, FormulaMeta> = {
args: {
min: 2,
max: 3,
type: FormulaDataTypes.DATE,
},
custom: (_argTypes: FormulaDataTypes[], parsedTree: any) => {
if (parsedTree.arguments[0].type === JSEPNode.LITERAL) {
Expand Down Expand Up @@ -820,6 +818,7 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 0,
type: FormulaDataTypes.DATE,
},
},
description: 'Retrieve the current time and day.',
Expand Down Expand Up @@ -887,29 +886,8 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 2,
type: FormulaDataTypes.STRING,
},
custom(argTypes: FormulaDataTypes[], parsedTree) {
if (argTypes[0] !== FormulaDataTypes.STRING) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.stringTypeIsExpected',
calleeName: parsedTree.callee?.name?.toUpperCase(),
},
'String type is expected'
);
}
if (argTypes[1] !== FormulaDataTypes.NUMERIC) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.numericTypeIsExpected',
calleeName: parsedTree.callee?.name?.toUpperCase(),
},
'Numeric type is expected'
);
}
}
},
description: 'Retrieve the last n characters from the input string.',
syntax: 'RIGHT(str, n)',
Expand All @@ -923,29 +901,8 @@ export const formulas: Record<string, FormulaMeta> = {
validation: {
args: {
rqd: 2,
type: FormulaDataTypes.STRING,
},
custom(argTypes: FormulaDataTypes[], parsedTree) {
if (argTypes[0] !== FormulaDataTypes.STRING) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.stringTypeIsExpected',
calleeName: parsedTree.callee?.name?.toUpperCase(),
},
'String type is expected'
);
}
if (argTypes[1] !== FormulaDataTypes.NUMERIC) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.numericTypeIsExpected',
calleeName: parsedTree.callee?.name?.toUpperCase(),
},
'Numeric type is expected'
);
}
}
},
description: 'Retrieve the first n characters from the input string.',
syntax: 'LEFT(str, n)',
Expand Down Expand Up @@ -990,30 +947,6 @@ export const formulas: Record<string, FormulaMeta> = {
FormulaDataTypes.NUMERIC,
],
},
custom(argTypes: FormulaDataTypes[], parsedTree) {
if (argTypes[0] !== FormulaDataTypes.STRING) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.stringTypeIsExpected',
calleeName: parsedTree.callee?.name?.toUpperCase(),
},
'String type is expected'
);
}
for(const i of [1,2]) {
if (argTypes[i] !== FormulaDataTypes.NUMERIC) {
throw new FormulaError(
FormulaErrorType.INVALID_ARG,
{
key: 'msg.formula.numericTypeIsExpected',
calleeName: parsedTree.callee?.name?.toUpperCase(),
},
'Numeric type is expected'
);
}
}
}
},
description: 'Extracts a substring; an alias for SUBSTR.',
syntax: 'MID(str, position, [count])',
Expand Down Expand Up @@ -1131,6 +1064,7 @@ export const formulas: Record<string, FormulaMeta> = {
args: {
min: 1,
max: 2,
type: FormulaDataTypes.NUMERIC,
},
custom(_argTypes: FormulaDataTypes[], parsedTree: any) {
if (parsedTree.arguments[0].type === JSEPNode.LITERAL) {
Expand Down
6 changes: 4 additions & 2 deletions packages/nocodb/src/db/BaseModelSqlv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,8 @@ class BaseModelSqlv2 {
obj.conditionGraph = args.conditionGraph || {};
obj.limit = Math.max(
Math.min(
args.limit || args.l || BaseModelSqlv2.config.limitDefault,
Math.max(+(args.limit || args.l), 0) ||
BaseModelSqlv2.config.limitDefault,
BaseModelSqlv2.config.limitMax,
),
BaseModelSqlv2.config.limitMin,
Expand Down Expand Up @@ -6371,7 +6372,8 @@ export function getListArgs(
obj.conditionGraph = args.conditionGraph || {};
obj.limit = Math.max(
Math.min(
args?.limit || args?.l || BaseModelSqlv2.config.limitDefault,
Math.max(+(args?.limit || args?.l), 0) ||
BaseModelSqlv2.config.limitDefault,
BaseModelSqlv2.config.limitMax,
),
BaseModelSqlv2.config.limitMin,
Expand Down
2 changes: 1 addition & 1 deletion packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { BaseModelSqlv2 } from '~/db/BaseModelSqlv2';
import type Column from '~/models/Column';
import Model from '~/models/Model';
import NocoCache from '~/cache/NocoCache';
import { CacheGetType, CacheScope } from '~/utils/globals';
import { CacheScope } from '~/utils/globals';
import { convertDateFormatForConcat } from '~/helpers/formulaFnHelper';
import FormulaColumn from '~/models/FormulaColumn';
import { Base, BaseUser } from '~/models';
Expand Down
14 changes: 6 additions & 8 deletions packages/nocodb/src/services/data-table.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ export class DataTableService {
viewId?: string;
ignorePagination?: boolean;
}) {
const { model, view } = await this.getModelAndView(param);

return await this.datasService.getDataList({
model,
view,
query: param.query,
throwErrorIfInvalidParams: true,
ignorePagination: param.ignorePagination,
const { modelId, viewId, baseId, ...rest } = param;
const { model, view } = await this.getModelAndView({
modelId,
viewId,
baseId,
});
return await this.datasService.dataList({ ...rest, model, view });
}

async dataRead(param: {
Expand Down
13 changes: 11 additions & 2 deletions packages/nocodb/src/services/datas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ export class DatasService {
constructor() {}

async dataList(
param: PathParams & {
param: (PathParams | { view?: View; model: Model }) & {
query: any;
disableOptimization?: boolean;
ignorePagination?: boolean;
throwErrorIfInvalidParams?: boolean;
},
) {
const { model, view } = await getViewAndModelByAliasOrId(param);
let { model, view } = param as { view?: View; model?: Model };

if (!model) {
const modelAndView = await getViewAndModelByAliasOrId(
param as PathParams,
);
model = modelAndView.model;
view = modelAndView.view;
}

return await this.getDataList({
model,
Expand Down

1 comment on commit a701def

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR changes have been deployed. Please run the following command to verify:

docker run -d -p 8888:8080 nocodb/nocodb-timely:0.204.1-pr-7750-20240229-0547

Please sign in to comment.