1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-19 01:33:33 +00:00

[PM-9926] Linked Fields order (#10174)

* refactor linkedFieldOption to take in an attributes object

* add sort positions for existing linked fields

* sort linked fields on new custom fields
This commit is contained in:
Nick Krantz
2024-07-23 12:26:02 -05:00
committed by GitHub
parent 88f585e09d
commit decc7a3031
5 changed files with 58 additions and 40 deletions

View File

@@ -1,11 +1,30 @@
import { LinkedIdType } from "./enums";
import { ItemView } from "./models/view/item.view";
type LinkedMetadataAttributes = {
/**
* The i18n key used to describe the decorated class property in the UI.
* If it is null, then the name of the class property will be used as the i18n key.
*/
i18nKey?: string;
/**
* The position of the individual field to be applied when sorted.
*/
sortPosition: number;
};
export class LinkedMetadata {
private readonly _i18nKey: string;
readonly sortPosition: number;
constructor(
readonly propertyKey: string,
private readonly _i18nKey?: string,
) {}
attributes: LinkedMetadataAttributes,
) {
this._i18nKey = attributes?.i18nKey;
this.sortPosition = attributes.sortPosition;
}
get i18nKey() {
return this._i18nKey ?? this.propertyKey;
@@ -16,15 +35,14 @@ export class LinkedMetadata {
* A decorator used to set metadata used by Linked custom fields. Apply it to a class property or getter to make it
* available as a Linked custom field option.
* @param id - A unique value that is saved in the Field model. It is used to look up the decorated class property.
* @param i18nKey - The i18n key used to describe the decorated class property in the UI. If it is null, then the name
* of the class property will be used as the i18n key.
* @param options - {@link LinkedMetadataAttributes}
*/
export function linkedFieldOption(id: LinkedIdType, i18nKey?: string) {
export function linkedFieldOption(id: LinkedIdType, attributes: LinkedMetadataAttributes) {
return (prototype: ItemView, propertyKey: string) => {
if (prototype.linkedFieldOptions == null) {
prototype.linkedFieldOptions = new Map<LinkedIdType, LinkedMetadata>();
}
prototype.linkedFieldOptions.set(id, new LinkedMetadata(propertyKey, i18nKey));
prototype.linkedFieldOptions.set(id, new LinkedMetadata(propertyKey, attributes));
};
}