Browse Source

fix: review changes

Ramesh Mane 4 days ago
parent
commit
86932966fc
  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 { copy } = useCopy()
const isUpdating = ref({
public: false,
password: false,
@ -104,16 +106,37 @@ const togglePasswordProtected = async () => {
const isOpenCustomUrlLocal = ref(false)
const isOpenCustomUrl = computed(() => {
return !!activeView.value?.password || isOpenCustomUrlLocal.value
return !!activeView.value?.custom_url_path || isOpenCustomUrlLocal.value
})
const customUrl = computed({
get: () => (isOpenCustomUrl.value ? activeView.value?.custom_url_path ?? '' : ''),
set: async (value) => {
if (!activeView.value) return
const customUrl = ref()
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 () => {
@ -121,17 +144,17 @@ const toggleCustomUrl = async () => {
if (!activeView.value) return
if (isUpdating.value.customUrl) return
isUpdating.value.password = true
isUpdating.value.customUrl = true
try {
if (passwordProtected.value) {
activeView.value = { ...(activeView.value as any), custom_url_path: null }
if (isOpenCustomUrl.value) {
customUrl.value = null
} else {
activeView.value = { ...(activeView.value as any), custom_url_path: '' }
customUrl.value = null
}
await updateSharedView()
} 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 () => {
if (!activeView.value?.id) return
@ -328,8 +340,9 @@ async function updateSharedView() {
await $api.dbViewShare.update(activeView.value.id!, {
meta,
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) {
message.error(await extractSdkResponseErrorMsg(e))
}
@ -396,10 +409,20 @@ async function savePreFilledMode() {
size="small"
:bordered="false"
autocomplete="off"
@update:value="updateSharedViewWithDebounce"
/>
<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') }}
</NcButton>
</div>

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

@ -9,8 +9,6 @@ import {
} from '@nestjs/common';
import { GlobalGuard } from '~/guards/global/global.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';
@Controller()
@ -22,23 +20,19 @@ export class CustomUrlsController {
'/api/v1/db/meta/custom-url/:customPath',
'/api/v2/meta/custom-url/:customPath',
])
async getOriginalPath(
@TenantContext() context: NcContext,
@Param('customPath') customPath: string,
) {
await this.customUrlsService.getOriginalPath(context, customPath);
async getOriginalPath(@Param('customPath') customPath: string) {
return await this.customUrlsService.getOriginalPath(customPath);
}
@Post(['/api/v1/db/meta/custom-url/check-path', '/api/v2/meta/check-path'])
@HttpCode(200)
async checkAvailability(
@TenantContext() context: NcContext,
@Body()
body: {
id?: 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,
} from '~/utils/globals';
import NocoCache from '~/cache/NocoCache';
import { NcContext } from 'src/interface/config';
import { NcError } from 'src/helpers/catchError';
export default class CustomUrl {
id?: string;
@ -23,7 +23,6 @@ export default class CustomUrl {
}
public static async get(
_context: NcContext,
params: Pick<CustomUrl, 'id' | 'view_id' | 'custom_path'>,
ncMeta = Noco.ncMeta,
) {
@ -40,7 +39,6 @@ export default class CustomUrl {
}
public static async getOriginUrlByCustomPath(
_context: NcContext,
customPath: string,
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(
_context: NcContext,
customUrl: Partial<CustomUrl>,
ncMeta = Noco.ncMeta,
) {
@ -94,7 +93,6 @@ export default class CustomUrl {
}
public static async list(
_context: NcContext,
params: Pick<CustomUrl, 'fk_workspace_id' | 'base_id' | 'fk_model_id'>,
ncMeta = Noco.ncMeta,
) {
@ -117,7 +115,6 @@ export default class CustomUrl {
}
public static async update(
_context: NcContext,
id: string,
customUrl: Partial<CustomUrl>,
ncMeta = Noco.ncMeta,
@ -137,7 +134,6 @@ export default class CustomUrl {
}
public static async checkAvailability(
_context: NcContext,
params: Pick<CustomUrl, 'id' | 'custom_path'>,
ncMeta = Noco.ncMeta,
) {
@ -165,7 +161,6 @@ export default class CustomUrl {
}
static async delete(
_context: NcContext,
customUrl: Pick<CustomUrl, 'id' | 'view_id'>,
ncMeta = Noco.ncMeta,
) {

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

@ -131,7 +131,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, {
const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@ -181,7 +181,7 @@ export default class View implements ViewType {
if (view) {
if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, {
const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@ -229,7 +229,7 @@ export default class View implements ViewType {
if (view) {
view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, {
const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@ -268,7 +268,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) {
const customUrl = await CustomUrl.get(context, {
const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@ -1283,7 +1283,7 @@ export default class View implements ViewType {
viewId,
);
await CustomUrl.delete(context, { view_id: viewId });
await CustomUrl.delete({ view_id: viewId });
await NocoCache.update(`${CacheScope.VIEW}:${viewId}`, {
uuid: null,
@ -1448,7 +1448,7 @@ export default class View implements ViewType {
}
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

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

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

@ -7,14 +7,11 @@ import CustomUrl from 'src/models/CustomUrl';
export class CustomUrlsService {
constructor(private readonly appHooksService: AppHooksService) {}
async checkAvailability(
context: NcContext,
params: Pick<CustomUrl, 'id' | 'custom_path'>,
) {
return await CustomUrl.checkAvailability(context, params);
async checkAvailability(params: Pick<CustomUrl, 'id' | 'custom_path'>) {
return await CustomUrl.checkAvailability(params);
}
async getOriginalPath(context: NcContext, custom_path: string) {
return await CustomUrl.getOriginUrlByCustomPath(context, custom_path);
async getOriginalPath(custom_path: string) {
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);
}
let customUrl: CustomUrl | undefined = await CustomUrl.get(context, {
let customUrl: CustomUrl | undefined = await CustomUrl.get({
view_id: view.id,
id: view.fk_custom_url_id,
});
if (customUrl?.id) {
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,
});
} else {
await CustomUrl.delete(context, { id: view.fk_custom_url_id });
await CustomUrl.delete({ id: view.fk_custom_url_id });
customUrl = undefined;
}
} else {
customUrl = await CustomUrl.insert(context, {
customUrl = await CustomUrl.insert({
fk_workspace_id: view.fk_workspace_id,
base_id: view.base_id,
fk_model_id: view.fk_model_id,

Loading…
Cancel
Save