刘光辉
2 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { FieldReadSource, FieldScope, FieldVersionStatus } from '#/api/x/eln/fields';
 
export type FieldAction = 'disable' | 'enable' | 'promoteGlobal' | 'versions';
export type VersionAction = 'cancel' | 'copy' | 'edit' | 'preRelease' | 'publish' | 'setCurrent';
 
export function versionActions(input: { current: boolean; enabled: boolean; status: FieldVersionStatus }): VersionAction[] {
  if (!input.enabled) return input.status === 'DRAFT' || input.status === 'PRE_RELEASE' ? ['cancel'] : [];
  if (input.status === 'DRAFT') return ['edit', 'preRelease', 'cancel'];
  if (input.status === 'PRE_RELEASE') return ['publish', 'cancel', 'copy'];
  if (input.status === 'PUBLISHED') return input.current ? ['copy'] : ['setCurrent', 'copy'];
  return [];
}
 
export function fieldActions(input: { enabled: boolean; scope: FieldScope }): FieldAction[] {
  if (!input.enabled) return ['versions', 'enable'];
  const actions: FieldAction[] = ['versions'];
  if (input.scope === 'TEMPLATE') actions.push('promoteGlobal');
  actions.push('disable');
  return actions;
}
 
export function canUseBatchShared(input: { readSource: FieldReadSource }): boolean {
  return input.readSource === 'NONE';
}