Skip to content

Commit

Permalink
Fixed alternate state support
Browse files Browse the repository at this point in the history
-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
  • Loading branch information
Albert Backenhof authored and Albert Backenhof committed May 27, 2019
1 parent 072a3b8 commit 16c380e
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 68 deletions.
40 changes: 27 additions & 13 deletions src/data-table/data-cell.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import qlik from 'qlik';
import React from 'react';
import PropTypes from 'prop-types';
import Tooltip from '../tooltip/index.jsx';
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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({
Expand All @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions src/data-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -42,8 +42,9 @@ const DataTable = ({ data, general, qlik, renderData, styling }) => {
<tr key={dimensionEntry.displayValue}>
{!renderData ?
<RowHeader
altState={data.meta.altState}
entry={dimensionEntry}
qlik={qlik}
component={component}
rowStyle={rowStyle}
styleBuilder={styleBuilder}
styling={styling}
Expand Down Expand Up @@ -80,7 +81,7 @@ const DataTable = ({ data, general, qlik, renderData, styling }) => {
general={general}
key={`${dimensionEntry.displayValue}-${id}`}
measurement={measurementData}
qlik={qlik}
component={component}
styleBuilder={styleBuilder}
styling={styling}
/>
Expand All @@ -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
Expand Down
26 changes: 11 additions & 15 deletions src/data-table/row-header.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import qlik from 'qlik';
import React from 'react';
import PropTypes from 'prop-types';
import HeaderPadding from './header-padding.jsx';
Expand All @@ -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 (
<td
Expand All @@ -43,18 +45,12 @@ class RowHeader extends React.PureComponent {

RowHeader.propTypes = {
entry: PropTypes.shape({
displayValue: PropTypes.string.isRequired
}).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
displayValue: PropTypes.string.isRequired,
elementNumber: PropTypes.number.isRequired,
name: PropTypes.string.isRequired
}).isRequired,
altState: PropTypes.string.isRequired,
component: PropTypes.shape({}).isRequired,
rowStyle: PropTypes.shape({}).isRequired,
styleBuilder: PropTypes.shape({}).isRequired,
styling: PropTypes.shape({}).isRequired
Expand Down
5 changes: 4 additions & 1 deletion src/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ async function buildDataCube (originCubeDefinition, hasTwoDimensions, app) {
cubeDefinition.qDimensions.push(originCubeDefinition.qDimensions[1]);
}
const cube = await createCube(cubeDefinition, app);
return cube.qHyperCube.qDataPages[0].qMatrix;
const cubeMatrix = cube.qHyperCube.qDataPages[0].qMatrix;
app.destroySessionObject(cube.qInfo.qId);
return cubeMatrix;
}

export async function initializeDataCube (component, layout) {
Expand All @@ -37,6 +39,7 @@ export async function initializeDataCube (component, layout) {
const hyperCubeDef = properties.qExtendsId
? (await app.getObjectProperties(properties.qExtendsId)).properties.qHyperCubeDef
: properties.qHyperCubeDef;
hyperCubeDef.qStateName = layout.qStateName || "";

return buildDataCube(hyperCubeDef, layout.qHyperCube.qDimensionInfo.length === 2, app);
}
Expand Down
23 changes: 9 additions & 14 deletions src/headers-table/column-header.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import qlik from 'qlik';
import React from 'react';
import PropTypes from 'prop-types';
import { HEADER_FONT_SIZE } from '../initialize-transformed';
Expand All @@ -10,13 +11,14 @@ class ColumnHeader extends React.PureComponent {
}

handleSelect () {
const { entry, qlik } = this.props;
qlik.backendApi.selectValues(1, [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 { baseCSS, cellWidth, colSpan, entry, styling, qlik } = this.props;
const inEditState = qlik.inEditState();
const { baseCSS, cellWidth, colSpan, entry, styling, component } = this.props;
const inEditState = component.inEditState();
const isMediumFontSize = styling.headerOptions.fontSizeAdjustment === HEADER_FONT_SIZE.MEDIUM;

const style = {
Expand Down Expand Up @@ -56,19 +58,12 @@ ColumnHeader.propTypes = {
cellWidth: PropTypes.string,
colSpan: PropTypes.number,
entry: PropTypes.shape({
displayValue: PropTypes.string.isRequired,
elementNumber: PropTypes.number.isRequired,
name: PropTypes.string.isRequired
}).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,
altState: PropTypes.string.isRequired,
component: PropTypes.shape({}).isRequired,
styling: PropTypes.shape({
headerOptions: PropTypes.shape({
fontSizeAdjustment: PropTypes.number.isRequired
Expand Down
21 changes: 8 additions & 13 deletions src/headers-table/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ColumnHeader from './column-header.jsx';
import MeasurementColumnHeader from './measurement-column-header.jsx';
import { injectSeparators } from '../utilities';

const HeadersTable = ({ data, general, qlik, styling, isKpi }) => {
const HeadersTable = ({ data, general, component, styling, isKpi }) => {
const baseCSS = {
backgroundColor: styling.headerOptions.colorSchema,
color: styling.headerOptions.textColor,
Expand All @@ -28,7 +28,7 @@ const HeadersTable = ({ data, general, qlik, styling, isKpi }) => {
<tr>
{isKpi ?
<ExportColumnHeader
id={qlik.options.id}
id={component.$scope.layout.qInfo.qId}
allowExcelExport={general.allowExcelExport}
baseCSS={baseCSS}
general={general}
Expand Down Expand Up @@ -67,12 +67,13 @@ const HeadersTable = ({ data, general, qlik, styling, isKpi }) => {
}
return (
<ColumnHeader
altState={data.meta.altState}
baseCSS={baseCSS}
cellWidth={general.cellWidth}
colSpan={measurements.length}
entry={entry}
key={entry.displayValue}
qlik={qlik}
component={component}
styling={styling}
/>
);
Expand Down Expand Up @@ -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({})
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default {
const jsx = (
<Root
editmodeClass={editmodeClass}
qlik={this}
component={this}
state={state}
/>
);
Expand Down
3 changes: 2 additions & 1 deletion src/initialize-transformed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
12 changes: 6 additions & 6 deletions src/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ 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 }) => (
<div className="root">
<LinkedScrollWrapper>
<div className={`kpi-table ${editmodeClass}`}>
<HeadersTable
data={state.data}
general={state.general}
isKpi
qlik={qlik}
component={component}
styling={state.styling}
/>
<LinkedScrollSection linkVertical>
<DataTable
data={state.data}
general={state.general}
qlik={qlik}
component={component}
renderData={false}
styling={state.styling}
/>
Expand All @@ -31,7 +31,7 @@ const Root = ({ state, qlik, editmodeClass }) => (
data={state.data}
general={state.general}
isKpi={false}
qlik={qlik}
component={component}
styling={state.styling}
/>
</LinkedScrollSection>
Expand All @@ -42,7 +42,7 @@ const Root = ({ state, qlik, editmodeClass }) => (
<DataTable
data={state.data}
general={state.general}
qlik={qlik}
component={component}
styling={state.styling}
/>
</LinkedScrollSection>
Expand All @@ -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,
Expand Down

0 comments on commit 16c380e

Please sign in to comment.