mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 17:23:37 +00:00
[PM-7162] Cipher Form - Item Details (#9758)
* [PM-7162] Fix weird angular error regarding disabled component bit-select * [PM-7162] Introduce CipherFormConfigService and related types * [PM-7162] Introduce CipherFormService * [PM-7162] Introduce the Item Details section component and the CipherFormContainer interface * [PM-7162] Introduce the CipherForm component * [PM-7162] Add strongly typed QueryParams to the add-edit-v2.component * [PM-7162] Export CipherForm from Vault Lib * [PM-7162] Use the CipherForm in Browser AddEditV2 * [PM-7162] Introduce CipherForm storybook * [PM-7162] Remove VaultPopupListFilterService dependency from NewItemDropDownV2 component * [PM-7162] Add support for content projection of attachment button * [PM-7162] Fix typo * [PM-7162] Cipher form service cleanup * [PM-7162] Move readonly collection notice to bit-hint * [PM-7162] Refactor CipherFormConfig type to enforce required properties with Typescript * [PM-7162] Fix storybook after config changes * [PM-7162] Use new add-edit component for clone route
This commit is contained in:
@@ -0,0 +1,135 @@
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { CipherId, CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
|
||||
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
|
||||
/**
|
||||
* The mode of the add/edit form.
|
||||
* - `add` - The form is creating a new cipher.
|
||||
* - `edit` - The form is editing an existing cipher.
|
||||
* - `partial-edit` - The form is editing an existing cipher, but only the favorite/folder fields
|
||||
* - `clone` - The form is creating a new cipher that is a clone of an existing cipher.
|
||||
*/
|
||||
export type CipherFormMode = "add" | "edit" | "partial-edit" | "clone";
|
||||
|
||||
/**
|
||||
* Optional initial values for the form.
|
||||
*/
|
||||
export type OptionalInitialValues = {
|
||||
folderId?: string;
|
||||
organizationId?: OrganizationId;
|
||||
collectionIds?: CollectionId[];
|
||||
loginUri?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Base configuration object for the cipher form. Includes all common fields.
|
||||
*/
|
||||
type BaseCipherFormConfig = {
|
||||
/**
|
||||
* The mode of the form.
|
||||
*/
|
||||
mode: CipherFormMode;
|
||||
|
||||
/**
|
||||
* The type of cipher to create/edit.
|
||||
*/
|
||||
cipherType: CipherType;
|
||||
|
||||
/**
|
||||
* Flag to indicate the form should submit to admin endpoints that have different permission checks. If the
|
||||
* user is not an admin or performing an action that requires admin permissions, this should be false.
|
||||
*/
|
||||
admin: boolean;
|
||||
|
||||
/**
|
||||
* Flag to indicate if the user is allowed to create ciphers in their own Vault. If false, configuration must
|
||||
* supply a list of organizations that the user can create ciphers in.
|
||||
*/
|
||||
allowPersonalOwnership: boolean;
|
||||
|
||||
/**
|
||||
* The original cipher that is being edited or cloned. This can be undefined when creating a new cipher.
|
||||
*/
|
||||
originalCipher?: Cipher;
|
||||
|
||||
/**
|
||||
* Optional initial values for the form when creating a new cipher. Useful when creating a cipher in a filtered view.
|
||||
*/
|
||||
initialValues?: OptionalInitialValues;
|
||||
|
||||
/**
|
||||
* The list of collections that the user has visibility to. This list should include read-only collections as they
|
||||
* can still be displayed in the component for reference.
|
||||
*/
|
||||
collections: CollectionView[];
|
||||
|
||||
/**
|
||||
* The list of folders for the current user. Should include the "No Folder" option with a `null` id.
|
||||
*/
|
||||
folders: FolderView[];
|
||||
|
||||
/**
|
||||
* List of organizations that the user can create ciphers for.
|
||||
*/
|
||||
organizations?: Organization[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form when editing/cloning an existing cipher.
|
||||
*/
|
||||
type ExistingCipherConfig = BaseCipherFormConfig & {
|
||||
mode: "edit" | "partial-edit" | "clone";
|
||||
originalCipher: Cipher;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form when creating a completely new cipher.
|
||||
*/
|
||||
type CreateNewCipherConfig = BaseCipherFormConfig & {
|
||||
mode: "add";
|
||||
};
|
||||
|
||||
type CombinedAddEditConfig = ExistingCipherConfig | CreateNewCipherConfig;
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form when personal ownership is allowed.
|
||||
*/
|
||||
type PersonalOwnershipAllowed = CombinedAddEditConfig & {
|
||||
allowPersonalOwnership: true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form when personal ownership is not allowed.
|
||||
* Organizations must be provided.
|
||||
*/
|
||||
type PersonalOwnershipNotAllowed = CombinedAddEditConfig & {
|
||||
allowPersonalOwnership: false;
|
||||
organizations: Organization[];
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form.
|
||||
* Determines the behavior of the form and the controls that are displayed/enabled.
|
||||
*/
|
||||
export type CipherFormConfig = PersonalOwnershipAllowed | PersonalOwnershipNotAllowed;
|
||||
|
||||
/**
|
||||
* Service responsible for building the configuration object for the cipher form.
|
||||
*/
|
||||
export abstract class CipherFormConfigService {
|
||||
/**
|
||||
* Builds the configuration for the cipher form using the specified mode, cipherId, and cipherType.
|
||||
* The other configuration fields will be fetched from their respective services.
|
||||
* @param mode
|
||||
* @param cipherId
|
||||
* @param cipherType
|
||||
*/
|
||||
abstract buildConfig(
|
||||
mode: CipherFormMode,
|
||||
cipherId?: CipherId,
|
||||
cipherType?: CipherType,
|
||||
): Promise<CipherFormConfig>;
|
||||
}
|
||||
Reference in New Issue
Block a user