Skip to content

Commit

Permalink
paginatorControls ignore read-only flag (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
dqnykamp authored Oct 29, 2023
1 parent f7a9273 commit c00bdbf
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 22 deletions.
71 changes: 71 additions & 0 deletions packages/doenetml-worker/src/components/Paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export class Paginator extends BlockComponent {
actionId,
sourceInformation,
skipRendererUpdate,
overrideReadOnly: true,
event: {
verb: "selected",
object: {
Expand Down Expand Up @@ -345,6 +346,76 @@ export class PaginatorControls extends BlockComponent {
},
};

// disabledDirectly for paginatorControls is not affected by the readOnly flag
// nor the parentDisabled flag
stateVariableDefinitions.disabledDirectly = {
public: true,
shadowingInstructions: {
createComponentOfType: "boolean",
},
forRenderer: true,
hasEssential: true,
doNotShadowEssential: true,
defaultValue: false,
returnDependencies: () => ({
disabledPreliminary: {
dependencyType: "stateVariable",
variableName: "disabledPreliminary",
variablesOptional: true,
},
sourceCompositeDisabled: {
dependencyType: "sourceCompositeStateVariable",
variableName: "disabled",
},
adapterSourceDisabled: {
dependencyType: "adapterSourceStateVariable",
variableName: "disabled",
},
}),
definition({ dependencyValues, usedDefault }) {
if (!usedDefault.disabledPreliminary) {
return {
setValue: {
disabledDirectly:
dependencyValues.disabledPreliminary,
},
};
}

let disabledDirectly = false;
let useEssential = true;

if (
dependencyValues.sourceCompositeDisabled !== null &&
!usedDefault.sourceCompositeDisabled
) {
disabledDirectly =
disabledDirectly ||
dependencyValues.sourceCompositeDisabled;
useEssential = false;
}
if (
dependencyValues.adapterSourceDisabled !== null &&
!usedDefault.adapterSourceDisabled
) {
disabledDirectly =
disabledDirectly ||
dependencyValues.adapterSourceDisabled;
useEssential = false;
}

if (useEssential) {
return {
useEssentialOrDefaultValue: {
disabledDirectly: true,
},
};
} else {
return { setValue: { disabledDirectly } };
}
},
};

return stateVariableDefinitions;
}
}
7 changes: 5 additions & 2 deletions packages/doenetml/src/Viewer/renderers/paginatorControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default React.memo(function PaginatorControls(props) {
args: { number: SVs.currentPage - 1 },
});
}}
disabled={SVs.disabled || !(SVs.currentPage > 1)}
disabled={SVs.disabledDirectly || !(SVs.currentPage > 1)}
value={SVs.previousLabel}
/>
</div>
Expand All @@ -38,7 +38,10 @@ export default React.memo(function PaginatorControls(props) {
args: { number: SVs.currentPage + 1 },
});
}}
disabled={SVs.disabled || !(SVs.currentPage < SVs.numPages)}
disabled={
SVs.disabledDirectly ||
!(SVs.currentPage < SVs.numPages)
}
value={SVs.nextLabel}
/>
</div>
Expand Down
31 changes: 11 additions & 20 deletions packages/test-cypress/cypress/e2e/tagSpecific/paginator.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2305,8 +2305,7 @@ describe("Paginator Tag Tests", function () {
cy.get(cesc2("#/ca")).should("have.text", "0.722");
});

// Do we restore this feature?
it.skip("Paginator controls ignore read only flag", () => {
it("Paginator controls ignore read only flag", () => {
let doenetML = `
<text>a</text>
<paginatorControls paginator="pgn" name="pcontrols" />
Expand All @@ -2324,11 +2323,6 @@ describe("Paginator Tag Tests", function () {
<p>Credit achieved: $_document1.creditAchieved{assignNames="ca"}</p>
`;

cy.get("#testRunner_toggleControls").click();
cy.get("#testRunner_allowLocalState").click();
cy.wait(100);
cy.get("#testRunner_toggleControls").click();

cy.window().then(async (win) => {
win.postMessage(
{
Expand Down Expand Up @@ -2356,29 +2350,26 @@ describe("Paginator Tag Tests", function () {
cy.get(cesc("#\\/ti2_submit")).should("be.visible");
cy.get(cesc2("#/ca")).should("have.text", "0.5");

// at least right now, this turns on Read Only
cy.get("h3 > button").click();
cy.get(":nth-child(5) > label > input").click();
cy.get("h3 > button").click();

cy.get(cesc("#\\/ti2_input")).should("be.disabled");
cy.get(cesc("#\\/ti2_input")).should("have.value", "2");
cy.get(cesc("#\\/ti2_submit")).should("be.disabled");
cy.get("#testRunner_toggleControls").click();
cy.get("#testRunner_readOnly").click();
cy.wait(100);
cy.get("#testRunner_toggleControls").click();

cy.get(cesc2("#/pcontrols_previous")).click();
cy.get(cesc2("#/_title1")).should("have.text", "Problem 1");
cy.get(cesc2("#/ca")).should("have.text", "0.5");

cy.get(cesc("#\\/ti1_input")).should("be.disabled");
cy.get(cesc("#\\/ti1_input")).should("have.value", "1");
cy.get(cesc("#\\/ti1_submit")).should("be.disabled");

cy.get(cesc2("#/pcontrols_next")).click();
cy.get(cesc2("#/_title2")).should("have.text", "Problem 2");
cy.get(cesc2("#/ca")).should("have.text", "0.5");

cy.get(cesc("#\\/ti2_input")).should("be.disabled");
cy.get(cesc("#\\/ti2_input")).should("have.value", "2");
cy.get(cesc("#\\/ti2_submit")).should("be.disabled");

cy.get(cesc2("#/pcontrols_previous")).click();
cy.get(cesc2("#/_title1")).should("have.text", "Problem 1");
cy.get(cesc("#\\/ti1_input")).should("be.disabled");
cy.get(cesc("#\\/ti1_submit")).should("be.disabled");
});

it("Variants stay consistent with external copies", () => {
Expand Down

0 comments on commit c00bdbf

Please sign in to comment.