Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/v2.5.4 [main] #563

Merged
merged 3 commits into from
Dec 19, 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
4 changes: 3 additions & 1 deletion .github/workflows/update-jira-tickets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ jobs:
echo "tickets=${jiraTickets}" >> $GITHUB_OUTPUT

- name: Periodically ping Jenkins for current tag build status
env:
REPO_URL: "${{ github.server_url }}/${{ github.repository }}"
run: |
repoName=${GITHUB_REPOSITORY##*/}
currentTag="${{ steps.get-tag.outputs.tag }}"
Expand All @@ -124,7 +126,7 @@ jobs:
if [[ "$result" == "SUCCESS" ]]; then
echo "Build successful! Submitting ticket numbers to Jira"
tickets="${{ steps.jira-tickets.outputs.tickets }}"
json="{ \"issues\": $(echo "${tickets}" | jq -R -s -c 'split(" ")[:-1]') }"
json="{ \"issues\": $(echo "${tickets}" | jq -R -s -c 'split(" ")[:-1]'), \"data\": { \"tag\": \"${currentTag}\", \"repository\": \"${REPO_URL}\" } }"
curl -X POST -H 'Content-Type: application/json' --url "${JIRA_WEBHOOK_URL}" --data "$json"
break
elif [[ "$result" != "null" ]]; then
Expand Down
76 changes: 31 additions & 45 deletions src/entities/activity/ui/items/ActionPlan/pageComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import {
SentencePageComponent,
TextItemResponsePageComponent,
} from './Document.type';
import { ActivitiesPhrasalData, ActivityPhrasalDataSliderRowContext } from './phrasalData';
import {
ActivitiesPhrasalData,
ActivityPhrasalDataSliderContext,
ActivityPhrasalDataSliderRowContext,
} from './phrasalData';

const isAnswersSkipped = (answers: string[]): boolean => {
if (!answers || answers.length <= 0) {
Expand All @@ -32,13 +36,12 @@ const isAnswersSkipped = (answers: string[]): boolean => {

const identity: FieldValueTransformer = (value) => value;
const sliderValueTransformer =
(
t: TFunction,
ctx: ActivityPhrasalDataSliderRowContext,
itemIndex: number,
): FieldValueTransformer =>
(t: TFunction, maxValue: number): FieldValueTransformer =>
(value) =>
t('sliderValue', { value, total: ctx.maxValues[itemIndex] });
t('sliderValue', {
value,
total: maxValue,
});

const joinWithComma: FieldValueItemsJoiner = (values) => values.join(', ');
const joinWithDash: FieldValueItemsJoiner = (values) => values.join(' - ');
Expand Down Expand Up @@ -79,11 +82,17 @@ export const buildPageComponents = (
if (fieldPhrasalData) {
let transformValue = identity;
let joinValueItems = joinWithComma;
if (fieldPhrasalData.context.itemResponseType === 'sliderRows') {
if (fieldPhrasalData.context.itemResponseType === 'slider') {
transformValue = sliderValueTransformer(
t,
(fieldPhrasalData.context as ActivityPhrasalDataSliderContext).maxValue,
);
} else if (fieldPhrasalData.context.itemResponseType === 'sliderRows') {
transformValue = sliderValueTransformer(
t,
fieldPhrasalData.context as ActivityPhrasalDataSliderRowContext,
field.itemIndex,
(fieldPhrasalData.context as ActivityPhrasalDataSliderRowContext).maxValues[
field.itemIndex
],
);
} else if (fieldPhrasalData.context.itemResponseType === 'timeRange') {
joinValueItems = joinWithDash;
Expand All @@ -100,44 +109,21 @@ export const buildPageComponents = (
? [t('questionSkipped')]
: indexedAnswers.map(transformValue);
} else if (fieldPhrasalDataType === 'matrix') {
// The admin UI actually allows matrix type items to have `sentence` as
// their display mode. So in this case, we're just going to assume the
// effective render order for the values to be "by row".
let renderByRowValues = true;
if (
field.displayMode === 'sentence_option_row' ||
field.displayMode === 'bullet_list_option_row'
) {
renderByRowValues = false;
} else if (
const rowFirst =
field.displayMode === 'sentence_row_option' ||
field.displayMode === 'bullet_list_text_row'
) {
renderByRowValues = true;
field.displayMode === 'bullet_list_text_row';

valueItems = [];
for (const { rowLabel, columnLabels } of fieldPhrasalData.values) {
for (const columnLabel of columnLabels) {
valueItems.push(
rowFirst ? `${rowLabel} ${columnLabel}` : `${columnLabel} ${rowLabel}`,
);
}
}

if (renderByRowValues) {
valueItems = fieldPhrasalData.values.byRow
.map(({ label, values }) => {
const transformedValues = isAnswersSkipped(values)
? [t('questionSkipped')]
: values.map(transformValue);
return transformedValues.map(
(transformedValue) => `${label} ${transformedValue}`,
);
})
.flat();
} else {
valueItems = fieldPhrasalData.values.byColumn
.map(({ label, values }) => {
const transformedValues = isAnswersSkipped(values)
? [t('questionSkipped')]
: values.map(transformValue);
return transformedValues.map(
(transformedValue) => `${label} ${transformedValue}`,
);
})
.flat();
if (isAnswersSkipped(valueItems)) {
valueItems = [t('questionSkipped')];
}
} else {
// This also shouldn't happen. But including a `else` here allows all
Expand Down
56 changes: 24 additions & 32 deletions src/entities/activity/ui/items/ActionPlan/phrasalData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ describe('Action Plan', () => {
const newTimeItem = newSimpleItem('time');
const newTimeRangeItem = newSimpleItem('timeRange');
const newNumberSelectItem = newSimpleItem<number>('numberSelect');
const newSliderItem = newSimpleItem('slider');
const newTextItem = newSimpleItem('text');

const newSelectItem = (type: string) => (name: string, answer: string[], options: string[]) =>
Expand All @@ -53,14 +52,14 @@ describe('Action Plan', () => {
responseType: 'multiSelectRows',
responseValues: {
rows: options[0].map((option) => ({ rowName: option })),
options: options[1].map((option) => ({ text: option })),
options: options[1].map((option, index) => ({ id: `col:${index}`, text: option })),
},
answer,
}) as never as ItemRecord;

const newSingleSelectRowsItem = (
name: string,
answer: string[],
answer: (string | null)[],
options: [string[], string[]],
) =>
({
Expand All @@ -73,6 +72,14 @@ describe('Action Plan', () => {
answer,
}) as never as ItemRecord;

const newSliderItem = (name: string, answer: string[], maxValue: number) =>
({
name,
responseType: 'slider',
responseValues: { maxValue },
answer,
}) as never as ItemRecord;

const newSliderRowsItem = (name: string, answer: number[], options: [number, number][]) =>
({
name,
Expand Down Expand Up @@ -132,12 +139,13 @@ describe('Action Plan', () => {
});

it('should extract data from `slider` activity type', () => {
const data = extractActivitiesPhrasalData([newSliderItem('item', ['6'])]);
const data = extractActivitiesPhrasalData([newSliderItem('item', ['6'], 10)]);

expect(data).toHaveProperty('item');
expect(data.item).toHaveProperty('type', 'array');
expect(data.item).toHaveProperty('values.0', '6');
expect(data.item).toHaveProperty('context.itemResponseType', 'slider');
expect(data.item).toHaveProperty('context.maxValue', 10);
});

it('should extract data from `text` activity type', () => {
Expand Down Expand Up @@ -199,22 +207,12 @@ describe('Action Plan', () => {

expect(data).toHaveProperty('item');
expect(data.item).toHaveProperty('type', 'matrix');
expect(data.item).toHaveProperty('values.byRow.0.label', 'R1');
expect(data.item).toHaveProperty('values.byRow.0.values.0', 'C1');
expect(data.item).toHaveProperty('values.byRow.0.values.1', 'C2');
expect(data.item).toHaveProperty('values.byRow.1.label', 'R2');
expect(data.item).toHaveProperty('values.byRow.1.values.0', 'C2');
expect(data.item).toHaveProperty('values.byRow.2.label', 'R3');
expect(data.item).toHaveProperty('values.byRow.2.values.0', 'C2');
expect(data.item).toHaveProperty('values.byRow.2.values.1', 'C3');
expect(data.item).toHaveProperty('values.byColumn.0.label', 'C1');
expect(data.item).toHaveProperty('values.byColumn.0.values.0', 'R1');
expect(data.item).toHaveProperty('values.byColumn.1.label', 'C2');
expect(data.item).toHaveProperty('values.byColumn.1.values.0', 'R1');
expect(data.item).toHaveProperty('values.byColumn.1.values.1', 'R2');
expect(data.item).toHaveProperty('values.byColumn.1.values.2', 'R3');
expect(data.item).toHaveProperty('values.byColumn.2.label', 'C3');
expect(data.item).toHaveProperty('values.byColumn.2.values.0', 'R3');
expect(data.item).toHaveProperty('values.0.rowLabel', 'R1');
expect(data.item).toHaveProperty('values.0.columnLabels', ['C1', 'C2']);
expect(data.item).toHaveProperty('values.1.rowLabel', 'R2');
expect(data.item).toHaveProperty('values.1.columnLabels', ['C2']);
expect(data.item).toHaveProperty('values.2.rowLabel', 'R3');
expect(data.item).toHaveProperty('values.2.columnLabels', ['C2', 'C3']);
expect(data.item).toHaveProperty('context.itemResponseType', 'multiSelectRows');
});

Expand All @@ -232,18 +230,12 @@ describe('Action Plan', () => {

expect(data).toHaveProperty('item');
expect(data.item).toHaveProperty('type', 'matrix');
expect(data.item).toHaveProperty('values.byRow.0.label', 'R1');
expect(data.item).toHaveProperty('values.byRow.0.values.0', 'C3');
expect(data.item).toHaveProperty('values.byRow.1.label', 'R2');
expect(data.item).toHaveProperty('values.byRow.1.values.0', 'C1');
expect(data.item).toHaveProperty('values.byRow.2.label', 'R3');
expect(data.item).toHaveProperty('values.byRow.2.values.0', 'C2');
expect(data.item).toHaveProperty('values.byColumn.0.label', 'C1');
expect(data.item).toHaveProperty('values.byColumn.0.values.0', 'R2');
expect(data.item).toHaveProperty('values.byColumn.1.label', 'C2');
expect(data.item).toHaveProperty('values.byColumn.1.values.0', 'R3');
expect(data.item).toHaveProperty('values.byColumn.2.label', 'C3');
expect(data.item).toHaveProperty('values.byColumn.2.values.0', 'R1');
expect(data.item).toHaveProperty('values.0.rowLabel', 'R1');
expect(data.item).toHaveProperty('values.0.columnLabels', ['C3']);
expect(data.item).toHaveProperty('values.1.rowLabel', 'R2');
expect(data.item).toHaveProperty('values.1.columnLabels', ['C1']);
expect(data.item).toHaveProperty('values.2.rowLabel', 'R3');
expect(data.item).toHaveProperty('values.2.columnLabels', ['C2']);
expect(data.item).toHaveProperty('context.itemResponseType', 'singleSelectRows');
});

Expand Down
Loading
Loading