From 16c380e1c67721b898f17c2f8db7fd03e9c04041 Mon Sep 17 00:00:00 2001 From: Albert Backenhof Date: Wed, 15 May 2019 08:31:05 +0200 Subject: [PATCH] Fixed alternate state support -Previously, the shown data always followed default state, and not the set state. -Previously, the selections made in smart pivot sometimes used the previous alternate state. Issue: QLIK-95802 --- src/data-table/data-cell.jsx | 40 +++++++++++++++++++---------- src/data-table/index.jsx | 9 ++++--- src/data-table/row-header.jsx | 26 ++++++++----------- src/dataset.js | 5 +++- src/headers-table/column-header.jsx | 23 +++++++---------- src/headers-table/index.jsx | 21 ++++++--------- src/index.js | 2 +- src/initialize-transformed.js | 3 ++- src/root.jsx | 12 ++++----- 9 files changed, 73 insertions(+), 68 deletions(-) diff --git a/src/data-table/data-cell.jsx b/src/data-table/data-cell.jsx index b0e1a54..27f11f8 100644 --- a/src/data-table/data-cell.jsx +++ b/src/data-table/data-cell.jsx @@ -1,3 +1,4 @@ +import qlik from 'qlik'; import React from 'react'; import PropTypes from 'prop-types'; import Tooltip from '../tooltip/index.jsx'; @@ -9,16 +10,33 @@ class DataCell extends React.PureComponent { } handleSelect () { - const { data: { meta: { dimensionCount } }, general: { allowFilteringByClick }, measurement, qlik } = this.props; + const { + data: { + headers, + meta: { + dimensionCount, + altState + } + }, + general: { + allowFilteringByClick + }, + measurement, + component + } = this.props; + const hasSecondDimension = dimensionCount > 1; if (!allowFilteringByClick) { return; } - qlik.backendApi.selectValues(0, [measurement.parents.dimension1.elementNumber], false); + const app = qlik.currApp(component); + app.field(headers.dimension1[0].name, altState) + .select([measurement.parents.dimension1.elementNumber], false, false); if (hasSecondDimension) { - qlik.backendApi.selectValues(1, [measurement.parents.dimension2.elementNumber], false); + app.field(headers.dimension2[0].name, altState) + .select([measurement.parents.dimension2.elementNumber], false, false); } } @@ -88,7 +106,12 @@ class DataCell extends React.PureComponent { DataCell.propTypes = { data: PropTypes.shape({ headers: PropTypes.shape({ + dimension1: PropTypes.array.isRequired, measurements: PropTypes.array.isRequired + }).isRequired, + meta: PropTypes.shape({ + altState: PropTypes.string.isRequired, + dimensionCount: PropTypes.number.isRequired }).isRequired }).isRequired, general: PropTypes.shape({ @@ -99,16 +122,7 @@ DataCell.propTypes = { name: PropTypes.string, value: PropTypes.any }).isRequired, - qlik: PropTypes.shape({ - backendApi: PropTypes.shape({ - selectValues: function (props, propName) { - if (props.isSnapshot || typeof props[propName] === 'function') { - return null; - } - return new Error('Missing implementation of qlik.backendApi.selectValues.'); - } - }).isRequired - }).isRequired, + component: PropTypes.shape({}).isRequired, styleBuilder: PropTypes.shape({ hasComments: PropTypes.func.isRequired }).isRequired, diff --git a/src/data-table/index.jsx b/src/data-table/index.jsx index 053da62..44905d4 100644 --- a/src/data-table/index.jsx +++ b/src/data-table/index.jsx @@ -5,7 +5,7 @@ import DataCell from './data-cell.jsx'; import RowHeader from './row-header.jsx'; import { injectSeparators } from '../utilities'; -const DataTable = ({ data, general, qlik, renderData, styling }) => { +const DataTable = ({ data, general, component, renderData, styling }) => { const { headers: { dimension1, @@ -42,8 +42,9 @@ const DataTable = ({ data, general, qlik, renderData, styling }) => { {!renderData ? { general={general} key={`${dimensionEntry.displayValue}-${id}`} measurement={measurementData} - qlik={qlik} + component={component} styleBuilder={styleBuilder} styling={styling} /> @@ -107,7 +108,7 @@ DataTable.propTypes = { matrix: PropTypes.arrayOf(PropTypes.array.isRequired).isRequired }).isRequired, general: PropTypes.shape({}).isRequired, - qlik: PropTypes.shape({}).isRequired, + component: PropTypes.shape({}).isRequired, renderData: PropTypes.bool, styling: PropTypes.shape({ hasCustomFileStyle: PropTypes.bool.isRequired diff --git a/src/data-table/row-header.jsx b/src/data-table/row-header.jsx index 08834ef..c8a3db5 100644 --- a/src/data-table/row-header.jsx +++ b/src/data-table/row-header.jsx @@ -1,3 +1,4 @@ +import qlik from 'qlik'; import React from 'react'; import PropTypes from 'prop-types'; import HeaderPadding from './header-padding.jsx'; @@ -11,13 +12,14 @@ class RowHeader extends React.PureComponent { } handleSelect () { - const { entry, qlik } = this.props; - qlik.backendApi.selectValues(0, [entry.elementNumber], true); + const { entry, altState, component } = this.props; + const app = qlik.currApp(component); + app.field(entry.name, altState).select([entry.elementNumber], false, false); } render () { - const { entry, rowStyle, styleBuilder, styling, qlik } = this.props; - const inEditState = qlik.inEditState(); + const { entry, rowStyle, styleBuilder, styling, component } = this.props; + const inEditState = component.inEditState(); return ( { +const HeadersTable = ({ data, general, component, styling, isKpi }) => { const baseCSS = { backgroundColor: styling.headerOptions.colorSchema, color: styling.headerOptions.textColor, @@ -28,7 +28,7 @@ const HeadersTable = ({ data, general, qlik, styling, isKpi }) => { {isKpi ? { } return ( ); @@ -124,19 +125,13 @@ HeadersTable.propTypes = { dimension1: PropTypes.array, dimension2: PropTypes.array, measurements: PropTypes.array + }), + meta: PropTypes.shape({ + altState: PropTypes.string.isRequired }) }).isRequired, general: PropTypes.shape({}).isRequired, - qlik: PropTypes.shape({ - backendApi: PropTypes.shape({ - selectValues: function (props, propName) { - if (props.isSnapshot || typeof props[propName] === 'function') { - return null; - } - return new Error('Missing implementation of qlik.backendApi.selectValues.'); - } - }).isRequired - }).isRequired, + component: PropTypes.shape({}).isRequired, styling: PropTypes.shape({ headerOptions: PropTypes.shape({}), options: PropTypes.shape({}) diff --git a/src/index.js b/src/index.js index 22ddc80..9fceb4f 100644 --- a/src/index.js +++ b/src/index.js @@ -71,7 +71,7 @@ export default { const jsx = ( ); diff --git a/src/initialize-transformed.js b/src/initialize-transformed.js index a333749..ced82d8 100644 --- a/src/initialize-transformed.js +++ b/src/initialize-transformed.js @@ -238,7 +238,8 @@ function initializeTransformed ({ $element, component, dataCube, designList, lay }, matrix, // 2d array of all rows/cells to render in body of datatable meta: { - dimensionCount: dimensionsInformation.length + dimensionCount: dimensionsInformation.length, + altState: layout.qStateName || "" } }, general: { diff --git a/src/root.jsx b/src/root.jsx index 402d9e7..c202ce7 100644 --- a/src/root.jsx +++ b/src/root.jsx @@ -4,7 +4,7 @@ import HeadersTable from './headers-table/index.jsx'; import DataTable from './data-table/index.jsx'; import { LinkedScrollWrapper, LinkedScrollSection } from './linked-scroll'; -const Root = ({ state, qlik, editmodeClass }) => ( +const Root = ({ state, component, editmodeClass }) => (
@@ -12,14 +12,14 @@ const Root = ({ state, qlik, editmodeClass }) => ( data={state.data} general={state.general} isKpi - qlik={qlik} + component={component} styling={state.styling} /> @@ -31,7 +31,7 @@ const Root = ({ state, qlik, editmodeClass }) => ( data={state.data} general={state.general} isKpi={false} - qlik={qlik} + component={component} styling={state.styling} /> @@ -42,7 +42,7 @@ const Root = ({ state, qlik, editmodeClass }) => ( @@ -52,7 +52,7 @@ const Root = ({ state, qlik, editmodeClass }) => ( ); Root.propTypes = { - qlik: PropTypes.shape({}).isRequired, + component: PropTypes.shape({}).isRequired, state: PropTypes.shape({ data: PropTypes.object.isRequired, general: PropTypes.object.isRequired,