Skip to content

Commit

Permalink
feat(eventtemplates): enable custom event template UI to display when…
Browse files Browse the repository at this point in the history
… no target is selected
  • Loading branch information
andrewazores committed Dec 5, 2024
1 parent 9725f51 commit 31abd24
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/app/Events/EventTemplates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ export const EventTemplates: React.FC<EventTemplatesProps> = () => {
context.target
.target()
.pipe(
filter((target) => !!target),
first(),
concatMap((target: Target) => context.api.getTargetEventTemplates(target)),
concatMap((target: Target) =>
target ? context.api.getTargetEventTemplates(target) : context.api.getEventTemplates(),
),
)
.subscribe({
next: handleTemplates,
Expand Down
64 changes: 47 additions & 17 deletions src/app/Events/Events.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,48 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { concatMap, filter } from 'rxjs';
import { EventTemplates } from './EventTemplates';
import { EventTypes } from './EventTypes';
import { BreadcrumbPage } from '@app/BreadcrumbPage/BreadcrumbPage';

Check warning on line 28 in src/app/Events/Events.tsx

View workflow job for this annotation

GitHub Actions / eslint-check (lts/*)

`@app/BreadcrumbPage/BreadcrumbPage` import should occur before import of `@app/Shared/Services/Services`
import { TargetContextSelector } from '@app/TargetView/TargetContextSelector';

Check warning on line 29 in src/app/Events/Events.tsx

View workflow job for this annotation

GitHub Actions / eslint-check (lts/*)

`@app/TargetView/TargetContextSelector` import should occur before import of `@app/TargetView/TargetView`

export interface EventsProps {}

export const Events: React.FC<EventsProps> = ({ ...props }) => {
const context = React.useContext(ServiceContext);
const addSubscription = useSubscriptions();
const [targetSelected, setTargetSelected] = React.useState(false);

React.useEffect(() => {
addSubscription(context.target.target().subscribe((t) => setTargetSelected(!!t)));
}, [context, context.target, setTargetSelected]);

Check failure on line 40 in src/app/Events/Events.tsx

View workflow job for this annotation

GitHub Actions / eslint-check (lts/*)

React Hook React.useEffect has a missing dependency: 'addSubscription'. Either include it or remove the dependency array

return (
<TargetView {...props} pageTitle="Events">
<Card isFullHeight>
<CardBody isFilled>
<EventTabs />
</CardBody>
</Card>
<Card isFullHeight>
<CardBody isFilled>
<AgentTabs />
</CardBody>
</Card>
<></>
</TargetView>
<>
<TargetContextSelector />
<BreadcrumbPage {...props} pageTitle="Events">
{targetSelected ? (
<>
<Card>
<CardBody isFilled>
<EventTabs targetSelected={targetSelected} />
</CardBody>
</Card>
<Card isFullHeight>
<CardBody isFilled>
<AgentTabs />
</CardBody>
</Card>
</>
) : (
<>
<Card>
<CardBody isFilled>
<EventTabs targetSelected={targetSelected} />
</CardBody>
</Card>
</>
)}
</BreadcrumbPage>
</>
);
};

Expand All @@ -51,7 +75,11 @@ enum EventTab {
EVENT_TYPE = 'event-type',
}

export const EventTabs: React.FC = () => {
export interface EventTabsProps {
targetSelected: boolean;
}

export const EventTabs: React.FC<EventTabsProps> = (props: EventTabsProps) => {
const { search, pathname } = useLocation();
const navigate = useNavigate();

Expand All @@ -70,9 +98,11 @@ export const EventTabs: React.FC = () => {
<Tab eventKey={EventTab.EVENT_TEMPLATE} title="Event Templates">
<EventTemplates />
</Tab>
<Tab eventKey={EventTab.EVENT_TYPE} title="Event types">
<EventTypes />
</Tab>
{props?.targetSelected && (
<Tab eventKey={EventTab.EVENT_TYPE} title="Event types">
<EventTypes />
</Tab>
)}
</Tabs>
);
};
Expand Down

0 comments on commit 31abd24

Please sign in to comment.