Browse Source

code cleanup

pull/4898/head
Daniel Spaude 2 years ago
parent
commit
37ed1e5bb0
No known key found for this signature in database
GPG Key ID: 654A3D1FA4F35FFE
  1. 26
      packages/nc-gui/components/smartsheet/expanded-form/Header.vue
  2. 61
      packages/nc-gui/components/smartsheet/sidebar/mobile.vue
  3. 2
      packages/nc-gui/components/virtual-cell/QrCode.vue
  4. 52
      packages/nc-gui/composables/useViewData.ts
  5. 4
      packages/nc-gui/composables/useViews.ts

26
packages/nc-gui/components/smartsheet/expanded-form/Header.vue

@ -1,6 +1,6 @@
<script lang="ts" setup>
import { message } from 'ant-design-vue'
import type { KanbanType, ViewType } from 'nocodb-sdk'
import type { ViewType } from 'nocodb-sdk'
import {
ReloadRowDataHookInj,
isMac,
@ -42,8 +42,6 @@ const save = async () => {
}
}
// const FOO: KanbanType
// todo: accept as a prop / inject
const iconColor = '#1890ff'
@ -75,19 +73,12 @@ useEventListener(document, 'keydown', async (e: KeyboardEvent) => {
}
})
const { deleteRowById, addEmptyRow } = useViewData(meta, ref(props.view))
// const onDuplicateRowClick = async () => {
// // const newRow = duplicateRowById(primaryKey.value)
// // console.log('newRow', newRow)
// const newRow = await addEmptyRow()
// // expandForm(newRow)
// }
const showDeleteRowModal = ref(false)
const { deleteRowById } = useViewData(meta, ref(props.view))
const onDeleteRowClick = () => {
// alert('deleteRow')
showDeleteRowModal.value = true
}
@ -97,16 +88,7 @@ const onConfirmDeleteRowClick = async () => {
reloadTrigger.trigger()
emit('cancel')
message.success('Row deleted')
// loadData()
// deleteRow
}
// const { deleteRowById, loadData } = useViewData(meta, view)
// const onClickDelete = async () => {
// await deleteRowById(primaryKey)
// loadData()
// }
</script>
<template>
@ -162,8 +144,6 @@ const onConfirmDeleteRowClick = async () => {
</div>
</a-button>
<!-- <SmartsheetExpandedFormMoreActions :meta="meta" :view="view" :primaryKey="primaryKey" /> -->
<a-dropdown>
<a-button v-e="['c:actions']" class="nc-actions-menu-btn nc-toolbar-btn">
<div class="flex gap-1 items-center">

61
packages/nc-gui/components/smartsheet/sidebar/mobile.vue

@ -3,7 +3,6 @@ import type { ViewType, ViewTypes } from 'nocodb-sdk'
import {
ActiveViewInj,
MetaInj,
computed,
inject,
ref,
resolveComponent,
@ -11,7 +10,6 @@ import {
useNuxtApp,
useRoute,
useRouter,
useSidebar,
useUIPermission,
useViewsStoreOrThrow,
watch,
@ -43,34 +41,15 @@ const route = useRoute()
const { $e } = useNuxtApp()
/** Sidebar visible */
// const { isOpen } = useSidebar('nc-right-sidebar')
// const FOO = useSidebar('nc-right-sidebar')
// FOO.
// const sidebarCollapsed = computed(() => !isOpen.value || isMobileMode.value)
// const sidebarCollapsed = false
/** Sidebar ref */
// const sidebar = ref()
/** Watch route param and change active view based on `viewTitle` */
watch(
[views, () => route.params.viewTitle],
([nextViews, viewTitle]) => {
// debugger
// alert('mobile watcher')
const lastOpenedViewId = activeTab.value?.id && lastOpenedViewMap.value[activeTab.value?.id]
console.log('lastOpenedViewId', lastOpenedViewId)
const lastOpenedView = nextViews.find((v) => v.id === lastOpenedViewId)
console.log('lastOpenedView', lastOpenedView)
// debugger
console.log('viewTitle', viewTitle)
if (viewTitle) {
let view = nextViews.find((v) => v.title === viewTitle)
console.log('view', view)
if (view) {
activeView.value = view
setLastOpenedViewId(activeView.value?.id)
@ -85,8 +64,7 @@ watch(
})
}
}
}
else if (lastOpenedView) {
} else if (lastOpenedView) {
/** if active view is not found, set it to last opened view */
router.replace({
params: {
@ -150,49 +128,14 @@ function onOpenModal({
</script>
<template>
<!-- <div> -->
<!-- Mobile Views Menu <br />
views: {{ views.length }} -->
<!-- <a-layout-sider
ref="sidebar"
:collapsed="sidebarCollapsed"
collapsiple
collapsed-width="0"
width="0"
class="nc-view-sidebar relative shadow h-full w-full !flex-1 !min-w-0 !max-w-[150px] !w-[150px] lg:(!max-w-[250px] !w-[250px])"
theme="light"
> -->
<!-- <LazySmartsheetSidebarToolbar
class="min-h-[var(--toolbar-height)] max-h-[var(--toolbar-height)] flex items-center py-3 px-3 justify-between border-b-1"
/> -->
<div class="flex items-center inline m-4">
<!-- <div>OUTER INDEX - isOpen: {{ isOpen }}</div> -->
<MdiBackburger
v-e="['c:grid:toggle-navdraw']"
class="cursor-pointer transform transition-transform duration-500"
@click="emits('closeMobileViewsSidebar')"
/>
<!-- <div
class="min-h-[var(--toolbar-height)] max-h-[var(--toolbar-height)] flex items-center py-3 px-3 justify-between border-b-1 inline"
> -->
<!-- <div class="flex gap-2 justify-start">
<div class="flex items-center gap-1 text-xs"> -->
<!-- <div :class="{ 'nc-active-btn': isOpen }"> -->
<span class="ml-2 text-bold uppercase text-gray-500 font-weight-bold">{{ meta?.title }}</span>
<!-- <a-button size="small" class="nc-toggle-right-navbar" @click="onClick">
<div class="flex items-center gap-1 text-xs" :class="{ 'text-gray-500': !isOpen }">
<AntDesignMenuUnfoldOutlined v-if="isOpen" />
<AntDesignMenuFoldOutlined v-else />
{{ $t('objects.views') }}
</div>
</a-button> -->
<!-- </div>
</div> -->
<!-- </div> -->
</div>
<div class="flex-1 flex flex-col min-h-0">
@ -210,8 +153,6 @@ function onOpenModal({
<LazySmartsheetSidebarMenuBottom @open-modal="onOpenModal" />
</template>
</div>
<!-- </a-layout-sider> -->
<!-- </div> -->
</template>
<style scoped>

2
packages/nc-gui/components/virtual-cell/QrCode.vue

@ -14,8 +14,6 @@ const showQrCode = computed(() => qrValue?.value?.length > 0 && !tooManyCharsFor
const qrCodeOptions: QRCode.QRCodeToDataURLOptions = {
errorCorrectionLevel: 'M',
// type: 'image/png',
// quality: 0.92,
margin: 1,
version: 4,
rendererOpts: {

52
packages/nc-gui/composables/useViewData.ts

@ -33,7 +33,6 @@ const formatData = (list: Row[]) =>
export function useViewData(
meta: Ref<TableType | undefined> | ComputedRef<TableType | undefined>,
// meta: Ref<Omit<TableType, 'table_name'> | undefined> | ComputedRef<Omit<TableType, 'table_name'> | undefined>,
viewMeta: Ref<ViewType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>,
where?: ComputedRef<string | undefined>,
) {
@ -100,7 +99,6 @@ export function useViewData(
}))
function addEmptyRow(addAfter = formattedData.value.length) {
debugger
formattedData.value.splice(addAfter, 0, {
row: {},
oldRow: {},
@ -110,19 +108,6 @@ export function useViewData(
return formattedData.value[addAfter]
}
// // function createNewRowWithDuplicatedValues()
// function duplicateRowById(rowId: string) {
// debugger
// const row = formattedData.value.find((row) => row.row.id === rowId)
// if (row) {
// const newRow = addEmptyRow(formattedData.value.indexOf(row) + 1)
// newRow.row = { ...row.row }
// return newRow
// }
// }
function removeLastEmptyRow() {
const lastRow = formattedData.value[formattedData.value.length - 1]
@ -355,47 +340,11 @@ export function useViewData(
$e('a:grid:pagination')
}
// async function deleteRow(row: Row) {
// try {
// if (!row.rowMeta.new) {
// const id = (meta?.value?.columns as ColumnType[])
// ?.filter((c) => c.pk)
// .map((c) => row.row[c.title!])
// .join('___')
// const deleted = await deleteRowById(id as string)
// if (!deleted) {
// return
// }
// }
// // remove deleted row from state
// removeRowFromTargetStack(row)
// } catch (e: any) {
// message.error(`${t('msg.error.deleteRowFailed')}: ${await extractSdkResponseErrorMsg(e)}`)
// }
// }
async function deleteRowById(id: string) {
if (!id) {
throw new Error("Delete not allowed for table which doesn't have primary Key")
}
const projetId = project.value.id
const metaId = meta.value.id
console.log('FOOBAR viewMeta', viewMeta)
// console.log('FOOBAR viewMeta.id', viewMeta.id)
console.log('FOOBAR viewMeta.value', viewMeta.value)
console.log('FOOBAR viewMeta.value.id', viewMeta.value.id)
const viewMetaId = viewMeta?.value?.id
console.log('FOOBAR projetId', projetId)
console.log('FOOBAR metaId', metaId)
console.log('FOOBAR viewMetaId', viewMetaId)
console.log('FOOBAR id', id)
const res: any = await $api.dbViewRow.delete(
'noco',
project.value.id as string,
@ -542,7 +491,6 @@ export function useViewData(
updateFormView,
aggCommentCount,
loadAggCommentsCount,
// duplicateRowById,
removeLastEmptyRow,
removeRowIfNew,
}

4
packages/nc-gui/composables/useViews.ts

@ -3,16 +3,12 @@ import type { MaybeRef } from '@vueuse/core'
import { ref, unref, useNuxtApp, watch } from '#imports'
const [useProvideViewsStore, useViewsStore] = useInjectionState((meta: MaybeRef<TableType | undefined>) => {
// debugger
// console.log('--------------------useViews--------------------')
// console.trace()
const views = ref<ViewType[]>([])
const isLoading = ref(false)
const { $api } = useNuxtApp()
const loadViews = async () => {
// debugger
isLoading.value = true
const _meta = unref(meta)

Loading…
Cancel
Save