Skip to content

Commit

Permalink
feat(#117): properly disable features in explorer menu based on enabl…
Browse files Browse the repository at this point in the history
…ed apis and readonly flag of server
  • Loading branch information
lukashornych committed Oct 1, 2024
1 parent 82f5bd9 commit 6d560d0
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Immutable from 'immutable'
import { Readiness } from '@/modules/connection/model/status/Readiness'
import { ApiStatus } from '@/modules/connection/model/status/ApiStatus'
import { Endpoint } from '@/modules/connection/model/status/Endpoint'
import { ApiType } from '@/modules/connection/model/status/ApiType'

/**
* Convert server status from gRPC to evitaLab representation.
Expand All @@ -30,6 +31,7 @@ export class ServerStatusConverter {
serverStatus.instanceId,
serverStatus.catalogsCorrupted,
serverStatus.catalogsOk,
serverStatus.readOnly,
this.convertHealthProblems(serverStatus.healthProblems),
this.convertReadiness(serverStatus.readiness),
this.convertApis(serverStatus.api)
Expand Down
33 changes: 18 additions & 15 deletions src/modules/connection/explorer/component/CatalogItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import {
import VTreeViewItem from '@/modules/base/component/VTreeViewItem.vue'
import VTreeViewEmptyItem from '@/modules/base/component/VTreeViewEmptyItem.vue'
import CollectionItem from '@/modules/connection/explorer/component/CollectionItem.vue'
import { provideCatalog, useConnection } from '@/modules/connection/explorer/component/dependecies'
import { provideCatalog, useConnection, useServerStatus } from '@/modules/connection/explorer/component/dependecies'
import { MenuItem } from '@/modules/base/model/menu/MenuItem'
import { MenuSubheader } from '@/modules/base/model/menu/MenuSubheader'
import { EvitaLabConfig, useEvitaLabConfig } from '@/modules/config/EvitaLabConfig'
import RenameCatalogDialog from '@/modules/connection/explorer/component/RenameCatalogDialog.vue'
import DropCatalogDialog from '@/modules/connection/explorer/component/DropCatalogDialog.vue'
import ReplaceCatalogDialog from '@/modules/connection/explorer/component/ReplaceCatalogDialog.vue'
Expand All @@ -44,8 +43,9 @@ import {
import { ItemFlag } from '@/modules/base/model/tree-view/ItemFlag'
import { EntityCollection } from '@/modules/connection/model/EntityCollection'
import Immutable from 'immutable'
import { ServerStatus } from '@/modules/connection/model/status/ServerStatus'
import { ApiType } from '@/modules/connection/model/status/ApiType'
const evitaLabConfig: EvitaLabConfig = useEvitaLabConfig()
const workspaceService: WorkspaceService = useWorkspaceService()
const evitaQLConsoleTabFactory: EvitaQLConsoleTabFactory = useEvitaQLConsoleTabFactory()
const graphQLConsoleTabFactory: GraphQLConsoleTabFactory = useGraphQLConsoleTabFactory()
Expand All @@ -57,6 +57,7 @@ const props = defineProps<{
catalog: Catalog
}>()
const emit = defineEmits<{ (e: 'change'): void }>()
const serverStatus: Ref<ServerStatus | undefined> = useServerStatus()
const showRenameCatalogDialog = ref<boolean>(false)
const showReplaceCatalogDialog = ref<boolean>(false)
Expand Down Expand Up @@ -97,6 +98,10 @@ function handleAction(action: string): void {
}
function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
const graphQlEnabled: boolean = serverStatus.value != undefined && serverStatus.value.apiEnabled(ApiType.GraphQL)
const catalogNotCorrupted: boolean = !props.catalog.corrupted
const serverWritable: boolean = serverStatus.value != undefined && !serverStatus.value.readOnly
const actions: Map<CatalogItemType, MenuItem<CatalogItemType>> = new Map()
actions.set(
CatalogItemType.OpenEvitaQLConsole,
Expand All @@ -111,7 +116,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
)
)
},
!props.catalog.corrupted
catalogNotCorrupted
)
)
actions.set(
Expand All @@ -128,7 +133,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
)
)
},
!props.catalog.corrupted
catalogNotCorrupted && graphQlEnabled
)
)
actions.set(
Expand All @@ -145,7 +150,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
)
)
},
!props.catalog.corrupted
catalogNotCorrupted && graphQlEnabled
)
)
actions.set(
Expand All @@ -161,7 +166,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
)
)
},
!props.catalog.corrupted
catalogNotCorrupted
)
)
Expand All @@ -180,9 +185,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
backupsService.createNew(connection, props.catalog.name, false)
)
},
// todo lho: discuss if we want to disable backuping without restoring
// todo lho: readonly flag must be on connection
!props.catalog.corrupted && !evitaLabConfig.readOnly
catalogNotCorrupted && serverWritable
)
)
Expand All @@ -196,7 +199,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
CatalogItemType.RenameCatalog,
'mdi-pencil-outline',
() => showRenameCatalogDialog.value = true,
!props.catalog.corrupted && !evitaLabConfig.readOnly
catalogNotCorrupted && serverWritable
)
)
actions.set(
Expand All @@ -205,7 +208,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
CatalogItemType.ReplaceCatalog,
'mdi-file-replace-outline',
() => showReplaceCatalogDialog.value = true,
!props.catalog.corrupted && !evitaLabConfig.readOnly
catalogNotCorrupted && serverWritable
)
)
if (props.catalog.isInWarmup) {
Expand All @@ -215,7 +218,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
CatalogItemType.SwitchCatalogToAliveState,
'mdi-toggle-switch-outline',
() => showSwitchCatalogToAliveStateDialog.value = true,
!props.catalog.corrupted && !evitaLabConfig.readOnly
catalogNotCorrupted && serverWritable
)
)
}
Expand All @@ -225,7 +228,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
CatalogItemType.DropCatalog,
'mdi-delete-outline',
() => showDropCatalogDialog.value = true,
!evitaLabConfig.readOnly
serverWritable
)
)
Expand All @@ -240,7 +243,7 @@ function createActions(): Map<CatalogItemType, MenuItem<CatalogItemType>> {
CatalogItemType.CreateCollection,
'mdi-plus',
() => showCreateCollectionDialog.value = true,
!props.catalog.corrupted && !evitaLabConfig.readOnly
catalogNotCorrupted && serverWritable
)
)
return new Map(actions)
Expand Down
29 changes: 13 additions & 16 deletions src/modules/connection/explorer/component/CollectionItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,29 @@ import {
EntityViewerTabFactory,
useEntityViewerTabFactory
} from '@/modules/entity-viewer/viewer/workspace/service/EntityViewerTabFactory'
import { useCatalog, useConnection } from '@/modules/connection/explorer/component/dependecies'
import { useCatalog, useConnection, useServerStatus } from '@/modules/connection/explorer/component/dependecies'
import { UnexpectedError } from '@/modules/base/exception/UnexpectedError'
import VTreeViewItem from '@/modules/base/component/VTreeViewItem.vue'
import { EntityCollection } from '../../model/EntityCollection'
import { EvitaLabConfig, useEvitaLabConfig } from '@/modules/config/EvitaLabConfig'
import { computed, ref } from 'vue'
import { computed, Ref, ref } from 'vue'
import { MenuSubheader } from '@/modules/base/model/menu/MenuSubheader'
import { MenuItem } from '@/modules/base/model/menu/MenuItem'
import DropCollectionDialog from '@/modules/connection/explorer/component/DropCollectionDialog.vue'
import RenameCollectionDialog from '@/modules/connection/explorer/component/RenameCollectionDialog.vue'
import { ServerStatus } from '@/modules/connection/model/status/ServerStatus'
const workspaceService: WorkspaceService = useWorkspaceService()
const entityViewerTabFactory: EntityViewerTabFactory =
useEntityViewerTabFactory()
const schemaViewerTabFactory: SchemaViewerTabFactory =
useSchemaViewerTabFactory()
const entityViewerTabFactory: EntityViewerTabFactory = useEntityViewerTabFactory()
const schemaViewerTabFactory: SchemaViewerTabFactory = useSchemaViewerTabFactory()
const { t } = useI18n()
const evitaLabConfig: EvitaLabConfig = useEvitaLabConfig()
const props = defineProps<{
entityCollection: EntityCollection
}>()
const emit = defineEmits<{
(e: 'change'): void
}>()
const serverStatus: Ref<ServerStatus | undefined> = useServerStatus()
const showDropCollectionDialog = ref<boolean>(false)
const showRenameCollectionDialog = ref<boolean>(false)
Expand Down Expand Up @@ -77,10 +75,9 @@ function handleAction(action: string) {
}
}
function createActions(): Map<
CollectionActionType,
MenuItem<CollectionActionType>
> {
function createActions(): Map<CollectionActionType, MenuItem<CollectionActionType>> {
const serverWritable: boolean = serverStatus.value != undefined && !serverStatus.value.readOnly
const actions: Map<CollectionActionType, MenuItem<CollectionActionType>> = new Map()
actions.set(
CollectionActionType.ViewEntities,
Expand Down Expand Up @@ -118,7 +115,7 @@ function createActions(): Map<
CollectionActionType.RenameCollection,
'mdi-pencil-outline',
() => showRenameCollectionDialog.value = true,
evitaLabConfig.readOnly
serverWritable
)
)
actions.set(
Expand All @@ -127,7 +124,7 @@ function createActions(): Map<
CollectionActionType.DropCollection,
'mdi-delete-outline',
() => showDropCollectionDialog.value = true,
evitaLabConfig.readOnly
serverWritable
)
)
return actions
Expand All @@ -137,15 +134,15 @@ function createMenuAction(
actionType: CollectionActionType,
prependIcon: string,
execute: () => void,
disabled?: boolean
enabled: boolean = true
): MenuAction<CollectionActionType> {
return new MenuAction(
actionType,
t(`explorer.collection.actions.${actionType}`),
prependIcon,
execute,
undefined,
disabled
!enabled
)
}
</script>
Expand Down
Loading

0 comments on commit 6d560d0

Please sign in to comment.