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

[MINT-3221] MTO Table Action Component #1552

Merged
merged 24 commits into from
Dec 10, 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
71 changes: 10 additions & 61 deletions src/features/ModelPlan/ModelToOperations/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useHistory, useLocation, useParams } from 'react-router-dom';
import {
Button,
Grid,
Header,
Icon,
Expand All @@ -20,9 +19,9 @@ import { ModelInfoContext } from 'contexts/ModelInfoContext';
import useCheckResponsiveScreen from 'hooks/useCheckMobile';
import useMessage from 'hooks/useMessage';

import MTOModal from '../_components/FormModal';
import MTOStatusBanner from '../_components/StatusBanner';
import MTOTable from '../_components/Table';
import MTOTableActions from '../_components/Table/Actions';

export type MTOOption = 'milestones' | 'systems-and-solutions';

Expand All @@ -35,7 +34,7 @@ const MTOHome = () => {

const { modelName } = useContext(ModelInfoContext);

const { data, loading } = useGetModelToOperationsMatrixQuery({
const { data, loading, error, refetch } = useGetModelToOperationsMatrixQuery({
variables: {
id: modelID
}
Comment on lines +37 to 40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the useGetModelToOperationsMatrixQuery is also used in <MTOTable /> component. So, I thought to pass down the data needed, instead of calling the gql again.

Also, this allowed me to pass refetch down to the sibling component <MTOTableActions />

Expand All @@ -47,7 +46,7 @@ const MTOHome = () => {

const location = useLocation();

const { clearMessage, message } = useMessage();
const { message } = useMessage();

const params = useMemo(() => {
return new URLSearchParams(location.search);
Expand All @@ -59,12 +58,6 @@ const MTOHome = () => {

const [currentView, setCurrentView] = useState<MTOOption>('milestones');

const [isModalOpen, setIsModalOpen] = useState(false);

const [modalType, setModalType] = useState<
'category' | 'milestone' | 'solution'
>('category');

useEffect(() => {
if (viewparam && mtoOptions.includes(viewparam as MTOOption)) {
setCurrentView(viewparam as MTOOption);
Expand All @@ -85,7 +78,7 @@ const MTOHome = () => {
]}
/>

{!isModalOpen && message && <Expire delay={45000}>{message}</Expire>}
{message && <Expire delay={45000}>{message}</Expire>}

<Grid row className="margin-bottom-2">
<Grid desktop={{ col: 9 }}>
Expand Down Expand Up @@ -165,55 +158,6 @@ const MTOHome = () => {
</div>
</Header>

<div className="display-none2 margin-top-4">
<MTOModal
isOpen={isModalOpen}
closeModal={() => setIsModalOpen(false)}
modalType={modalType}
/>
<div className="width-fit-content">
{/* <div
style={{ paddingTop: '2px', paddingBottom: '2px' }}
className={classNames(
'display-flex flex-justify bg-base-lightest padding-x-3 text-white radius-top-lg bg-secondary-dark'
)}
>
TEMPORARY
</div> */}
<Button
type="button"
onClick={() => {
clearMessage();
setModalType('category');
setIsModalOpen(true);
}}
>
Add custom category
</Button>
<Button
type="button"
onClick={() => {
clearMessage();
setModalType('milestone');
setIsModalOpen(true);
}}
>
Add custom milestone
</Button>
<Button
type="button"
onClick={() => {
clearMessage();
setModalType('solution');
setIsModalOpen(true);
}}
className="margin-bottom-4"
>
Add custom solution
</Button>
</div>
</div>

{isTablet && (
<div className="maxw-mobile-lg">
<Select
Expand All @@ -237,7 +181,12 @@ const MTOHome = () => {
</div>
)}

{currentView === 'milestones' && <MTOTable />}
{currentView === 'milestones' && (
<>
<MTOTableActions refetch={() => refetch({ id: modelID })} />
<MTOTable queryData={data} loading={loading} error={error} />
</>
)}
</div>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,13 @@ exports[`Custom Solution form > matches snapshot 1`] = `
>
<span>
Please double-check that you aren't creating an operational solution or IT system that already exists in the
<span
class="text-underline text-primary-light"
<button
class="usa-button usa-button usa-button--unstyled margin-top-0"
data-testid="button"
type="button"
>
solution library
</span>
</button>
.
</span>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
useForm
} from 'react-hook-form';
import { Trans, useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import { useHistory, useParams } from 'react-router-dom';
import {
Button,
Fieldset,
Expand Down Expand Up @@ -39,6 +39,7 @@ const SolutionForm = ({ closeModal }: { closeModal: () => void }) => {
const { solutionType: solutionTypeConfig } =
usePlanTranslation('mtoSolution');

const history = useHistory();
const { modelID } = useParams<{ modelID: string }>();
const { message, showMessage, clearMessage } = useMessage();

Expand Down Expand Up @@ -262,8 +263,19 @@ const SolutionForm = ({ closeModal }: { closeModal: () => void }) => {
<Trans
i18nKey={t('modal.solution.alert.info')}
components={{
s: <span className="text-underline text-primary-light" />
// TODO: Add a link to the documentation
s: (
<Button
type="button"
className="usa-button usa-button--unstyled margin-top-0"
onClick={() => {
history.push(
`/models/${modelID}/collaboration-area/model-to-operations/solution-library`
);
}}
>
{' '}
</Button>
)
}}
/>
</Alert>
Expand Down
Loading
Loading