Skip to content

Commit

Permalink
Asl/4495 keeping animal alive (#928)
Browse files Browse the repository at this point in the history
* Content updates for NTS fate of animals question (ref 1 in copy deck) and protocol fate of animals question (ref 2 in copy deck)

* conditional render and hyperlink done.

* conditional render on protocols and mapped nts - protocols correctly.

* reverting change made in error.

* applied eslint.

* existing modal using it has no CSS.

* dynaic checkbox text in the modal.

* css styling applied, cancel button is dif from design. Clear functionality on subquestion todo.

* Content updates for NTS fate of animals question (ref 1 in copy deck) and protocol fate of animals question (ref 2 in copy deck)

* conditional render and hyperlink done.

* conditional render on protocols and mapped nts - protocols correctly.

* reverting change made in error.

* applied eslint.

* existing modal using it has no CSS.

* dynaic checkbox text in the modal.

* css styling applied, cancel button is dif from design. Clear functionality on subquestion todo.

* apply css from stylesheet.

* match design.

* nts-modal work: successfully wrapped Checkbox component.

* complete refactor of checkbox and modal to appear in NTS with CSS. React comp done.

* eslint fix, existing test passing.

* ASL-4495 complete.

* ASL-4495 complete

* Content updates for NTS fate of animals question (ref 1 in copy deck) and protocol fate of animals question (ref 2 in copy deck)

* conditional render and hyperlink done.

* conditional render on protocols and mapped nts - protocols correctly.

* reverting change made in error.

* applied eslint.

* killing & use-in-other-project clearing nodes successfully.

* test stub data fixed as redux state shows.

* package-lock commit

* cancel button CSS matched.

* adding href to elimate WAG2.2 issue.

* crawl over all avilable protocols and handle changes based on checkbox selection.

* nts checkboxes to use special field set.

* nts checkboxes to use special field set.

* refactor method to be less expressive.

* lint applied

* use map over foreach as it safer approach.

* version update in package.json

* lock file commited so the pipleline reads the changes.

* merge master

* kept alive use not covered in checks.

* fixed issue with protocol

* bug fix on protocol review, fate-of-animal undefined.

* Update protocols.js

* refactor the code for readability.

* markdown url to return url when client side, otherwise parm.

* test added to mock window object and test if window is obj is null. to address client and server side rendering.

* typo fixed.

* ensure that else path also have options set to it.

---------

Co-authored-by: edemirbag <[email protected]>
  • Loading branch information
farrukhishaq and edemirbag authored Aug 2, 2024
1 parent 6d581e7 commit 29777d3
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
16 changes: 12 additions & 4 deletions client/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,16 @@ export const isTrainingLicence = values => {
};

export const getCurrentURLForFateOfAnimals = () => {
let currentURL = window.location.href;
// Remove everything after '/edit/' including 'protocols' and everything after it
currentURL = currentURL.split('/edit/')[0] + '/edit/fate-of-animals';
return currentURL;
if (window.location.href) {
return window.location.href.split('/edit/')[0] + '/edit/fate-of-animals';
}
return null;
};

export const UrlMarkdown = (linkText) => {
const url = getCurrentURLForFateOfAnimals();
if (url == null) {
return linkText;
}
return `[${linkText}](${url})`;
};
4 changes: 2 additions & 2 deletions client/pages/sections/protocols/protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ class Protocol extends PureComponent {

if (editable) {
const conditionalFateOfAnimalFields = renderFieldsInProtocol(this.props.project['fate-of-animals']);

// Ensure options array exists and is initialized properly
_.set(this.props.sections, 'fate.fields[0].options', _.get(this.props.sections, 'fate.fields[0].options', []));

// Update the options array with unique fields
this.props.sections.fate.fields[0].options = conditionalFateOfAnimalFields;
} else {
// Ensure options array exists and is initialized properly
_.set(this.props.sections, 'fate.fields[0].options', _.get(this.props.sections, 'fate.fields[0].options', []));
this.props.sections.fate.fields[0].options = NTSFateOfAnimalFields();
}

Expand Down
18 changes: 9 additions & 9 deletions client/schema/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import permissiblePurpose from './permissible-purpose';

import confirmProtocolsAffected from '../../helpers/confirm-protocols-affected';

import { isTrainingLicence, getCurrentURLForFateOfAnimals } from '../../helpers';
import {isTrainingLicence, UrlMarkdown} from '../../helpers';

export default () => {
return ({
Expand Down Expand Up @@ -1969,7 +1969,7 @@ export default () => {
{
name: 'fate',
label: 'What will happen to animals at the end of this protocol?',
hint: `Select all that apply. These options are based on what you selected in the [non-technical summary](${getCurrentURLForFateOfAnimals()}).`,
hint: `Select all that apply. These options are based on what you selected in the ${UrlMarkdown('non-technical summary')}.`,
type: 'checkbox',
preserveHierarchy: true,
className: 'smaller',
Expand Down Expand Up @@ -2286,7 +2286,7 @@ export default () => {
name: 'marmoset-colony',
label: 'Will all marmosets be sourced from a self-sustaining colony?',
hint: `This is a colony that is kept in captivity in a way that:
* ensures animals are accustomed to humans.
* consists only of animals that have been bred in captivity.
* is sustained only by animals bred within the same colony, or animals that are sourced from another self-sustaining colony.`,
Expand Down Expand Up @@ -2921,16 +2921,16 @@ export default () => {
title: 'Conditions',
subtitle: 'Additional conditions',
intro: `These additional conditions apply to the project as a whole.
Additional conditions that are specific to a set of procedures can be found in each protocol.`,
pdf: 'These additional conditions apply to the project as a whole. Additional conditions that are specific to a set of procedures can be found in each protocol. Standard conditions that apply to all project licences can be found at the end of this document.'
},
addMore: 'Add more conditions',
intro: `Additional conditions have been added automatically according to the selections made by the applicant.
Please review all sections of this application before making a recommendation.`,
emptyIntro: `Additional conditions have been added automatically according to the selections made by the applicant.
Please review all sections of this application before making a recommendation.`,
emptyIntroReadOnly: null,
type: 'condition',
Expand All @@ -2952,15 +2952,15 @@ export default () => {
},
review: GrantedAuthorisations,
intro: `These authorisations apply to the project as a whole.
Authorisations that are specific to a set of procedures can be found in each protocol.`
},
addMore: 'Add more authorisations',
intro: `Authorisations have been added automatically according to the selections made by the applicant.
Please review all sections of this application before making a recommendation.`,
emptyIntro: `No authorisations have been added to this licence.
If you want to add an authorisation, you will need to create one.`,
emptyIntroReadOnly: 'No authorisations have been added to this licence.',
type: 'authorisation',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@asl/projects",
"version": "15.5.6",
"version": "15.5.7",
"description": "ASL PPL prototype",
"main": "client/external.js",
"styles": "assets/scss/projects.scss",
Expand Down
42 changes: 42 additions & 0 deletions test/specs/helpers/url-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import assert from 'assert';
import {getCurrentURLForFateOfAnimals, UrlMarkdown} from '../../../client/helpers';

// Mock window object
global.window = {
location: {
href: 'https://example.com/edit/some-page'
}
};

describe('getCurrentURLForFateOfAnimals', () => {
it('should return the correct URL for fate-of-animals', () => {
const expectedURL = 'https://example.com/edit/fate-of-animals';
const result = getCurrentURLForFateOfAnimals();
assert.strictEqual(result, expectedURL);
});

it('should return null if window.location.href is not set', () => {
// Mock the href to be null
window.location.href = '';
const result = getCurrentURLForFateOfAnimals();
assert.strictEqual(result, null);
});
});

describe('UrlMarkdown', () => {
it('should return the anchor name with the correct URL markdown', () => {
window.location.href = 'https://example.com/edit/some-page';
const anchoreName = 'Fate of Animals';
const expectedMarkdown = '[Fate of Animals](https://example.com/edit/fate-of-animals)';
const result = UrlMarkdown(anchoreName);
assert.strictEqual(result, expectedMarkdown);
});

it('should return the anchor name if URL is null', () => {
// Mock the href to be null
window.location.href = '';
const anchoreName = 'Fate of Animals';
const result = UrlMarkdown(anchoreName);
assert.strictEqual(result, anchoreName);
});
});

0 comments on commit 29777d3

Please sign in to comment.