mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-23 10:05:01 +02:00
Add action to add new product version (#10865)
Signed-off-by: Artem Savchenko <armisav@gmail.com>
This commit is contained in:
@@ -254,6 +254,21 @@ function defineProduct (builder: Builder): void {
|
||||
builder.mixin(products.class.Product, core.class.Class, view.mixin.IgnoreActions, {
|
||||
actions: [tracker.action.NewRelatedIssue]
|
||||
})
|
||||
|
||||
createAction(
|
||||
builder,
|
||||
{
|
||||
action: products.actionImpl.CreateProductVersion,
|
||||
label: products.string.CreateProductVersion,
|
||||
icon: products.icon.ProductVersion,
|
||||
visibilityTester: products.function.CanCreateProductVersion,
|
||||
category: view.category.General,
|
||||
input: 'focus',
|
||||
target: products.class.Product,
|
||||
context: { mode: ['context', 'browser'], group: 'create' }
|
||||
},
|
||||
products.action.CreateProductVersion
|
||||
)
|
||||
}
|
||||
|
||||
function defineSpaceType (builder: Builder): void {
|
||||
|
||||
@@ -19,12 +19,16 @@ import products from '@hcengineering/products-resources/src/plugin'
|
||||
import type { Client, Doc, Ref, Role } from '@hcengineering/core'
|
||||
import { type Resource, mergeIds } from '@hcengineering/platform'
|
||||
import { type AnyComponent } from '@hcengineering/ui/src/types'
|
||||
import type { Action } from '@hcengineering/view'
|
||||
import type { Action, ViewAction } from '@hcengineering/view'
|
||||
|
||||
export default mergeIds(productsId, products, {
|
||||
action: {
|
||||
CreateProductVersion: '' as Ref<Action<Doc, any>>,
|
||||
DeleteProductVersion: '' as Ref<Action<Doc, any>>
|
||||
},
|
||||
actionImpl: {
|
||||
CreateProductVersion: '' as ViewAction
|
||||
},
|
||||
ids: {
|
||||
ModulePermissionGroup: '' as Ref<Doc>,
|
||||
ModulePermissionGroupReadOnlyGuest: '' as Ref<Doc>
|
||||
@@ -44,6 +48,7 @@ export default mergeIds(productsId, products, {
|
||||
ProductVersionVersionPresenter: '' as AnyComponent
|
||||
},
|
||||
function: {
|
||||
CanCreateProductVersion: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
|
||||
CanDeleteProductVersion: '' as Resource<(doc?: Doc | Doc[]) => Promise<boolean>>,
|
||||
ProductIdentifierProvider: '' as Resource<<T extends Doc>(client: Client, ref: Ref<T>, doc?: T) => Promise<string>>
|
||||
},
|
||||
|
||||
@@ -34,7 +34,13 @@ import ProductVersionsPresenter from './components/product-version/ProductVersio
|
||||
import ProductVersionStateEditor from './components/product-version/ProductVersionStateEditor.svelte'
|
||||
import ProductVersionStatePresenter from './components/product-version/ProductVersionStatePresenter.svelte'
|
||||
import ProductVersionVersionPresenter from './components/product-version/ProductVersionVersionPresenter.svelte'
|
||||
import { canDeleteProductVersion, getVisibleFilters, productIdentifierProvider } from './utils'
|
||||
import {
|
||||
canCreateProductVersion,
|
||||
canDeleteProductVersion,
|
||||
createProductVersion,
|
||||
getVisibleFilters,
|
||||
productIdentifierProvider
|
||||
} from './utils'
|
||||
|
||||
const toObjectSearchResult = (e: WithLookup<Product>): ObjectSearchResult => ({
|
||||
doc: e,
|
||||
@@ -86,7 +92,11 @@ export default async (): Promise<Resources> => ({
|
||||
},
|
||||
function: {
|
||||
GetVisibleFilters: getVisibleFilters,
|
||||
CanCreateProductVersion: canCreateProductVersion,
|
||||
CanDeleteProductVersion: canDeleteProductVersion,
|
||||
ProductIdentifierProvider: productIdentifierProvider
|
||||
},
|
||||
actionImpl: {
|
||||
CreateProductVersion: createProductVersion
|
||||
}
|
||||
})
|
||||
|
||||
@@ -21,10 +21,13 @@ import core, {
|
||||
getCurrentAccount
|
||||
} from '@hcengineering/core'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { showPopup } from '@hcengineering/ui'
|
||||
import { type KeyFilter } from '@hcengineering/view'
|
||||
import documents from '@hcengineering/controlled-documents'
|
||||
import products, { ProductVersionState, type Product, type ProductVersion } from '@hcengineering/products'
|
||||
|
||||
import CreateProductVersion from './components/product-version/CreateProductVersion.svelte'
|
||||
|
||||
export function getProductVersionVersion (doc: ProductVersion): string {
|
||||
const codename = doc.codename ?? ''
|
||||
const version = `${doc.major}.${doc.minor}.${doc.patch}`
|
||||
@@ -79,6 +82,35 @@ export async function canEditProductVersion (doc?: WithLookup<ProductVersion>):
|
||||
return await canEditProduct(product)
|
||||
}
|
||||
|
||||
export async function canCreateProductVersion (doc?: Product | Product[]): Promise<boolean> {
|
||||
if (doc === null || doc === undefined) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (Array.isArray(doc)) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (doc.archived) {
|
||||
return false
|
||||
}
|
||||
|
||||
return await canEditProduct(doc)
|
||||
}
|
||||
|
||||
export async function createProductVersion (doc?: Product | Product[]): Promise<void> {
|
||||
if (doc === null || doc === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const product = Array.isArray(doc) ? doc[0] : doc
|
||||
if (product === undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
showPopup(CreateProductVersion, { space: product._id }, 'top')
|
||||
}
|
||||
|
||||
export async function canDeleteProductVersion (doc?: ProductVersion | ProductVersion[]): Promise<boolean> {
|
||||
if (doc === null || doc === undefined) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user