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

feat: step cyclic dimension with sn-action-button #454

Merged
merged 7 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does unsupported feature navigations means? Is cyclic group an unsupported feature navigation?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for apps running in Direct Query mode. Unsupported features are controlled by engine and stored on the app layout. It would be good to verify if cyclic groups is something that can or cannot work in DQ apps

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Björn have noted this in our test plan. I guess in the mean time we let this test be like this until we know it has support or not

});
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does feature blacklisted navigations means? is cyclic group one of the feature blacklisted navigations?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also for apps running in Direct Query mode. The difference with unsupported features is that this is controlled by the client. Mostly bigger parts that just do not make sense when the app is DQ

});
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
Loading