Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
feat: step cyclic dimension with sn-action-button (#454)
Browse files Browse the repository at this point in the history
Co-authored-by: linhnguyen-qlik <lgu@qlik.com>
  • Loading branch information
Bjornwa and linhnguyen-qlik authored Jan 3, 2024
1 parent a616b68 commit 311b679
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/__tests__/ext.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,44 @@ describe("ext", () => {
},
},
];
const dimensions = [
{
qInfo: {
qId: "mHsTwF",
qType: "dimension",
},
qMeta: {
title: "cyclic",
},
qData: {
grouping: "C",
},
},
{
qInfo: {
qId: "GNHRZQ",
qType: "dimension",
},
qMeta: {
title: "single",
},
qData: {
grouping: "N",
},
},
{
qInfo: {
qId: "fb8b9972-e894-4ea1-a4d9-452d8f791672",
qType: "dimension",
},
qMeta: {
title: "Drill-down",
},
qData: {
grouping: "H",
},
},
];
const handler = {
app: {
getBookmarkList: () => bookmarks,
Expand All @@ -154,6 +192,7 @@ describe("ext", () => {
getSheetList: () => sheets,
getStoryList: () => stories,
getObject: () => sheet,
getDimensionList: () => dimensions,
},
};

Expand Down Expand Up @@ -184,6 +223,18 @@ describe("ext", () => {
expect(options).toHaveLength(2);
});

it("Should return only cyclic group dimensions", async () => {
options = await actionItems.cyclicGroup.options(null, handler);
expect(options).toHaveLength(1);
expect(options[0].label).toEqual("cyclic");
});

it("Should return forward and backward option", async () => {
options = await actionItems.indexStepper.options();
expect(options).toHaveLength(2);
expect(options[0].value).toEqual(1);
expect(options[1].value).toEqual(-1);
});
it("Should return an array with all automations", async () => {
const automationId = "automationId";
const automationName = "fakeAutomationName";
Expand Down
37 changes: 37 additions & 0 deletions src/ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,43 @@ export default function ext({ translator, shouldHide, senseNavigation, theme, is
},
show: (data) => checkShowAction(data, "field"),
},
cyclicGroup: {
type: "string",
ref: "cyclicGroupId",
component: "expression-with-dropdown",
translation: "Common.Dimension",
defaultValue: "",
dropdownOnly: true,
options: async (action, hyperCubeHandler) => {
const dimensions = await hyperCubeHandler.app.getDimensionList();
return dimensions
.filter((dim) => dim.qData.grouping === "C")
.map((dim) => ({
label: dim.qMeta.title,
value: dim.qInfo.qId,
}));
},
show: (data) => checkShowAction(data, "cyclicGroup"),
},
indexStepper: {
type: "string",
ref: "indexStepper",
component: "expression-with-dropdown",
translation: "Object.ActionButton.Step",
defaultValue: 1,
dropdownOnly: true,
options: async () => [
{
translation: "Object.ActionButton.Forward",
value: 1,
},
{
translation: "Object.ActionButton.Backward",
value: -1,
},
],
show: (data) => checkShowAction(data, "indexStepper"),
},
variable: {
type: "string",
ref: "variable",
Expand Down
14 changes: 11 additions & 3 deletions src/utils/__tests__/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ describe("actions", () => {
expect(app.doSave).toHaveBeenCalledTimes(0);
});

it("should do step cycle", async () => {
const actionObject = actions.find((action) => action.value === "cyclicGroup");
const stepCycle = jest.fn();
app.getDimension = () => ({ stepCycle });
await actionObject.getActionCall({ app, partial: true })();
expect(stepCycle).toHaveBeenCalledTimes(1);
});

it("should call executeAutomation when automationTriggered is true", async () => {
inputs = [];
const appId = "fakeAppId";
Expand Down Expand Up @@ -576,7 +584,7 @@ describe("actions", () => {
isEnabled: jest.fn().mockReturnValue(true),
};
const result = getActionsList(shouldHide);
expect(result.length).toBe(20);
expect(result.length).toBe(21);
});
it("should return all but not feature blacklisted navigations", () => {
const shouldHide = {
Expand All @@ -585,7 +593,7 @@ describe("actions", () => {
isEnabled: jest.fn().mockReturnValue(true),
};
const result = getActionsList(shouldHide);
expect(result.length).toBe(13);
expect(result.length).toBe(14);
});
it("should return all", () => {
const shouldHide = {
Expand All @@ -594,7 +602,7 @@ describe("actions", () => {
isEnabled: jest.fn().mockReturnValue(true),
};
const result = getActionsList(shouldHide);
expect(result.length).toBe(21);
expect(result.length).toBe(22);
});
});
});
13 changes: 13 additions & 0 deletions src/utils/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ const actions = [
hide: ({ isFeatureBlacklisted }) => isFeatureBlacklisted?.("advancedSelectionOptions"),
requiredInput: ["field", "softLock"],
},
{
value: "cyclicGroup",
translation: "Dimensions.Dialog.Type.CyclicGroup",
group: "selection",
getActionCall:
({ cyclicGroupId, indexStepper, app }) =>
async () => {
const model = await app.getDimension(cyclicGroupId);
await model.stepCycle(indexStepper);
},
hide: ({ isEnabled }) => !isEnabled("PS_21223_CYCLIC_GROUPS"),
requiredInput: ["cyclicGroup", "indexStepper"],
},
{
value: "selectExcluded",
translation: "Object.ActionButton.SelectExcluded",
Expand Down

0 comments on commit 311b679

Please sign in to comment.