Browse Source

fix: review changes

Ramesh Mane 1 week ago
parent
commit
f88e61d343
  1. 75
      packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue
  2. 12
      packages/nocodb/src/controllers/custom-urls.controller.ts
  3. 15
      packages/nocodb/src/models/CustomUrl.ts
  4. 12
      packages/nocodb/src/models/View.ts
  5. 6
      packages/nocodb/src/modules/noco.module.ts
  6. 11
      packages/nocodb/src/services/custom-urls.service.ts
  7. 8
      packages/nocodb/src/services/views.service.ts

75
packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue

@ -16,6 +16,8 @@ const workspaceStore = useWorkspace()
const isLocked = inject(IsLockedInj, ref(false)) const isLocked = inject(IsLockedInj, ref(false))
const { copy } = useCopy()
const isUpdating = ref({ const isUpdating = ref({
public: false, public: false,
password: false, password: false,
@ -104,16 +106,37 @@ const togglePasswordProtected = async () => {
const isOpenCustomUrlLocal = ref(false) const isOpenCustomUrlLocal = ref(false)
const isOpenCustomUrl = computed(() => { const isOpenCustomUrl = computed(() => {
return !!activeView.value?.password || isOpenCustomUrlLocal.value return !!activeView.value?.custom_url_path || isOpenCustomUrlLocal.value
}) })
const customUrl = computed({ const customUrl = ref()
get: () => (isOpenCustomUrl.value ? activeView.value?.custom_url_path ?? '' : ''),
set: async (value) => {
if (!activeView.value) return
activeView.value = { ...(activeView.value as any), custom_url_path: isOpenCustomUrl.value ? value : null } // const customUrl = computed({
}, // get: () => (isOpenCustomUrl.value ? activeView.value?.custom_url_path ?? '' : ''),
// set: async (value) => {
// if (!activeView.value) return
// activeView.value = { ...(activeView.value as any), custom_url_path: isOpenCustomUrl.value ? value : null }
// },
// })
const dashboardUrl1 = computed(() => {
// get base url for workspace
const baseUrl = getBaseUrl(workspaceStore.activeWorkspaceId)
if (baseUrl) {
return `${baseUrl}${appInfo.value?.dashboardPath}`
}
return dashboardUrl.value
})
const copyCustomUrl = () => {
copy(`${dashboardUrl1.value}}#/shared/${customUrl.value}`)
}
onMounted(() => {
customUrl.value = activeView.value?.custom_url_path
}) })
const toggleCustomUrl = async () => { const toggleCustomUrl = async () => {
@ -121,17 +144,17 @@ const toggleCustomUrl = async () => {
if (!activeView.value) return if (!activeView.value) return
if (isUpdating.value.customUrl) return if (isUpdating.value.customUrl) return
isUpdating.value.password = true isUpdating.value.customUrl = true
try { try {
if (passwordProtected.value) { if (isOpenCustomUrl.value) {
activeView.value = { ...(activeView.value as any), custom_url_path: null } customUrl.value = null
} else { } else {
activeView.value = { ...(activeView.value as any), custom_url_path: '' } customUrl.value = null
} }
await updateSharedView() await updateSharedView()
} finally { } finally {
isUpdating.value.password = false isUpdating.value.customUrl = false
} }
} }
@ -251,17 +274,6 @@ function sharedViewUrl() {
}` }`
} }
const dashboardUrl1 = computed(() => {
// get base url for workspace
const baseUrl = getBaseUrl(workspaceStore.activeWorkspaceId)
if (baseUrl) {
return `${baseUrl}${appInfo.value?.dashboardPath}`
}
return dashboardUrl.value
})
const toggleViewShare = async () => { const toggleViewShare = async () => {
if (!activeView.value?.id) return if (!activeView.value?.id) return
@ -328,8 +340,9 @@ async function updateSharedView() {
await $api.dbViewShare.update(activeView.value.id!, { await $api.dbViewShare.update(activeView.value.id!, {
meta, meta,
password: activeView.value.password, password: activeView.value.password,
custom_url_path: activeView.value?.custom_url_path ?? null, custom_url_path: customUrl.value ?? null,
}) })
activeView.value.custom_url_path = customUrl.value ?? null
} catch (e: any) { } catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
} }
@ -396,10 +409,20 @@ async function savePreFilledMode() {
size="small" size="small"
:bordered="false" :bordered="false"
autocomplete="off" autocomplete="off"
@update:value="updateSharedViewWithDebounce"
/> />
<div> <div>
<NcButton size="xs" @click.stop="updateSharedView"> <NcButton
v-if="customUrl && customUrl === activeView?.custom_url_path"
size="xs"
type="secondary"
@click="copyCustomUrl"
>
<template #icon>
<MdiContentCopy class="h-3.5" />
</template>
{{ $t('general.copy') }}
</NcButton>
<NcButton v-else size="xs" :disabled="!customUrl" @click.stop="updateSharedView">
{{ $t('general.save') }} {{ $t('general.save') }}
</NcButton> </NcButton>
</div> </div>

12
packages/nocodb/src/controllers/custom-urls.controller.ts

@ -9,8 +9,6 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { GlobalGuard } from '~/guards/global/global.guard'; import { GlobalGuard } from '~/guards/global/global.guard';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard'; import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
import { TenantContext } from '~/decorators/tenant-context.decorator';
import { NcContext } from '~/interface/config';
import { CustomUrlsService } from 'src/services/custom-urls.service'; import { CustomUrlsService } from 'src/services/custom-urls.service';
@Controller() @Controller()
@ -22,23 +20,19 @@ export class CustomUrlsController {
'/api/v1/db/meta/custom-url/:customPath', '/api/v1/db/meta/custom-url/:customPath',
'/api/v2/meta/custom-url/:customPath', '/api/v2/meta/custom-url/:customPath',
]) ])
async getOriginalPath( async getOriginalPath(@Param('customPath') customPath: string) {
@TenantContext() context: NcContext, return await this.customUrlsService.getOriginalPath(customPath);
@Param('customPath') customPath: string,
) {
await this.customUrlsService.getOriginalPath(context, customPath);
} }
@Post(['/api/v1/db/meta/custom-url/check-path', '/api/v2/meta/check-path']) @Post(['/api/v1/db/meta/custom-url/check-path', '/api/v2/meta/check-path'])
@HttpCode(200) @HttpCode(200)
async checkAvailability( async checkAvailability(
@TenantContext() context: NcContext,
@Body() @Body()
body: { body: {
id?: string; id?: string;
custom_path?: string; custom_path?: string;
}, },
) { ) {
await this.customUrlsService.checkAvailability(context, body); return await this.customUrlsService.checkAvailability(body);
} }
} }

15
packages/nocodb/src/models/CustomUrl.ts

@ -7,7 +7,7 @@ import {
RootScopes, RootScopes,
} from '~/utils/globals'; } from '~/utils/globals';
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import { NcContext } from 'src/interface/config'; import { NcError } from 'src/helpers/catchError';
export default class CustomUrl { export default class CustomUrl {
id?: string; id?: string;
@ -23,7 +23,6 @@ export default class CustomUrl {
} }
public static async get( public static async get(
_context: NcContext,
params: Pick<CustomUrl, 'id' | 'view_id' | 'custom_path'>, params: Pick<CustomUrl, 'id' | 'view_id' | 'custom_path'>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
@ -40,7 +39,6 @@ export default class CustomUrl {
} }
public static async getOriginUrlByCustomPath( public static async getOriginUrlByCustomPath(
_context: NcContext,
customPath: string, customPath: string,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
@ -64,13 +62,14 @@ export default class CustomUrl {
} }
} }
console.log('custom url', customUrl); if (!customUrl) {
NcError.notFound();
}
return customUrl && new CustomUrl(customUrl); return customUrl?.original_path;
} }
public static async insert( public static async insert(
_context: NcContext,
customUrl: Partial<CustomUrl>, customUrl: Partial<CustomUrl>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
@ -94,7 +93,6 @@ export default class CustomUrl {
} }
public static async list( public static async list(
_context: NcContext,
params: Pick<CustomUrl, 'fk_workspace_id' | 'base_id' | 'fk_model_id'>, params: Pick<CustomUrl, 'fk_workspace_id' | 'base_id' | 'fk_model_id'>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
@ -117,7 +115,6 @@ export default class CustomUrl {
} }
public static async update( public static async update(
_context: NcContext,
id: string, id: string,
customUrl: Partial<CustomUrl>, customUrl: Partial<CustomUrl>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
@ -137,7 +134,6 @@ export default class CustomUrl {
} }
public static async checkAvailability( public static async checkAvailability(
_context: NcContext,
params: Pick<CustomUrl, 'id' | 'custom_path'>, params: Pick<CustomUrl, 'id' | 'custom_path'>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {
@ -165,7 +161,6 @@ export default class CustomUrl {
} }
static async delete( static async delete(
_context: NcContext,
customUrl: Pick<CustomUrl, 'id' | 'view_id'>, customUrl: Pick<CustomUrl, 'id' | 'view_id'>,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
) { ) {

12
packages/nocodb/src/models/View.ts

@ -131,7 +131,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view); view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) { if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, { const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id, id: view.fk_custom_url_id,
}); });
@ -181,7 +181,7 @@ export default class View implements ViewType {
if (view) { if (view) {
if (view.fk_custom_url_id) { if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, { const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id, id: view.fk_custom_url_id,
}); });
@ -229,7 +229,7 @@ export default class View implements ViewType {
if (view) { if (view) {
view.meta = parseMetaProp(view); view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) { if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, { const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id, id: view.fk_custom_url_id,
}); });
@ -268,7 +268,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view); view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) { if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, { const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id, id: view.fk_custom_url_id,
}); });
@ -1283,7 +1283,7 @@ export default class View implements ViewType {
viewId, viewId,
); );
await CustomUrl.delete(context, { view_id: viewId }); await CustomUrl.delete({ view_id: viewId });
await NocoCache.update(`${CacheScope.VIEW}:${viewId}`, { await NocoCache.update(`${CacheScope.VIEW}:${viewId}`, {
uuid: null, uuid: null,
@ -1448,7 +1448,7 @@ export default class View implements ViewType {
} }
if (view.fk_custom_url_id) { if (view.fk_custom_url_id) {
await CustomUrl.delete(context, { id: view.fk_custom_url_id }); await CustomUrl.delete({ id: view.fk_custom_url_id });
} }
// on update, delete any optimised single query cache // on update, delete any optimised single query cache

6
packages/nocodb/src/modules/noco.module.ts

@ -16,6 +16,8 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service';
import { TelemetryService } from '~/services/telemetry.service'; import { TelemetryService } from '~/services/telemetry.service';
import { AppHooksListenerService } from '~/services/app-hooks-listener.service'; import { AppHooksListenerService } from '~/services/app-hooks-listener.service';
import { HookHandlerService } from '~/services/hook-handler.service'; import { HookHandlerService } from '~/services/hook-handler.service';
import { CustomUrlsController } from '~/controllers/custom-urls.controller';
import { CustomUrlsService } from '~/services/custom-urls.service';
/* User */ /* User */
import { UsersController } from '~/controllers/users/users.controller'; import { UsersController } from '~/controllers/users/users.controller';
@ -145,6 +147,8 @@ export const nocoModuleMetadata = {
controllers: [ controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true' ...(process.env.NC_WORKER_CONTAINER !== 'true'
? [ ? [
CustomUrlsController,
/* Users */ /* Users */
UsersController, UsersController,
@ -215,6 +219,7 @@ export const nocoModuleMetadata = {
AppHooksListenerService, AppHooksListenerService,
TelemetryService, TelemetryService,
HookHandlerService, HookHandlerService,
CustomUrlsService,
/* Users */ /* Users */
UsersService, UsersService,
@ -277,6 +282,7 @@ export const nocoModuleMetadata = {
TelemetryService, TelemetryService,
HookHandlerService, HookHandlerService,
JwtStrategy, JwtStrategy,
CustomUrlsService,
/* Users */ /* Users */
UsersService, UsersService,

11
packages/nocodb/src/services/custom-urls.service.ts

@ -7,14 +7,11 @@ import CustomUrl from 'src/models/CustomUrl';
export class CustomUrlsService { export class CustomUrlsService {
constructor(private readonly appHooksService: AppHooksService) {} constructor(private readonly appHooksService: AppHooksService) {}
async checkAvailability( async checkAvailability(params: Pick<CustomUrl, 'id' | 'custom_path'>) {
context: NcContext, return await CustomUrl.checkAvailability(params);
params: Pick<CustomUrl, 'id' | 'custom_path'>,
) {
return await CustomUrl.checkAvailability(context, params);
} }
async getOriginalPath(context: NcContext, custom_path: string) { async getOriginalPath(custom_path: string) {
return await CustomUrl.getOriginUrlByCustomPath(context, custom_path); return await CustomUrl.getOriginUrlByCustomPath(custom_path);
} }
} }

8
packages/nocodb/src/services/views.service.ts

@ -273,22 +273,22 @@ export class ViewsService {
NcError.viewNotFound(param.viewId); NcError.viewNotFound(param.viewId);
} }
let customUrl: CustomUrl | undefined = await CustomUrl.get(context, { let customUrl: CustomUrl | undefined = await CustomUrl.get({
view_id: view.id, view_id: view.id,
id: view.fk_custom_url_id, id: view.fk_custom_url_id,
}); });
if (customUrl?.id) { if (customUrl?.id) {
if (param.sharedView.custom_url_path) { if (param.sharedView.custom_url_path) {
await CustomUrl.update(context, view.fk_custom_url_id, { await CustomUrl.update(view.fk_custom_url_id, {
custom_path: param.sharedView.custom_url_path, custom_path: param.sharedView.custom_url_path,
}); });
} else { } else {
await CustomUrl.delete(context, { id: view.fk_custom_url_id }); await CustomUrl.delete({ id: view.fk_custom_url_id });
customUrl = undefined; customUrl = undefined;
} }
} else { } else {
customUrl = await CustomUrl.insert(context, { customUrl = await CustomUrl.insert({
fk_workspace_id: view.fk_workspace_id, fk_workspace_id: view.fk_workspace_id,
base_id: view.base_id, base_id: view.base_id,
fk_model_id: view.fk_model_id, fk_model_id: view.fk_model_id,

Loading…
Cancel
Save