Skip to content

Commit

Permalink
fibre/fibres/fibers -> fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed May 21, 2024
1 parent 9176f3e commit 9e87168
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 42 deletions.
2 changes: 1 addition & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"goalEnergy": "Energy goal",
"goalProtein": "Protein goal",
"goalCarbohydrates": "Carbohydrates goal",
"goalFibers": "Fibers goal",
"goalFiber": "Fiber goal",
"goalFat": "Fat goal",
"addNutritionalDiary": "Add nutrition diary entry",
"meal": "Meal",
Expand Down
14 changes: 7 additions & 7 deletions src/components/Nutrition/helpers/nutritionalValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type NutritionalValuesConstructor = {
carbohydratesSugar?: number;
fat?: number;
fatSaturated?: number;
fibres?: number;
fiber?: number;
sodium?: number;
bodyWeight?: number;
}
Expand All @@ -29,7 +29,7 @@ export class NutritionalValues {
carbohydratesSugar: number = 0;
fat: number = 0;
fatSaturated: number = 0;
fibres: number = 0;
fiber: number = 0;
sodium: number = 0;

get energyKj(): number {
Expand Down Expand Up @@ -64,7 +64,7 @@ export class NutritionalValues {
this.carbohydratesSugar = values?.carbohydratesSugar ?? 0;
this.fat = values?.fat ?? 0;
this.fatSaturated = values?.fatSaturated ?? 0;
this.fibres = values?.fibres ?? 0;
this.fiber = values?.fiber ?? 0;
this.sodium = values?.sodium ?? 0;
this.bodyWeight = values?.bodyWeight ?? 0;
}
Expand All @@ -83,7 +83,7 @@ export class NutritionalValues {
out.carbohydratesSugar = ingredient.carbohydratesSugar ? ingredient.carbohydratesSugar * weight / 100 : 0;
out.fat = ingredient.fat * weight / 100;
out.fatSaturated = ingredient.fatSaturated ? ingredient.fatSaturated * weight / 100 : 0;
out.fibres = ingredient.fibres ? ingredient.fibres * weight / 100 : 0;
out.fiber = ingredient.fiber ? ingredient.fiber * weight / 100 : 0;
out.sodium = ingredient.sodium ? ingredient.sodium * weight / 100 : 0;

return out;
Expand All @@ -97,14 +97,14 @@ export class NutritionalValues {
this.carbohydratesSugar += other.carbohydratesSugar;
this.fat += other.fat;
this.fatSaturated += other.fatSaturated;
this.fibres += other.fibres;
this.fiber += other.fiber;
this.sodium += other.sodium;

return this;
}

toString(): string {
return `e: ${this.energy}, p: ${this.protein}, c: ${this.carbohydrates}, cS: ${this.carbohydratesSugar}, f: ${this.fat}, fS: ${this.fatSaturated}, fi: ${this.fibres}, s: ${this.sodium}`;
return `e: ${this.energy}, p: ${this.protein}, c: ${this.carbohydrates}, cS: ${this.carbohydratesSugar}, f: ${this.fat}, fS: ${this.fatSaturated}, fi: ${this.fiber}, s: ${this.sodium}`;
}

equals(other: NutritionalValues): boolean {
Expand All @@ -115,7 +115,7 @@ export class NutritionalValues {
this.carbohydratesSugar === other.carbohydratesSugar &&
this.fat === other.fat &&
this.fatSaturated === other.fatSaturated &&
this.fibres === other.fibres &&
this.fiber === other.fiber &&
this.sodium === other.sodium
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Nutrition/models/Ingredient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Ingredient {
public carbohydratesSugar: number | null,
public fat: number,
public fatSaturated: number | null,
public fibres: number | null,
public fiber: number | null,
public sodium: number | null,
public image: IngredientImage | null = null,
) {
Expand All @@ -36,7 +36,7 @@ export class IngredientAdapter implements Adapter<Ingredient> {
item.carbohydrates_sugar === null ? null : parseFloat(item.carbohydrates_sugar),
parseFloat(item.fat),
item.fat_saturated === null ? null : parseFloat(item.fat_saturated),
item.fibres === null ? null : parseFloat(item.fibres),
item.fiber === null ? null : parseFloat(item.fiber),
item.sodium === null ? null : parseFloat(item.sodium),
item.image === null ? null : new IngredientImageAdapter().fromJson(item.image),
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Nutrition/models/mealItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe("Test the meal item model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(611.999, 2);
expect(values.fat).toBeCloseTo(198, 2);
expect(values.fatSaturated).toBeCloseTo(54, 2);
expect(values.fibres).toBeCloseTo(30, 2);
expect(values.fiber).toBeCloseTo(30, 2);
expect(values.sodium).toBeCloseTo(2.4, 2);
});
});
12 changes: 6 additions & 6 deletions src/components/Nutrition/models/nutritionalPlan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("Test the nutritional plan model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(44.35, 2);
expect(values.fat).toBeCloseTo(6.51, 2);
expect(values.fatSaturated).toBeCloseTo(1.58, 2);
expect(values.fibres).toBeCloseTo(5.25, 2);
expect(values.fiber).toBeCloseTo(5.25, 2);
expect(values.sodium).toBeCloseTo(0.064, 2);
});

Expand All @@ -41,7 +41,7 @@ describe("Test the nutritional plan model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(9.424, 2);
expect(values.fat).toBeCloseTo(0, 2);
expect(values.fatSaturated).toBeCloseTo(0, 2);
expect(values.fibres).toBeCloseTo(0, 2);
expect(values.fiber).toBeCloseTo(0, 2);
expect(values.sodium).toBeCloseTo(0.0048, 2);
});

Expand All @@ -57,7 +57,7 @@ describe("Test the nutritional plan model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(7.73, 2);
expect(values.fat).toBeCloseTo(1.77, 2);
expect(values.fatSaturated).toBeCloseTo(0.89, 2);
expect(values.fibres).toBeCloseTo(2.19, 2);
expect(values.fiber).toBeCloseTo(2.19, 2);
expect(values.sodium).toBeCloseTo(0.0085, 2);
});

Expand All @@ -73,7 +73,7 @@ describe("Test the nutritional plan model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(111.76, 2);
expect(values.fat).toBeCloseTo(165.239, 2);
expect(values.fatSaturated).toBeCloseTo(90.36, 2);
expect(values.fibres).toBeCloseTo(214.36, 2);
expect(values.fiber).toBeCloseTo(214.36, 2);
expect(values.sodium).toBeCloseTo(0.3296, 2);
});

Expand All @@ -89,7 +89,7 @@ describe("Test the nutritional plan model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(7.733, 2);
expect(values.fat).toBeCloseTo(1.7675, 2);
expect(values.fatSaturated).toBeCloseTo(0.89, 2);
expect(values.fibres).toBeCloseTo(2.1875, 2);
expect(values.fiber).toBeCloseTo(2.1875, 2);
expect(values.sodium).toBeCloseTo(0.0088, 2);
});

Expand All @@ -105,7 +105,7 @@ describe("Test the nutritional plan model", () => {
expect(values.carbohydratesSugar).toBeCloseTo(44.34999, 2);
expect(values.fat).toBeCloseTo(6.51, 2);
expect(values.fatSaturated).toBeCloseTo(1.58, 2);
expect(values.fibres).toBeCloseTo(5.25, 2);
expect(values.fiber).toBeCloseTo(5.25, 2);
expect(values.sodium).toBeCloseTo(0.064, 2);
});

Expand Down
12 changes: 8 additions & 4 deletions src/components/Nutrition/models/nutritionalPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ export class NutritionalPlan {
public goalEnergy: number | null = null,
public goalProtein: number | null = null,
public goalCarbohydrates: number | null = null,
public goalFibers: number | null = null,
public goalFiber: number | null = null,
public goalSodium: number | null = null,
public goalFat: number | null = null,
public goalFatsSaturated: number | null = null,
) {
}

Expand All @@ -39,7 +41,9 @@ export class NutritionalPlan {
}

get hasAnyAdvancedGoals() {
return this.goalFibers !== null;
return this.goalFiber !== null
|| this.goalSodium !== null
|| this.goalFatsSaturated !== null;
}

get hasAnyPlanned() {
Expand Down Expand Up @@ -159,7 +163,7 @@ export class NutritionalPlan {
out.carbohydratesSugar = out.carbohydratesSugar / nrOfEntries;
out.fat = out.fat / nrOfEntries;
out.fatSaturated = out.fatSaturated / nrOfEntries;
out.fibres = out.fibres / nrOfEntries;
out.fiber = out.fiber / nrOfEntries;
out.sodium = out.sodium / nrOfEntries;
return out;
}
Expand All @@ -182,7 +186,7 @@ export class NutritionalPlanAdapter implements Adapter<NutritionalPlan> {
item.goal_energy,
item.goal_protein,
item.goal_carbohydrates,
item.goal_fibers,
item.goal_fiber,
item.goal_fat,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ export const LoggedPlannedNutritionalValuesTable = (props: {
<TableCell></TableCell>
</TableRow>
<TableRow>
<TableCell>{t('nutrition.fibres')}</TableCell>
<TableCell>{t('nutrition.fiber')}</TableCell>
<TableCell align="right">
{numberGramLocale(props.planned.fibres, i18n.language)}
{numberGramLocale(props.planned.fiber, i18n.language)}
</TableCell>
<TableCell align="right">
{numberGramLocale(props.logged.fibres, i18n.language)}
{numberGramLocale(props.logged.fiber, i18n.language)}
</TableCell>
<TableCell align="right">
{numberGramLocale(props.logged.fibres - props.planned.fibres, i18n.language)}
{numberGramLocale(props.logged.fiber - props.planned.fiber, i18n.language)}
</TableCell>
</TableRow>
<TableRow>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Nutrition/widgets/NutritionalValuesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export const NutritionalValuesTable = (props: { values: NutritionalValues }) =>
{/*<TableCell align="right"></TableCell>*/}
</TableRow>
<TableRow>
<TableCell>{t('nutrition.fibres')}</TableCell>
<TableCell>{t('nutrition.fiber')}</TableCell>
<TableCell align="right">
{numberGramLocale(props.values.fibres, i18n.language)}
{numberGramLocale(props.values.fiber, i18n.language)}
</TableCell>
<TableCell align="right"></TableCell>
{/*<TableCell align="right"></TableCell>*/}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Nutrition/widgets/forms/PlanForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("Test the PlanForm component", () => {
// eslint-disable-next-line camelcase
goal_carbohydrates: null,
// eslint-disable-next-line camelcase
goal_fibers: null,
goal_fiber: null,
// eslint-disable-next-line camelcase
goal_energy: null,
// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -106,7 +106,7 @@ describe("Test the PlanForm component", () => {
// eslint-disable-next-line camelcase
goal_protein: null,
// eslint-disable-next-line camelcase
goal_fibers: null,
goal_fiber: null,
});
});
});
16 changes: 8 additions & 8 deletions src/components/Nutrition/widgets/forms/PlanForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const PlanForm = ({ plan, closeFn }: PlanFormProps) => {
.positive() // TODO: allow 0 but not negative
.max(750, t('forms.maxValue', { value: '750' })),
// eslint-disable-next-line camelcase
goal_fibers: yup
goal_fiber: yup
.number()
.notRequired()
.positive()
Expand All @@ -94,7 +94,7 @@ export const PlanForm = ({ plan, closeFn }: PlanFormProps) => {
// eslint-disable-next-line camelcase
goal_carbohydrates: plan ? plan.goalCarbohydrates : null,
// eslint-disable-next-line camelcase
goal_fibers: plan ? plan.goalFibers : null,
goal_fiber: plan ? plan.goalFiber : null,
// eslint-disable-next-line camelcase
goal_fat: plan ? plan.goalFat : null,
}}
Expand All @@ -108,7 +108,7 @@ export const PlanForm = ({ plan, closeFn }: PlanFormProps) => {
// eslint-disable-next-line camelcase
values.goal_carbohydrates = values.goal_carbohydrates ? values.goal_carbohydrates : null;
// eslint-disable-next-line camelcase
values.goal_fibers = values.goal_fibers ? values.goal_fibers : null;
values.goal_fiber = values.goal_fiber ? values.goal_fiber : null;
// eslint-disable-next-line camelcase
values.goal_fat = values.goal_fat ? values.goal_fat : null;

Expand Down Expand Up @@ -239,11 +239,11 @@ export const PlanForm = ({ plan, closeFn }: PlanFormProps) => {
<Grid container spacing={1}>
<Grid xs={4}>
<TextField
id="fibers"
label={t('nutrition.goalFibers')}
error={formik.touched.goal_fibers && Boolean(formik.errors.goal_fibers)}
helperText={formik.touched.goal_fibers && formik.errors.goal_fibers}
{...formik.getFieldProps('goal_fibers')}
id="fiber"
label={t('nutrition.goalFiber')}
error={formik.touched.goal_fiber && Boolean(formik.errors.goal_fiber)}
helperText={formik.touched.goal_fiber && formik.errors.goal_fiber}
{...formik.getFieldProps('goal_fiber')}
InputProps={{
startAdornment: <InputAdornment position="start">
{t('nutrition.valueEnergyKcal', { value: 0 })}
Expand Down
4 changes: 2 additions & 2 deletions src/services/ingredient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("Ingrediente service tests", () => {
"carbohydrates_sugar": "4.000",
"fat": "18.000",
"fat_saturated": "6.000",
"fibres": null,
"fiber": null,
"sodium": "0.508",
"license": 5,
"license_title": "감자깡",
Expand Down Expand Up @@ -65,7 +65,7 @@ describe("Ingrediente service tests", () => {
expect(result.carbohydratesSugar).toEqual(4);
expect(result.fat).toEqual(18);
expect(result.fatSaturated).toEqual(6);
expect(result.fibres).toEqual(null);
expect(result.fiber).toEqual(null);
expect(result.sodium).toEqual(0.508);
expect(result.image?.url).toEqual('http://localhost:8000/media/ingredients/59197/b260b245-efe9-4c92-9d8f-d2c4406221dd.jpg');

Expand Down
2 changes: 1 addition & 1 deletion src/services/nutritionalPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface AddNutritionalPlanParams {
goal_energy: number | string | null;
goal_protein: number | string | null;
goal_carbohydrates: number | string | null;
goal_fibers: number | string | null;
goal_fiber: number | string | null;
goal_fat: number | string | null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export interface ApiIngredientType {
carbohydrates_sugar: string | null,
fat: string,
fat_saturated: string | null,
fibres: string | null,
fiber: string | null,
sodium: string | null,
license: {
id: number,
Expand Down Expand Up @@ -111,7 +111,7 @@ export interface ApiNutritionalPlanType {
only_logging: boolean,
goal_energy: number | null,
goal_protein: number | null,
goal_fibers: number | null,
goal_fiber: number | null,
goal_carbohydrates: number | null,
goal_fat: number | null,
}
Expand Down

0 comments on commit 9e87168

Please sign in to comment.