Skip to content

Commit

Permalink
Merge branch 'main' into feat/1454-smp-success-on-parent-step-5
Browse files Browse the repository at this point in the history
  • Loading branch information
ngunner15 authored Oct 4, 2024
2 parents 2e15589 + bf41772 commit 4a36f25
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
jobs:
cleanup:
name: Cleanup and Images
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected].0
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected].1
secrets:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_token: ${{ secrets.OC_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
validate:
name: Validate PR
needs: [init]
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected].0
uses: bcgov/quickstart-openshift-helpers/.github/workflows/[email protected].1
with:
markdown_links: |
- [Frontend](https://${{ github.event.repository.name }}-${{ needs.init.outputs.mod-tag }}-frontend.apps.silver.devops.gov.bc.ca/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ public final class Constants {
public static final String INCOMPLETE_SEEDLOT_STATUS = "INC";
public static final String PENDING_SEEDLOT_STATUS = "PND";
public static final String SUBMITTED_SEEDLOT_STATUS = "SUB";
public static final String MINITRY_OF_FORESTS_ID = "00012797";
public static final String MINISTRY_OF_FORESTS_ID = "00012797";
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,28 @@ public static Set<String> getUserRolesFromJwt(Jwt jwtPrincipal) {
*/
public static List<String> getClientIdsFromJwt(Jwt jwtPrincipal) {
List<String> clientIds = new ArrayList<>();
getRolesWithClientIds(jwtPrincipal)
.forEach(
role -> {
if (role.length() >= 9) {
String clientNumber = role.substring(role.length() - 8);
if (clientNumber.replaceAll("[0-9]", "").isEmpty()) {
clientIds.add(clientNumber);
}
}
// Handling concrete roles with no client id affixed
if (concreteRoles.contains(role)
&& !clientIds.contains(Constants.MINITRY_OF_FORESTS_ID)) {
clientIds.add(Constants.MINITRY_OF_FORESTS_ID);
}
});
boolean foundRole = false;

List<String> rolesAndClientIds = getRolesWithClientIds(jwtPrincipal);
for (String role : rolesAndClientIds) {
if (role.length() >= 9) {
String clientNumber = role.substring(role.length() - 8);
if (clientNumber.replaceAll("[0-9]", "").isEmpty()) {
clientIds.add(clientNumber);
}
}

if (concreteRoles.contains(role)) {
foundRole = true;
}
}

// If has role SPAR_MINISTRY_ORCHARD or SPAR_TSC_ADMIN and has no client id
// then add MOF client id
if (foundRole && !clientIds.contains(Constants.MINISTRY_OF_FORESTS_ID)) {
clientIds.add(Constants.MINISTRY_OF_FORESTS_ID);
}

return clientIds;
}

Expand Down
70 changes: 70 additions & 0 deletions frontend/src/components/SeedlotNavigator/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';

import {
Button, TextInput, Column
} from '@carbon/react';
import { ArrowRight } from '@carbon/icons-react';
import ROUTES from '../../routes/constants';
import useWindowSize from '../../hooks/UseWindowSize';
import { MEDIUM_SCREEN_WIDTH } from '../../shared-constants/shared-constants';

import { addParamToPath } from '../../utils/PathUtils';
import focusById from '../../utils/FocusUtils';
import { isNumeric } from '../../utils/NumberUtils';

import './styles.scss';

const SeedlotNavigator = () => {
const navigate = useNavigate();
const windowSize = useWindowSize();

const [seedlotNumber, setSeedlotNumber] = useState<string>('');
const [errorMessage, setErrorMessage] = useState<string>('');

return (
<>
<Column className="no-padding-col" sm={4} md={6} lg={12} xlg={12}>
<TextInput
id="go-to-seedlot-input"
labelText=""
placeholder="Enter seedlot number"
value={seedlotNumber}
invalid={!!errorMessage}
invalidText={errorMessage}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
const inputValue = e.target.value;
if (inputValue && !isNumeric(inputValue)) {
setErrorMessage('Numbers only');
return;
}

setSeedlotNumber(e.target.value);
setErrorMessage('');
}}
onWheel={(e: React.ChangeEvent<HTMLInputElement>) => e.target.blur()}
/>
</Column>
<Column className="no-padding-col" sm={4} md={2} lg={4} xlg={4}>
<Button
className={`seedlot-nav-btn ${windowSize.innerWidth >= MEDIUM_SCREEN_WIDTH && 'seedlot-nav-btn-float-right'}`}
kind="primary"
size="md"
renderIcon={ArrowRight}
onClick={() => {
if (seedlotNumber) {
navigate(addParamToPath(ROUTES.SEEDLOT_DETAILS, seedlotNumber));
} else {
setErrorMessage('Please enter a seedlot number');
focusById('go-to-seedlot-input');
}
}}
>
Go to seedlot
</Button>
</Column>
</>
);
};

export default SeedlotNavigator;
14 changes: 14 additions & 0 deletions frontend/src/components/SeedlotNavigator/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@use "@bcgov-nr/nr-theme/design-tokens/variables.scss" as vars;
@use "@carbon/type";

.seedlot-nav-btn {
width: fit-content;
max-width: 16rem;
margin-top: 1rem;
white-space: nowrap;
}

.seedlot-nav-btn-float-right {
float: right;
margin-top: 0;
}
2 changes: 2 additions & 0 deletions frontend/src/utils/NumberUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const isFloatWithinRange = (value: string, min: string, max: string): boo
new BigNumber(value).isGreaterThanOrEqualTo(min)
&& new BigNumber(value).isLessThanOrEqualTo(max)
);

export const isNumeric = (value: string) => value.replace(/[0-9]/g, '').length === 0;
4 changes: 4 additions & 0 deletions frontend/src/views/Seedlot/MySeedlots/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SeedlotTable from '../../../components/SeedlotTable';
import ROUTES from '../../../routes/constants';
import useWindowSize from '../../../hooks/UseWindowSize';
import { MEDIUM_SCREEN_WIDTH } from '../../../shared-constants/shared-constants';
import SeedlotNavigator from '../../../components/SeedlotNavigator';

import { tableText } from './constants';

Expand Down Expand Up @@ -56,6 +57,9 @@ const MySeedlots = () => {
</Button>
</Column>
</Row>
<Row className="my-seedlot-nav">
<SeedlotNavigator />
</Row>
<Row className="my-seedlot-data-table-row">
<SeedlotTable
userId={userId}
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/views/Seedlot/MySeedlots/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@
.no-padding-col {
padding: 0;
}

.my-seedlot-nav {
justify-content: space-around;
margin: 0 2.5rem 2.5rem 2.5rem;
}
}
54 changes: 7 additions & 47 deletions frontend/src/views/Seedlot/ReviewSeedlots/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
import React, {
useContext,
useEffect,
useState
} from 'react';
import React, { useContext, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

import {
TextInput,
Button,
Row,
Column,
Breadcrumb,
BreadcrumbItem,
FlexGrid
} from '@carbon/react';
import { ArrowRight } from '@carbon/icons-react';
import PageTitle from '../../../components/PageTitle';
import AuthContext from '../../../contexts/AuthContext';
import SeedlotTable from '../../../components/SeedlotTable';
import SeedlotNavigator from '../../../components/SeedlotNavigator';

import ROUTES from '../../../routes/constants';
import { addParamToPath } from '../../../utils/PathUtils';
import focusById from '../../../utils/FocusUtils';

import './styles.scss';

Expand All @@ -29,9 +22,6 @@ const ReviewSeedlots = () => {
const { user, isTscAdmin } = useContext(AuthContext);
const userId = user?.userId ?? '';

const [seedlotNumber, setSeedlotNumber] = useState<string>('');
const [seedlotInputErr, setSeedlotInputErr] = useState<boolean>(false);

useEffect(() => {
if (!isTscAdmin) {
navigate(ROUTES.FOUR_OH_FOUR);
Expand All @@ -42,7 +32,9 @@ const ReviewSeedlots = () => {
<FlexGrid fullWidth className="review-seedlots-content">
<Row className="review-seedlots-breadcrumb">
<Breadcrumb>
<BreadcrumbItem onClick={() => navigate(ROUTES.SEEDLOTS)}>Seedlots</BreadcrumbItem>
<BreadcrumbItem onClick={() => navigate(ROUTES.SEEDLOTS)}>
Seedlots
</BreadcrumbItem>
</Breadcrumb>
</Row>
<Row className="review-seedlots-title">
Expand All @@ -55,39 +47,7 @@ const ReviewSeedlots = () => {
</Column>
</Row>
<Row className="go-to-seedlot-section">
<Column className="no-padding-col" sm={4} md={6} lg={14} xlg={14}>
<TextInput
id="go-to-seedlot-input"
type="number"
labelText=""
placeholder="Enter seedlot number"
value={seedlotNumber}
invalid={seedlotInputErr}
invalidText="Please, enter a seedlot number"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setSeedlotInputErr(false);
setSeedlotNumber(e.target.value);
}}
onWheel={(e: React.ChangeEvent<HTMLInputElement>) => e.target.blur()}
/>
</Column>
<Column sm={4} md={2} lg={2} xlg={2}>
<Button
kind="primary"
size="md"
renderIcon={ArrowRight}
onClick={() => {
if (seedlotNumber) {
navigate(addParamToPath(ROUTES.SEEDLOT_DETAILS, seedlotNumber));
} else {
setSeedlotInputErr(true);
focusById('go-to-seedlot-input');
}
}}
>
Go to seedlot
</Button>
</Column>
<SeedlotNavigator />
</Row>
<div className="review-seedlots-table-wrapper">
<Row className="review-seedlots-data-table-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import ROUTES from '../../../../routes/constants';
import AuthContext from '../../../../contexts/AuthContext';
import SeedlotTable from '../../../../components/SeedlotTable';
import Subtitle from '../../../../components/Subtitle';
import SeedlotNavigator from '../../../../components/SeedlotNavigator';

import { getSubTitle, getTitle } from './constants';

Expand All @@ -23,7 +24,9 @@ const RecentSeedlots = () => {
<Row className="recent-seedlots">
<Column
sm={4}
className={`recent-seedlots-title-section ${isTscAdmin ? 'review-seedlots-table-header' : ''}`}
className={`recent-seedlots-title-section ${
isTscAdmin ? 'review-seedlots-table-header' : ''
}`}
onClick={() => {
if (isTscAdmin) {
navigate(ROUTES.TSC_SEEDLOTS_TABLE);
Expand All @@ -32,17 +35,29 @@ const RecentSeedlots = () => {
>
<div>
<h2>{getTitle(isTscAdmin)}</h2>
<Subtitle text={getSubTitle(isTscAdmin)} className="recent-seedlots-subtitle" />
<Subtitle
text={getSubTitle(isTscAdmin)}
className="recent-seedlots-subtitle"
/>
</div>
{
isTscAdmin
? (
<IconButton className="std-card-button" kind="ghost" label="Go" align="bottom" onClick={() => { navigate(ROUTES.TSC_SEEDLOTS_TABLE); }}>
<ArrowRight />
</IconButton>
)
: null
}
{isTscAdmin ? (
<IconButton
className="std-card-button"
kind="ghost"
label="Go"
align="bottom"
onClick={() => {
navigate(ROUTES.TSC_SEEDLOTS_TABLE);
}}
>
<ArrowRight />
</IconButton>
) : null}
</Column>
<Column sm={4}>
<Row className="recent-seedlots-navigator">
<SeedlotNavigator />
</Row>
</Column>
<Column sm={4} className="recent-seedlots-table">
<SeedlotTable userId={userId} isTscAdmin={isTscAdmin} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@
background-color: var(--#{vars.$bcgov-prefix}-layer-hover-01);
cursor: pointer;
}

.recent-seedlots-navigator {
justify-content: space-around;
margin-bottom: 1rem;
}
}

0 comments on commit 4a36f25

Please sign in to comment.