2022-02-08 15:23:14 +00:00
|
|
|
import * as UserType from 'app/client/widgets/UserType';
|
|
|
|
import {ColumnToMap} from 'app/plugin/CustomSectionAPI';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper that wraps custom widget's column definition and expands all the defaults.
|
|
|
|
*/
|
|
|
|
export class ColumnToMapImpl implements Required<ColumnToMap> {
|
|
|
|
// Name of the column Custom Widget expects.
|
|
|
|
public name: string;
|
|
|
|
// Label to show instead of the name.
|
|
|
|
public title: string;
|
2022-08-26 12:25:34 +00:00
|
|
|
// Human description of the column.
|
|
|
|
public description: string;
|
2022-02-08 15:23:14 +00:00
|
|
|
// If column is optional (used only on the UI).
|
|
|
|
public optional: boolean;
|
2023-09-13 10:29:36 +00:00
|
|
|
// Type of the column that widget expects. Might be a single or a comma separated list of types.
|
2022-02-08 15:23:14 +00:00
|
|
|
public type: string;
|
|
|
|
// Description of the type (used to show a placeholder).
|
|
|
|
public typeDesc: string;
|
|
|
|
// Allow multiple column assignment (like Series in Charts).
|
|
|
|
public allowMultiple: boolean;
|
|
|
|
constructor(def: string|ColumnToMap) {
|
|
|
|
this.name = typeof def === 'string' ? def : def.name;
|
|
|
|
this.title = typeof def === 'string' ? def : (def.title ?? def.name);
|
2022-08-26 12:25:34 +00:00
|
|
|
this.description = typeof def === 'string' ? '' : (def.description ?? '');
|
2022-02-08 15:23:14 +00:00
|
|
|
this.optional = typeof def === 'string' ? false : (def.optional ?? false);
|
|
|
|
this.type = typeof def === 'string' ? 'Any' : (def.type ?? 'Any');
|
|
|
|
this.typeDesc = String(UserType.typeDefs[this.type]?.label ?? "any").toLowerCase();
|
|
|
|
this.allowMultiple = typeof def === 'string' ? false : (def.allowMultiple ?? false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does the column type matches this definition.
|
|
|
|
*/
|
|
|
|
public canByMapped(pureType: string) {
|
2023-09-13 10:29:36 +00:00
|
|
|
return this.type.split(',').includes(pureType)
|
2022-02-08 15:23:14 +00:00
|
|
|
|| pureType === "Any"
|
|
|
|
|| this.type === "Any";
|
|
|
|
}
|
|
|
|
}
|