Skip to content

Commit

Permalink
Merge pull request #2926 from the-deep/feature/test-tag
Browse files Browse the repository at this point in the history
TestTag component for test project
  • Loading branch information
AdityaKhatri authored May 8, 2024
2 parents 930fc24 + a2265a5 commit 10f9e2d
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 91 deletions.
11 changes: 11 additions & 0 deletions app/components/SubNavbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ export function SubNavbarChildren(props: SubNavbarChildrenProps) {
const {
children,
} = props;

const {
childrenNode,
} = useContext(NavbarContext);

if (!childrenNode) {
return null;
}

return ReactDOM.createPortal(
children,
childrenNode,
Expand All @@ -35,16 +38,20 @@ export function SubNavbarChildren(props: SubNavbarChildrenProps) {
interface SubNavbarIconsProps {
children: React.ReactNode;
}

export function SubNavbarIcons(props: SubNavbarIconsProps) {
const {
children,
} = props;

const {
iconsNode,
} = useContext(NavbarContext);

if (!iconsNode) {
return null;
}

return ReactDOM.createPortal(
children,
iconsNode,
Expand All @@ -54,16 +61,20 @@ export function SubNavbarIcons(props: SubNavbarIconsProps) {
interface SubNavbarActionsProps {
children: React.ReactNode;
}

export function SubNavbarActions(props: SubNavbarActionsProps) {
const {
children,
} = props;

const {
actionsNode,
} = useContext(NavbarContext);

if (!actionsNode) {
return null;
}

return ReactDOM.createPortal(
children,
actionsNode,
Expand Down
32 changes: 32 additions & 0 deletions app/components/TestTag/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import {
Tag,
} from '@the-deep/deep-ui';
import { IoInformationCircleOutline } from 'react-icons/io5';
import { _cs } from '@togglecorp/fujs';

import styles from './styles.css';

interface Props {
className?: string;
}

function TestTag(props: Props) {
const { className } = props;

return (
<Tag
className={_cs(className, styles.testTag)}
spacing="compact"
icons={(
<IoInformationCircleOutline
title="This project has been set as test project by the admin of the project."
/>
)}
>
Test Project
</Tag>
);
}

export default TestTag;
8 changes: 8 additions & 0 deletions app/components/TestTag/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.test-tag {
--tag-flex-order: 4;
align-items: center;
align-self: center;
flex-shrink: 0;
order: var(--tag-flex-order);
background: var(--dui-color-complement3);
}
1 change: 1 addition & 0 deletions app/gqlFragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ export const LAST_ACTIVE_PROJECT_FRAGMENT = gql`
isPrivate
isProjectPinned
title
isTest
isVisualizationEnabled
isVisualizationAvailable
membershipPending
Expand Down
2 changes: 2 additions & 0 deletions app/views/AnalysisModule/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { generatePath, Redirect, Route, Switch } from 'react-router-dom';
import SubNavbarContext from '#components/SubNavbar/context';
import SubNavbar, { SubNavbarIcons } from '#components/SubNavbar';
import ProjectSwitcher from '#components/general/ProjectSwitcher';
import TestTag from '#components/TestTag';
import { ProjectContext } from '#base/context/ProjectContext';

import routes from '#base/configs/routes';
Expand Down Expand Up @@ -51,6 +52,7 @@ function AnalysisModule(props: AnalysisModuleProps) {
<div className={_cs(styles.analysisModule, className)}>
<SubNavbarIcons>
<ProjectSwitcher />
{project?.isTest && <TestTag />}
</SubNavbarIcons>
<SubNavbar
className={styles.subNavbar}
Expand Down
137 changes: 77 additions & 60 deletions app/views/EntryEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import { GeoArea } from '#components/GeoMultiSelectInput';
import { transformToFormError, ObjectError } from '#base/utils/errorTransform';
import ProjectContext from '#base/context/ProjectContext';
import UserContext from '#base/context/UserContext';
import SubNavbar from '#components/SubNavbar';
import SubNavbarContext from '#components/SubNavbar/context';
import SubNavbar, { SubNavbarIcons } from '#components/SubNavbar';
import TestTag from '#components/TestTag';
import BackLink from '#components/BackLink';
import ExcerptInput from '#components/entry/ExcerptInput';
import EntryControl from '#components/entryReview/EntryControl';
Expand Down Expand Up @@ -165,6 +167,16 @@ function EntryEdit(props: Props) {

const projectId = project ? project.id : undefined;

const [iconsNode, setIconsNode] = useState<Element | null | undefined>();

const navbarContextValue = useMemo(
() => ({
iconsNode,
setIconsNode,
}),
[iconsNode],
);

const [
geoAreaOptions,
setGeoAreaOptions,
Expand Down Expand Up @@ -1457,67 +1469,72 @@ function EntryEdit(props: Props) {
useHash
defaultHash="source-details"
>
<SubNavbar
className={styles.header}
heading="Source"
description={lead?.title}
homeLinkShown
defaultActions={(
<>
<BackLink defaultLink="/">
Close
</BackLink>
<Button
name={undefined}
disabled={formPristine || !!selectedEntry || loading}
onClick={handleSaveClick}
<SubNavbarContext.Provider value={navbarContextValue}>
<SubNavbarIcons>
{project?.isTest && <TestTag />}
</SubNavbarIcons>
<SubNavbar
className={styles.header}
heading="Source"
description={lead?.title}
homeLinkShown
defaultActions={(
<>
<BackLink defaultLink="/">
Close
</BackLink>
<Button
name={undefined}
disabled={formPristine || !!selectedEntry || loading}
onClick={handleSaveClick}
>
Save
</Button>
<ConfirmButton
name={undefined}
disabled={disableFinalizeButton}
variant="primary"
onConfirm={handleFinalizeClick}
message="Finalizing the source will mark it as tagged.
Are you sure you want to finalize the source and all its entries?"
>
Finalize
</ConfirmButton>
</>
)}
>
<TabList>
<Tab
name="source-details"
transparentBorder
disabled={isEntrySelectionActive}
>
Save
</Button>
<ConfirmButton
name={undefined}
disabled={disableFinalizeButton}
variant="primary"
onConfirm={handleFinalizeClick}
message="Finalizing the source will mark it as tagged.
Are you sure you want to finalize the source and all its entries?"
Source Details
</Tab>
<Tab
name="primary-tagging"
transparentBorder
disabled={isEntrySelectionActive}
>
Finalize
</ConfirmButton>
</>
)}
>
<TabList>
<Tab
name="source-details"
transparentBorder
disabled={isEntrySelectionActive}
>
Source Details
</Tab>
<Tab
name="primary-tagging"
transparentBorder
disabled={isEntrySelectionActive}
>
Primary Tagging
</Tab>
<Tab
name="secondary-tagging"
transparentBorder
disabled={isEntrySelectionActive}
>
Secondary Tagging
</Tab>
<Tab
name="review"
transparentBorder
disabled={isEntrySelectionActive}
>
Review
</Tab>
</TabList>
</SubNavbar>
Primary Tagging
</Tab>
<Tab
name="secondary-tagging"
transparentBorder
disabled={isEntrySelectionActive}
>
Secondary Tagging
</Tab>
<Tab
name="review"
transparentBorder
disabled={isEntrySelectionActive}
>
Review
</Tab>
</TabList>
</SubNavbar>
</SubNavbarContext.Provider>
<CommentCountContext.Provider value={commentCountContext}>
<div className={styles.tabPanelContainer}>
{loading && <PendingMessage />}
Expand Down
74 changes: 47 additions & 27 deletions app/views/ReportEdit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import { IoShareSocialOutline } from 'react-icons/io5';

import BackLink from '#components/BackLink';
import routes from '#base/configs/routes';
import SubNavbar from '#components/SubNavbar';
import SubNavbarContext from '#components/SubNavbar/context';
import SubNavbar, { SubNavbarIcons } from '#components/SubNavbar';
import TestTag from '#components/TestTag';
import {
BasicOrganization,
} from '#components/selections/NewOrganizationMultiSelectInput';
Expand Down Expand Up @@ -641,6 +643,19 @@ function ReportEdit(props: Props) {
const history = useHistory();
const leftContentRef = useRef<HTMLDivElement>(null);

const [iconsNode, setIconsNode] = useState<Element | null | undefined>();
const [actionsNode, setActionsNode] = useState<Element | null | undefined>();

const navbarContextValue = useMemo(
() => ({
iconsNode,
actionsNode,
setIconsNode,
setActionsNode,
}),
[iconsNode, actionsNode],
);

const [
contentEditPaneVisible,
setContentEditPaneVisibility,
Expand Down Expand Up @@ -1081,32 +1096,37 @@ function ReportEdit(props: Props) {

return (
<div className={_cs(className, styles.reportEdit)}>
<SubNavbar
className={styles.header}
heading="New Report"
homeLinkShown
defaultActions={(
<>
<BackLink
defaultLink="/"
>
Back
</BackLink>
<Button
name={undefined}
onClick={createSubmitHandler(
validate,
handleError,
handleSubmit,
)}
disabled={pristine}
variant="primary"
>
Save
</Button>
</>
)}
/>
<SubNavbarContext.Provider value={navbarContextValue}>
<SubNavbarIcons>
{project?.isTest && <TestTag />}
</SubNavbarIcons>
<SubNavbar
className={styles.header}
heading="New Report"
homeLinkShown
defaultActions={(
<>
<BackLink
defaultLink="/"
>
Back
</BackLink>
<Button
name={undefined}
onClick={createSubmitHandler(
validate,
handleError,
handleSubmit,
)}
disabled={pristine}
variant="primary"
>
Save
</Button>
</>
)}
/>
</SubNavbarContext.Provider>
<div className={styles.content}>
{pending && <PendingMessage />}
<div
Expand Down
Loading

0 comments on commit 10f9e2d

Please sign in to comment.