@adaptabletools/adaptable 14.0.1-canary.0 → 14.0.1-canary.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/bundle.cjs.js +177 -177
  2. package/package.json +1 -1
  3. package/publishTimestamp.d.ts +1 -1
  4. package/publishTimestamp.js +1 -1
  5. package/src/AdaptableOptions/AdaptableFrameworkComponent.d.ts +14 -7
  6. package/src/AdaptableOptions/ChartingOptions.d.ts +6 -0
  7. package/src/AdaptableOptions/ToolPanelOptions.d.ts +1 -1
  8. package/src/Api/Implementation/AlertApiImpl.js +1 -1
  9. package/src/PredefinedConfig/Common/Enums.d.ts +0 -9
  10. package/src/PredefinedConfig/Common/Enums.js +1 -11
  11. package/src/PredefinedConfig/Common/SpecialColumnSettings.d.ts +2 -2
  12. package/src/Strategy/CalculatedColumnModule.js +7 -0
  13. package/src/Strategy/ChartingModule.js +2 -4
  14. package/src/Strategy/FormatColumnModule.d.ts +1 -1
  15. package/src/Strategy/FormatColumnModule.js +11 -3
  16. package/src/Strategy/StyledColumnModule.js +6 -1
  17. package/src/Utilities/Services/CalculatedColumnExpressionService.d.ts +2 -2
  18. package/src/Utilities/Services/CalculatedColumnExpressionService.js +3 -0
  19. package/src/Utilities/Services/Interface/ICalculatedColumnExpressionService.d.ts +2 -2
  20. package/src/View/AdaptableWizardView/AdaptableConfigurationDialog/UIOptions/UiOptionsForm.js +11 -3
  21. package/src/View/CalculatedColumn/Wizard/CalculatedColumnSettingsWizardSection.js +3 -1
  22. package/src/View/Components/Charting/ChartingStatusBarPopover.js +19 -14
  23. package/src/View/Components/Charting/ChartingViewPanel.js +2 -67
  24. package/src/View/Components/Charting/DeleteChartButton.d.ts +1 -0
  25. package/src/View/Components/Charting/DeleteChartButton.js +1 -1
  26. package/src/View/Components/Charting/EditChartButton.d.ts +1 -0
  27. package/src/View/Components/Charting/EditChartButton.js +1 -1
  28. package/src/View/Components/Charting/useChartState.js +14 -9
  29. package/src/View/Components/Charting/useChartingElements.d.ts +14 -0
  30. package/src/View/Components/Charting/useChartingElements.js +90 -0
  31. package/src/View/FreeTextColumn/Wizard/FreeTextColumnSettingsWizardSection.js +4 -3
  32. package/src/View/StyledColumn/Wizard/StyledColumnWizard.js +3 -3
  33. package/src/View/TeamSharing/SharedEntityObjectView.js +5 -4
  34. package/src/agGrid/Adaptable.js +9 -4
  35. package/src/metamodel/adaptable.metamodel.d.ts +27 -2
  36. package/src/metamodel/adaptable.metamodel.js +1 -1
  37. package/version.d.ts +1 -1
  38. package/version.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptabletools/adaptable",
3
- "version": "14.0.1-canary.0",
3
+ "version": "14.0.1-canary.2",
4
4
  "description": "Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements",
5
5
  "keywords": [
6
6
  "web-components",
@@ -1,2 +1,2 @@
1
- declare const _default: 1672558364064;
1
+ declare const _default: 1672852001158;
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = 1672558364064;
3
+ exports.default = 1672852001158;
@@ -1,18 +1,20 @@
1
1
  import { AdaptableApi } from '../Api/AdaptableApi';
2
2
  import { ReactElement } from 'react';
3
+ import { BaseContext } from '../types';
4
+ /**
5
+ * Base Component for Bespoke Components - Can be Angular or React
6
+ */
3
7
  export declare type AdaptableFrameworkComponent = AngularFrameworkComponent | ReactFrameworkComponent;
4
8
  /**
5
- * An Angular component defined by its type and an optional initialisation callback.
9
+ * Angular component defined by its type and (optional) initialisation callback
6
10
  */
7
11
  export declare type AngularFrameworkComponent<T = unknown> = {
8
12
  /**
9
- * The angular component class (instance of https://angular.io/api/core/Type).
10
- * It will be automatically instantiated at runtime and the `adaptableApi` is provided through an Injection token
13
+ * Angular component class (instance of https://angular.io/api/core/Type); will be automatically instantiated at runtime - `adaptableApi` is provided via Injection token
11
14
  */
12
15
  type: T;
13
16
  /**
14
- * Optional initialisation callback.
15
- * If provided, it will be invoked after each component instantiation and the returned object properties will be assigned to the component instance
17
+ * Optional initialisation callback; will be invoked after each component instantiation and returned object properties assigned to component instance
16
18
  */
17
19
  onSetup?: ({ adaptableApi }: {
18
20
  adaptableApi: AdaptableApi;
@@ -32,8 +34,13 @@ export declare type ReactFrameworkComponent = ({ adaptableApi, }: {
32
34
  /**
33
35
  * Context provided for any custom rendering
34
36
  */
35
- export interface CustomRenderContext {
37
+ export interface CustomRenderContext extends BaseContext {
38
+ /**
39
+ * Whether Tool Panel is currently visible
40
+ */
36
41
  visible: boolean;
42
+ /**
43
+ * Current Div Element
44
+ */
37
45
  element: HTMLDivElement;
38
- adaptableApi: AdaptableApi;
39
46
  }
@@ -21,6 +21,12 @@ export interface ChartContainer {
21
21
  * Name of the Location - used in Dropdowns
22
22
  */
23
23
  name: string;
24
+ /**
25
+ * Weather a single chart can be displayed or multiple in the same location
26
+ *
27
+ * @defaults 'single'
28
+ */
29
+ type?: 'single' | 'multiple';
24
30
  /**
25
31
  * Location - can be HTMLElement or Id of Div
26
32
  */
@@ -41,7 +41,7 @@ export interface CustomToolPanel extends AdaptableObject {
41
41
  */
42
42
  buttons?: AdaptableButton<CustomToolPanelButtonContext>[];
43
43
  /**
44
- * Function to provide bespoke content when NOT using a Framework wrapper
44
+ * Function to provide bespoke content when using AdapTable Vanilla
45
45
  */
46
46
  render?: (customRenderContext: CustomRenderContext) => string | null;
47
47
  /**
@@ -267,7 +267,7 @@ class AlertApiImpl extends ApiBase_1.ApiBase {
267
267
  this.internalApi.executeAlertButton(button, context);
268
268
  }
269
269
  getActiveNonReactiveAlertDefinitions() {
270
- (0, logDeprecation_1.logDeprecationInternal)('AlertApi', 'executeAlertButton');
270
+ (0, logDeprecation_1.logDeprecationInternal)('AlertApi', 'getActiveNonReactiveAlertDefinitions');
271
271
  return this.internalApi.getActiveNonReactiveAlertDefinitions();
272
272
  }
273
273
  getActiveReactiveAlertDefinitions() {
@@ -1,12 +1,3 @@
1
- export declare enum DataType {
2
- String = "String",
3
- Number = "Number",
4
- Boolean = "Boolean",
5
- Date = "Date",
6
- Object = "Object",
7
- Unknown = "Unknown",
8
- All = "All"
9
- }
10
1
  export declare enum MathOperation {
11
2
  Add = "Add",
12
3
  Subtract = "Subtract",
@@ -1,17 +1,7 @@
1
1
  "use strict";
2
2
  // General Enums
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ChangeDirection = exports.FilterOnDataChangeOptions = exports.SummaryOperation = exports.StatusColour = exports.ColumnMenuTab = exports.FontSize = exports.FontStyle = exports.FontWeight = exports.SelectionMode = exports.SortOrder = exports.ScheduleType = exports.ExportDestination = exports.MathOperation = exports.DataType = void 0;
5
- var DataType;
6
- (function (DataType) {
7
- DataType["String"] = "String";
8
- DataType["Number"] = "Number";
9
- DataType["Boolean"] = "Boolean";
10
- DataType["Date"] = "Date";
11
- DataType["Object"] = "Object";
12
- DataType["Unknown"] = "Unknown";
13
- DataType["All"] = "All";
14
- })(DataType = exports.DataType || (exports.DataType = {}));
4
+ exports.ChangeDirection = exports.FilterOnDataChangeOptions = exports.SummaryOperation = exports.StatusColour = exports.ColumnMenuTab = exports.FontSize = exports.FontStyle = exports.FontWeight = exports.SelectionMode = exports.SortOrder = exports.ScheduleType = exports.ExportDestination = exports.MathOperation = void 0;
15
5
  var MathOperation;
16
6
  (function (MathOperation) {
17
7
  MathOperation["Add"] = "Add";
@@ -3,9 +3,9 @@
3
3
  */
4
4
  export interface SpecialColumnSettings {
5
5
  /**
6
- * Expression's return value DataType; inferred by AdapTable but settable by User
6
+ * Expression's return value DataType, only mandatory property
7
7
  */
8
- DataType: 'String' | 'Number' | 'Boolean' | 'Date';
8
+ DataType: 'String' | 'Number' | 'Boolean' | 'Date' | 'NumberArray';
9
9
  /**
10
10
  * Preferred (pixel) Column Width; if unset, calculated dynamically by AG Grid
11
11
  */
@@ -34,6 +34,13 @@ class CalculatedColumnModule extends AdaptableModuleBase_1.AdaptableModuleBase {
34
34
  oldCalculatedColumns.push(cc);
35
35
  (0, LoggingHelper_1.LogAdaptableWarning)(`Updating incorrect Predefined Config for Calculated Column: ${cc.ColumnId}`);
36
36
  }
37
+ if (!cc.CalculatedColumnSettings) {
38
+ cc.CalculatedColumnSettings = {
39
+ DataType: 'Number',
40
+ };
41
+ oldCalculatedColumns.push(cc);
42
+ (0, LoggingHelper_1.LogAdaptableWarning)(`Updating incorrect Predefined Config for Calculated Column: ${cc.ColumnId}`);
43
+ }
37
44
  });
38
45
  oldCalculatedColumns.forEach((oldCalcCol) => this.api.calculatedColumnApi.editCalculatedColumn(oldCalcCol));
39
46
  }
@@ -98,12 +98,10 @@ class ChartingModule extends AdaptableModuleBase_1.AdaptableModuleBase {
98
98
  },
99
99
  emptyView: 'To create a chart select a few cells and right click. Then select "Chart Range" from the context menu.',
100
100
  getStatusBarPanelProps: () => {
101
- const chartDefinitions = this.getModuleAdaptableObjects();
102
- const popover = chartDefinitions.length > 0 ? ChartingStatusBarPopover_1.ChartingStatusBarPopover : null;
103
- const content = popover ? 'See Charts' : 'No Charts';
101
+ const content = ChartingStatusBarPopover_1.ChartingStatusBarPopover;
104
102
  return {
105
103
  content,
106
- popover,
104
+ triggerActionOnWrapperClick: false,
107
105
  };
108
106
  },
109
107
  };
@@ -12,7 +12,7 @@ export declare class FormatColumnModule extends AdaptableModuleBase implements I
12
12
  includeLayoutNotAssociatedObjects?: boolean;
13
13
  }): AdaptableObject[];
14
14
  getExplicitlyReferencedColumnIds(formatColumn: FormatColumn): string[];
15
- hasNamedQueryReferences(): boolean;
15
+ getReferencedNamedQueryNames(formatColumn: FormatColumn): string[];
16
16
  updateOldConfig(): void;
17
17
  private updateFormatColumnSingleToMultiplePredicates;
18
18
  private updateConditionalStylesColumnsOldConfig;
@@ -24,15 +24,23 @@ class FormatColumnModule extends AdaptableModuleBase_1.AdaptableModuleBase {
24
24
  return this.api.formatColumnApi.getFormatColumns(config);
25
25
  }
26
26
  getExplicitlyReferencedColumnIds(formatColumn) {
27
- if (this.api.scopeApi.scopeHasColumns(formatColumn.Scope)) {
27
+ const queryExpression = this.api.queryLanguageApi.getAdaptableQueryExpression(formatColumn.Rule);
28
+ if (queryExpression) {
29
+ return this.api.queryLanguageApi.getColumnsFromExpression(queryExpression);
30
+ }
31
+ else if (this.api.scopeApi.scopeHasColumns(formatColumn.Scope)) {
28
32
  return this.api.scopeApi
29
33
  .getColumnsForScope(formatColumn.Scope)
30
34
  .map((adaptableColumn) => adaptableColumn.columnId);
31
35
  }
32
36
  return [];
33
37
  }
34
- hasNamedQueryReferences() {
35
- return false;
38
+ getReferencedNamedQueryNames(formatColumn) {
39
+ const queryExpression = this.api.queryLanguageApi.getAdaptableQueryExpression(formatColumn.Rule);
40
+ if (!queryExpression) {
41
+ return [];
42
+ }
43
+ return this.api.queryApi.internalApi.getReferencedNamedQueryNames(queryExpression);
36
44
  }
37
45
  updateOldConfig() {
38
46
  this.updateConditionalStylesColumnsOldConfig();
@@ -108,9 +108,14 @@ class StyledColumnModule extends AdaptableModuleBase_1.AdaptableModuleBase {
108
108
  let styledColumn = this.api.styledColumnApi.getStyledColumnForColumnId(column.columnId);
109
109
  let styledColumnExists = Boolean(styledColumn);
110
110
  if (!styledColumn) {
111
+ const emptyRanges = this.api.scopeApi.createCellColorRangesForScope({
112
+ ColumnIds: [column.columnId],
113
+ });
111
114
  styledColumn = Object.assign(Object.assign({}, ObjectFactory_1.default.CreateEmptyStyledColumn()), { ColumnId: column.columnId,
112
115
  // numbers default to gradient
113
- GradientStyle: {} });
116
+ GradientStyle: {
117
+ CellRanges: emptyRanges,
118
+ } });
114
119
  }
115
120
  if (styledColumn && styledColumn.IsReadOnly && styledColumn.IsReadOnly == true) {
116
121
  styledColumnExists = false;
@@ -1,13 +1,13 @@
1
1
  import { ICalculatedColumnExpressionService } from './Interface/ICalculatedColumnExpressionService';
2
2
  import { RowNode } from '@ag-grid-community/core';
3
- import { AdaptableCalculatedColumnQuery, CalculatedColumn } from '../../PredefinedConfig/CalculatedColumnState';
3
+ import { AdaptableCalculatedColumnQuery, CalculatedColumn, CalculatedColumnSettings } from '../../PredefinedConfig/CalculatedColumnState';
4
4
  import { AdaptableApi } from '../../../types';
5
5
  export declare class CalculatedColumnExpressionService implements ICalculatedColumnExpressionService {
6
6
  private adaptableApi;
7
7
  private aggregatedScalarLiveValuesMap;
8
8
  constructor(adaptableApi: AdaptableApi);
9
9
  destroy(): void;
10
- getCalculatedColumnDataType(calculatedColumnQuery: AdaptableCalculatedColumnQuery): 'String' | 'Number' | 'Boolean' | 'Date';
10
+ getCalculatedColumnDataType(calculatedColumnQuery: AdaptableCalculatedColumnQuery): CalculatedColumnSettings['DataType'];
11
11
  isCalculatedColumnQueryValid(calculatedColumnQuery: AdaptableCalculatedColumnQuery): boolean;
12
12
  evaluateCalculatedColumnQuery(calculatedColumn: CalculatedColumn, rowNode: RowNode): any;
13
13
  createAggregatedScalarLiveValue(calculatedColumn: CalculatedColumn): void;
@@ -69,6 +69,9 @@ class CalculatedColumnExpressionService {
69
69
  if (typeof firstRowValue === 'number') {
70
70
  return 'Number';
71
71
  }
72
+ if (Array.isArray(firstRowValue)) {
73
+ return 'NumberArray';
74
+ }
72
75
  }
73
76
  catch (e) {
74
77
  (0, LoggingHelper_1.LogAdaptableWarning)(`Invalid CalculatedColumn expression ${this.adaptableApi.queryLanguageApi.getAdaptableQueryExpression(calculatedColumnQuery)} :: ${e}`);
@@ -1,10 +1,10 @@
1
1
  import { IAdaptableService } from './IAdaptableService';
2
2
  import { RowNode } from '@ag-grid-community/core';
3
- import { AdaptableCalculatedColumnQuery, CalculatedColumn } from '../../../PredefinedConfig/CalculatedColumnState';
3
+ import { AdaptableCalculatedColumnQuery, CalculatedColumn, CalculatedColumnSettings } from '../../../PredefinedConfig/CalculatedColumnState';
4
4
  export interface ICalculatedColumnExpressionService extends IAdaptableService {
5
5
  isCalculatedColumnQueryValid(calculatedColumnQuery: AdaptableCalculatedColumnQuery): boolean;
6
6
  evaluateCalculatedColumnQuery(calculatedColumn: CalculatedColumn, rowNode: RowNode): any;
7
- getCalculatedColumnDataType(calculatedColumnQuery: AdaptableCalculatedColumnQuery): 'String' | 'Number' | 'Boolean' | 'Date';
7
+ getCalculatedColumnDataType(calculatedColumnQuery: AdaptableCalculatedColumnQuery): CalculatedColumnSettings['DataType'];
8
8
  createAggregatedScalarLiveValue(calculatedColumn: CalculatedColumn): void;
9
9
  destroyAggregatedScalarLiveValue(calculatedColumn: CalculatedColumn): void;
10
10
  }
@@ -4,14 +4,22 @@ exports.UIElementsForm = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const React = tslib_1.__importStar(require("react"));
6
6
  const rebass_1 = require("rebass");
7
+ const Tabs_1 = require("../../../../components/Tabs");
7
8
  const UIOptionsActionColumnsForm_1 = require("./UIOptionsActionColumnsForm");
8
9
  const UIOptionsSidebarForm_1 = require("./UIOptionsSidebarForm");
9
10
  const UIOptionsStatusbarForm_1 = require("./UIOptionsStatusbarForm");
10
11
  const UIElementsForm = (props) => {
11
12
  let abOptions = props.adaptableOptions;
12
13
  return (React.createElement(rebass_1.Box, { p: 2 },
13
- React.createElement(UIOptionsActionColumnsForm_1.UIOptionsActionColumnsForm, { abOptions: abOptions, onChange: props.onChangeadAptableOptions }),
14
- React.createElement(UIOptionsSidebarForm_1.UIOptionsSidebarForm, { abOptions: abOptions, onChange: props.onChangeadAptableOptions }),
15
- React.createElement(UIOptionsStatusbarForm_1.UIOptionsStatusbarForm, { abOptions: abOptions, onChange: props.onChangeadAptableOptions })));
14
+ React.createElement(Tabs_1.Tabs, null,
15
+ React.createElement(Tabs_1.Tabs.Tab, null, "Action Rows"),
16
+ React.createElement(Tabs_1.Tabs.Tab, null, "Sidebar"),
17
+ React.createElement(Tabs_1.Tabs.Tab, null, "Statusbar"),
18
+ React.createElement(Tabs_1.Tabs.Content, null,
19
+ React.createElement(UIOptionsActionColumnsForm_1.UIOptionsActionColumnsForm, { abOptions: abOptions, onChange: props.onChangeadAptableOptions })),
20
+ React.createElement(Tabs_1.Tabs.Content, null,
21
+ React.createElement(UIOptionsSidebarForm_1.UIOptionsSidebarForm, { abOptions: abOptions, onChange: props.onChangeadAptableOptions })),
22
+ React.createElement(Tabs_1.Tabs.Content, null,
23
+ React.createElement(UIOptionsStatusbarForm_1.UIOptionsStatusbarForm, { abOptions: abOptions, onChange: props.onChangeadAptableOptions })))));
16
24
  };
17
25
  exports.UIElementsForm = UIElementsForm;
@@ -78,6 +78,8 @@ const CalculatedColumnSettingsWizardSection = (props) => {
78
78
  Width: Number(e.target.value),
79
79
  }) })))))),
80
80
  ErrorMessage ? React.createElement(ErrorBox_1.default, { marginTop: 2 }, ErrorMessage) : null,
81
- React.createElement(SpecialColumnSettingsWizardStep_1.SpecialColumnSettingsWizardStep, { isEditable: false, settings: data.CalculatedColumnSettings, onChange: handleSpecialColumnSettingsChange })));
81
+ React.createElement(SpecialColumnSettingsWizardStep_1.SpecialColumnSettingsWizardStep, { isEditable: false,
82
+ // @ts-ignore CalculatedColumn has a broader DataType
83
+ settings: data.CalculatedColumnSettings, onChange: handleSpecialColumnSettingsChange })));
82
84
  };
83
85
  exports.CalculatedColumnSettingsWizardSection = CalculatedColumnSettingsWizardSection;
@@ -3,21 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChartingStatusBarPopover = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const React = tslib_1.__importStar(require("react"));
6
- const react_redux_1 = require("react-redux");
7
6
  const AdaptableContext_1 = require("../../AdaptableContext");
8
- const ChartingRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/ChartingRedux"));
9
- const SelectList_1 = require("../../../components/SelectList");
10
- const ChartingStatusBarPopover = () => {
7
+ const ModuleConstants = tslib_1.__importStar(require("../../../Utilities/Constants/ModuleConstants"));
8
+ const useChartingElements_1 = require("./useChartingElements");
9
+ const rebass_1 = require("rebass");
10
+ const ChartingStatusBarPopover = (props) => {
11
11
  const adaptable = (0, AdaptableContext_1.useAdaptable)();
12
- const chartDefinitions = (0, react_redux_1.useSelector)(ChartingRedux.ChartingGetChartModels);
13
- const options = chartDefinitions.map((chartDefinition) => ({
14
- label: chartDefinition.Name,
15
- value: chartDefinition.Uuid,
16
- }));
17
- const handleChange = React.useCallback((option) => {
18
- const definition = chartDefinitions.find((cd) => cd.Uuid === option.value);
19
- adaptable.api.chartingApi.showChartDefinitionOnce(definition);
20
- }, [chartDefinitions]);
21
- return React.createElement(SelectList_1.SelectList, { options: options, onChange: handleChange });
12
+ const accessLevel = adaptable.api.internalApi
13
+ .getEntitlementService()
14
+ .getEntitlementAccessLevelForModule(ModuleConstants.ChartingModuleId);
15
+ const { chartSelector, containerSelector, chartButton, deleteButton, editButton } = (0, useChartingElements_1.useChartingElements)({
16
+ elementType: 'Statusbar',
17
+ accessLevel: accessLevel,
18
+ size: 'small',
19
+ });
20
+ return (React.createElement(rebass_1.Flex, { width: "100%", alignItems: "center" },
21
+ React.createElement(rebass_1.Box, null, chartSelector),
22
+ containerSelector && React.createElement(rebass_1.Box, { ml: 1 }, containerSelector),
23
+ React.createElement(rebass_1.Box, { ml: 1 },
24
+ chartButton,
25
+ deleteButton,
26
+ editButton)));
22
27
  };
23
28
  exports.ChartingStatusBarPopover = ChartingStatusBarPopover;
@@ -3,76 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChartingViewPanel = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const React = tslib_1.__importStar(require("react"));
6
- const react_redux_1 = require("react-redux");
7
6
  const rebass_1 = require("rebass");
8
- const DropdownButton_1 = tslib_1.__importDefault(require("../../../components/DropdownButton"));
9
- const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
10
- const ChartingRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/ChartingRedux"));
11
- const AdaptableHelper_1 = tslib_1.__importDefault(require("../../../Utilities/Helpers/AdaptableHelper"));
12
- const AdaptableContext_1 = require("../../AdaptableContext");
13
- const useChartState_1 = require("./useChartState");
14
- const DeleteChartButton_1 = require("./DeleteChartButton");
15
- const EditChartButton_1 = require("./EditChartButton");
7
+ const useChartingElements_1 = require("./useChartingElements");
16
8
  const ChartingViewPanel = (props) => {
17
- var _a, _b, _c;
18
- const adaptable = (0, AdaptableContext_1.useAdaptable)();
19
- const chartDefinitions = (0, react_redux_1.useSelector)(ChartingRedux.ChartingGetChartModels);
20
- const chartContainers = (_b = (_a = adaptable.adaptableOptions) === null || _a === void 0 ? void 0 : _a.chartingOptions) === null || _b === void 0 ? void 0 : _b.chartContainers;
21
- const [selectedChartId, setSelectedChartId] = React.useState(() => {
22
- // ID is kept in state becaus that does not change, the definition might change
23
- return chartDefinitions.length > 0 ? chartDefinitions[0].Uuid : null;
24
- });
25
- const selectedChart = chartDefinitions.find((chart) => chart.Uuid === selectedChartId);
26
- const accessLevel = AdaptableHelper_1.default.getAppropriateAccessLevel(selectedChart, props.accessLevel);
27
- const [selectedContainer, setSelectedContainer] = React.useState(null);
28
- const { isOpen, showChart, closeChart } = (0, useChartState_1.useChartState)(selectedChart);
29
- const options = chartDefinitions.map((chartDefinition) => ({
30
- label: chartDefinition.Name,
31
- value: chartDefinition.Uuid,
32
- onClick: () => {
33
- setSelectedChartId(chartDefinition.Uuid);
34
- },
35
- }));
36
- const hasCharts = options.length > 0;
37
- const isSelectedChart = hasCharts && selectedChart != null;
38
- let content = '';
39
- if (hasCharts && selectedChart) {
40
- content = (_c = chartDefinitions.find((chart) => chart.Uuid === selectedChart.Uuid)) === null || _c === void 0 ? void 0 : _c.Name;
41
- }
42
- else if (hasCharts) {
43
- content = 'Select Chart';
44
- }
45
- else {
46
- content = 'No Charts';
47
- }
48
9
  const elementType = props.viewType === 'Toolbar' ? 'DashboardToolbar' : 'ToolPanel';
49
- React.useEffect(() => {
50
- // select first
51
- if (!selectedChart && chartDefinitions.length > 0) {
52
- setSelectedChartId(chartDefinitions[0].Uuid);
53
- }
54
- }, [chartDefinitions]);
55
- const containerOptions = [
56
- {
57
- label: 'Ag Grid Window',
58
- onClick: () => {
59
- setSelectedContainer(null);
60
- },
61
- },
62
- ...(chartContainers
63
- ? chartContainers === null || chartContainers === void 0 ? void 0 : chartContainers.map((contianerDef) => ({
64
- label: contianerDef.name,
65
- onClick: () => {
66
- setSelectedContainer(contianerDef);
67
- },
68
- }))
69
- : []),
70
- ];
71
- const chartSelector = (React.createElement(DropdownButton_1.default, { width: "100%", columns: ['label'], className: `ab-${elementType}__Chart__select`, items: options, disabled: !hasCharts }, content));
72
- const containerSelector = Boolean(chartContainers === null || chartContainers === void 0 ? void 0 : chartContainers.length) && (React.createElement(DropdownButton_1.default, { width: "100%", columns: ['label'], items: containerOptions, disabled: !isSelectedChart }, (selectedContainer === null || selectedContainer === void 0 ? void 0 : selectedContainer.name) || 'Ag Grid Window'));
73
- const chartButton = (React.createElement(SimpleButton_1.default, { mr: 1, onClick: () => (isOpen ? closeChart() : showChart(selectedContainer)), disabled: !Boolean(selectedChart), variant: 'outlined', tone: 'neutral' }, isOpen ? 'Close' : 'Open'));
74
- const deleteButton = React.createElement(DeleteChartButton_1.DeleteChartButton, { chart: selectedChart, accessLevel: accessLevel });
75
- const editButton = (React.createElement(EditChartButton_1.EditChartButton, { chart: selectedChart, accessLevel: accessLevel, isOpen: isOpen }));
10
+ const { chartSelector, containerSelector, chartButton, deleteButton, editButton } = (0, useChartingElements_1.useChartingElements)({ elementType, accessLevel: props.accessLevel });
76
11
  if (elementType === 'DashboardToolbar') {
77
12
  return (React.createElement(rebass_1.Flex, { width: "100%", alignItems: "center" },
78
13
  React.createElement(rebass_1.Box, null, chartSelector),
@@ -3,5 +3,6 @@ import { AccessLevel, ChartDefinition } from '../../../types';
3
3
  export interface ButtonDeleteProps {
4
4
  chart: ChartDefinition;
5
5
  accessLevel: AccessLevel;
6
+ iconSize?: number;
6
7
  }
7
8
  export declare const DeleteChartButton: React.FunctionComponent<ButtonDeleteProps>;
@@ -7,6 +7,6 @@ const ButtonDelete_1 = require("../Buttons/ButtonDelete");
7
7
  const ChartingRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/ChartingRedux"));
8
8
  const DeleteChartButton = (props) => {
9
9
  var _a;
10
- return (React.createElement(ButtonDelete_1.ButtonDelete, { disabled: !props.chart, ConfirmAction: ChartingRedux.ChartingDeleteChart((_a = props.chart) === null || _a === void 0 ? void 0 : _a.Name), ConfirmationMsg: `Are you sure you want to delete this Charts?`, ConfirmationTitle: 'Delete Charts', accessLevel: props.accessLevel }));
10
+ return (React.createElement(ButtonDelete_1.ButtonDelete, { iconSize: props.iconSize, disabled: !props.chart, ConfirmAction: ChartingRedux.ChartingDeleteChart((_a = props.chart) === null || _a === void 0 ? void 0 : _a.Name), ConfirmationMsg: `Are you sure you want to delete this Charts?`, ConfirmationTitle: 'Delete Charts', accessLevel: props.accessLevel }));
11
11
  };
12
12
  exports.DeleteChartButton = DeleteChartButton;
@@ -4,5 +4,6 @@ export interface EditChartButtonProps {
4
4
  chart: ChartDefinition;
5
5
  accessLevel: AccessLevel;
6
6
  isOpen: boolean;
7
+ iconSize?: number;
7
8
  }
8
9
  export declare const EditChartButton: React.FunctionComponent<EditChartButtonProps>;
@@ -9,7 +9,7 @@ const ModuleConstants = tslib_1.__importStar(require("../../../Utilities/Constan
9
9
  const react_redux_1 = require("react-redux");
10
10
  const EditChartButton = (props) => {
11
11
  const dispatch = (0, react_redux_1.useDispatch)();
12
- return (React.createElement(ButtonEdit_1.ButtonEdit, { tooltip: "Edit Chart",
12
+ return (React.createElement(ButtonEdit_1.ButtonEdit, { iconSize: props.iconSize, tooltip: "Edit Chart",
13
13
  // It gets complicated when a chart is both open and opened in edit wizard
14
14
  // There an be conflicts between the two open charts (preview and main) and the changes to the active chart may not be syncronized correctly.
15
15
  disabled: !props.chart || props.isOpen, accessLevel: props.accessLevel, onClick: () => dispatch(PopupRedux.PopupShowScreen(ModuleConstants.ChartingModuleId, 'Chart', {
@@ -20,6 +20,18 @@ const useChartState = (chartDefinition) => {
20
20
  const currentChartRef = (_a = adaptable.api.chartingApi.getChartRef(chartDefinition.Model.chartId)) !== null && _a !== void 0 ? _a : null;
21
21
  setChartRef(currentChartRef);
22
22
  }, [currentChartModels, chartDefinition]);
23
+ const closeAlreadyOpenedChartsInContainer = (element) => {
24
+ const chartModelAlreadyInChartContainer = currentChartModels.find((chartModel) => {
25
+ const chartRef = adaptable.api.chartingApi.getChartRef(chartModel.chartId);
26
+ return chartRef && element.contains(chartRef.chartElement);
27
+ });
28
+ if (chartModelAlreadyInChartContainer) {
29
+ const chartRef = adaptable.api.chartingApi.getChartRef(chartModelAlreadyInChartContainer.chartId);
30
+ if (chartRef) {
31
+ chartRef.destroyChart();
32
+ }
33
+ }
34
+ };
23
35
  const handleShowChart = React.useCallback((chartContainer) => {
24
36
  if (!adaptable || !chartDefinition) {
25
37
  return;
@@ -41,15 +53,8 @@ const useChartState = (chartDefinition) => {
41
53
  * If multple charts are opened in the same contianer, it infinitly adds the charts to the container.
42
54
  */
43
55
  if (chartContainer && element) {
44
- const chartModelAlreadyInChartContainer = currentChartModels.find((chartModel) => {
45
- const chartRef = adaptable.api.chartingApi.getChartRef(chartModel.chartId);
46
- return chartRef && element.contains(chartRef.chartElement);
47
- });
48
- if (chartModelAlreadyInChartContainer) {
49
- const chartRef = adaptable.api.chartingApi.getChartRef(chartModelAlreadyInChartContainer.chartId);
50
- if (chartRef) {
51
- chartRef.destroyChart();
52
- }
56
+ if (chartContainer.type !== 'multiple') {
57
+ closeAlreadyOpenedChartsInContainer(element);
53
58
  }
54
59
  adaptable.api.chartingApi.showChartDefinitionOnce(chartDefinition, element);
55
60
  }
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { AccessLevel, ChartDefinition } from '../../../types';
3
+ export declare const useChartingElements: ({ elementType, accessLevel, size, }: {
4
+ elementType: string;
5
+ accessLevel: AccessLevel;
6
+ size?: 'small' | 'normal';
7
+ }) => {
8
+ chartSelector: JSX.Element;
9
+ containerSelector: JSX.Element;
10
+ chartButton: JSX.Element;
11
+ deleteButton: JSX.Element;
12
+ editButton: JSX.Element;
13
+ selectedChart: ChartDefinition;
14
+ };
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useChartingElements = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const React = tslib_1.__importStar(require("react"));
6
+ const react_redux_1 = require("react-redux");
7
+ const AdaptableContext_1 = require("../../AdaptableContext");
8
+ const DropdownButton_1 = tslib_1.__importDefault(require("../../../components/DropdownButton"));
9
+ const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
10
+ const ChartingRedux = tslib_1.__importStar(require("../../../Redux/ActionsReducers/ChartingRedux"));
11
+ const AdaptableHelper_1 = tslib_1.__importDefault(require("../../../Utilities/Helpers/AdaptableHelper"));
12
+ const useChartState_1 = require("./useChartState");
13
+ const DeleteChartButton_1 = require("./DeleteChartButton");
14
+ const EditChartButton_1 = require("./EditChartButton");
15
+ const useChartingElements = ({ elementType, accessLevel, size = 'normal', }) => {
16
+ var _a, _b, _c;
17
+ const adaptable = (0, AdaptableContext_1.useAdaptable)();
18
+ const chartDefinitions = (0, react_redux_1.useSelector)(ChartingRedux.ChartingGetChartModels);
19
+ const chartContainers = (_b = (_a = adaptable.adaptableOptions) === null || _a === void 0 ? void 0 : _a.chartingOptions) === null || _b === void 0 ? void 0 : _b.chartContainers;
20
+ const [selectedChartId, setSelectedChartId] = React.useState(() => {
21
+ // ID is kept in state becaus that does not change, the definition might change
22
+ return chartDefinitions.length > 0 ? chartDefinitions[0].Uuid : null;
23
+ });
24
+ const selectedChart = chartDefinitions.find((chart) => chart.Uuid === selectedChartId);
25
+ const chartAccessLevel = AdaptableHelper_1.default.getAppropriateAccessLevel(selectedChart, accessLevel);
26
+ const [selectedContainer, setSelectedContainer] = React.useState(null);
27
+ const { isOpen, showChart, closeChart } = (0, useChartState_1.useChartState)(selectedChart);
28
+ const options = chartDefinitions.map((chartDefinition) => ({
29
+ label: chartDefinition.Name,
30
+ value: chartDefinition.Uuid,
31
+ onClick: () => {
32
+ setSelectedChartId(chartDefinition.Uuid);
33
+ },
34
+ }));
35
+ const hasCharts = options.length > 0;
36
+ const isSelectedChart = hasCharts && selectedChart != null;
37
+ let content = '';
38
+ if (hasCharts && selectedChart) {
39
+ content = (_c = chartDefinitions.find((chart) => chart.Uuid === selectedChart.Uuid)) === null || _c === void 0 ? void 0 : _c.Name;
40
+ }
41
+ else if (hasCharts) {
42
+ content = 'Select Chart';
43
+ }
44
+ else {
45
+ content = 'No Charts';
46
+ }
47
+ React.useEffect(() => {
48
+ // select first
49
+ if (!selectedChart && chartDefinitions.length > 0) {
50
+ setSelectedChartId(chartDefinitions[0].Uuid);
51
+ }
52
+ }, [chartDefinitions]);
53
+ const containerOptions = [
54
+ {
55
+ label: 'Ag Grid Window',
56
+ onClick: () => {
57
+ setSelectedContainer(null);
58
+ },
59
+ },
60
+ ...(chartContainers
61
+ ? chartContainers === null || chartContainers === void 0 ? void 0 : chartContainers.map((contianerDef) => ({
62
+ label: contianerDef.name,
63
+ onClick: () => {
64
+ setSelectedContainer(contianerDef);
65
+ },
66
+ }))
67
+ : []),
68
+ ];
69
+ const style = {};
70
+ let iconSize;
71
+ if (size === 'small') {
72
+ style.padding = 2;
73
+ style.fontSize = 'small';
74
+ iconSize = 15;
75
+ }
76
+ const chartSelector = (React.createElement(DropdownButton_1.default, { style: style, width: "100%", columns: ['label'], className: `ab-${elementType}__Chart__select`, items: options, disabled: !hasCharts }, content));
77
+ const containerSelector = Boolean(chartContainers === null || chartContainers === void 0 ? void 0 : chartContainers.length) && (React.createElement(DropdownButton_1.default, { style: style, width: "100%", columns: ['label'], items: containerOptions, disabled: !isSelectedChart }, (selectedContainer === null || selectedContainer === void 0 ? void 0 : selectedContainer.name) || 'Ag Grid Window'));
78
+ const chartButton = (React.createElement(SimpleButton_1.default, { style: style, mr: 1, onClick: () => (isOpen ? closeChart() : showChart(selectedContainer)), disabled: !Boolean(selectedChart), variant: 'outlined', tone: 'neutral' }, isOpen ? 'Close' : 'Open'));
79
+ const deleteButton = (React.createElement(DeleteChartButton_1.DeleteChartButton, { iconSize: iconSize, chart: selectedChart, accessLevel: chartAccessLevel }));
80
+ const editButton = (React.createElement(EditChartButton_1.EditChartButton, { iconSize: iconSize, chart: selectedChart, accessLevel: chartAccessLevel, isOpen: isOpen }));
81
+ return {
82
+ chartSelector,
83
+ containerSelector,
84
+ chartButton,
85
+ deleteButton,
86
+ editButton,
87
+ selectedChart,
88
+ };
89
+ };
90
+ exports.useChartingElements = useChartingElements;