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

✨ Add provider dropdown for targets #1500

Merged
merged 4 commits into from
Nov 2, 2023
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
1 change: 1 addition & 0 deletions client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ export interface Target {
labels?: TargetLabel[];
image?: RulesetImage;
ruleset: Ruleset;
provider?: string;
}

export interface Metadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import {
Title,
TextContent,
Expand All @@ -15,12 +15,15 @@ import { AnalysisWizardFormValues } from "./schema";
import { useSetting } from "@app/queries/settings";
import { useFetchTargets } from "@app/queries/targets";
import { Target } from "@app/api/models";
import { SimpleSelect } from "@app/components/SimpleSelect";

export const SetTargets: React.FC = () => {
const { t } = useTranslation();

const { targets } = useFetchTargets();

const [provider, setProvider] = useState("Java");

const targetOrderSetting = useSetting("ui.target.order");

const { watch, setValue, getValues } =
Expand Down Expand Up @@ -131,6 +134,19 @@ export const SetTargets: React.FC = () => {
{t("wizard.terms.setTargets")}
</Title>
<Text>{t("wizard.label.setTargets")}</Text>
<SimpleSelect
width={200}
variant="typeahead"
id="action-select"
toggleId="action-select-toggle"
toggleAriaLabel="Action select dropdown toggle"
aria-label={"Select provider"}
value={provider}
options={["Java", "Go"]}
onChange={(selection) => {
setProvider(selection as string);
}}
/>
</TextContent>
<Gallery hasGutter>
{targetOrderSetting.isSuccess
Expand All @@ -139,7 +155,7 @@ export const SetTargets: React.FC = () => {

const isSelected = selectedTargets?.includes(id);

if (matchingTarget) {
if (matchingTarget && matchingTarget.provider === provider) {
return (
<GalleryItem key={index}>
<TargetCard
Expand Down
112 changes: 66 additions & 46 deletions client/src/app/pages/migration-targets/migration-targets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ import { CustomTargetForm } from "./components/custom-target-form";
import { useSetting, useSettingMutation } from "@app/queries/settings";
import { useDeleteTargetMutation, useFetchTargets } from "@app/queries/targets";
import { Target } from "@app/api/models";
import { SimpleSelect } from "@app/components/SimpleSelect";

export const MigrationTargets: React.FC = () => {
const { t } = useTranslation();
const { pushNotification } = React.useContext(NotificationsContext);
const [provider, setProvider] = useState("Java");

const { targets, refetch: refetchTargets } = useFetchTargets();

Expand Down Expand Up @@ -164,12 +166,26 @@ export const MigrationTargets: React.FC = () => {
</TextContent>
</GridItem>
<GridItem span={2}></GridItem>
<GridItem span={10}>
<GridItem span={12}>
<TextContent>
<Text>{t("terms.customTargetsDetails")}</Text>
</TextContent>
</GridItem>
<GridItem span={2} className="button-align">
<GridItem span={2} className={spacing.mtSm}>
<SimpleSelect
variant="typeahead"
id="action-select"
toggleId="action-select-toggle"
toggleAriaLabel="Action select dropdown toggle"
aria-label={"Select provider"}
value={provider}
options={["Java", "Go"]}
onChange={(selection) => {
setProvider(selection as string);
}}
/>
</GridItem>
<GridItem span={2} className={spacing.mtSm}>
<Button
id="clear-repository"
isInline
Expand All @@ -180,6 +196,8 @@ export const MigrationTargets: React.FC = () => {
</Button>
</GridItem>
</Grid>
</PageSection>
<PageSection>
<Modal
id="create-edit-custom-tarrget-modal"
title={t(
Expand All @@ -198,52 +216,54 @@ export const MigrationTargets: React.FC = () => {
onCancel={() => setCreateUpdateModalState(null)}
/>
</Modal>
</PageSection>
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragStart={handleDragStart}
onDragOver={handleDragOver}
>
<SortableContext
items={targetOrderSetting.isSuccess ? targetOrderSetting.data : []}
strategy={rectSortingStrategy}
<DndContext
sensors={sensors}
collisionDetection={closestCenter}
onDragStart={handleDragStart}
onDragOver={handleDragOver}
>
<DndGrid>
{targetOrderSetting.isSuccess &&
targetOrderSetting.data.map((id) => {
const matchingTarget = targets.find(
(target) => target.id === id
);
if (matchingTarget) {
return (
<SortableItem
key={id}
id={id}
onEdit={() => {
if (matchingTarget) {
setCreateUpdateModalState(matchingTarget);
}
}}
onDelete={() => {
const matchingTarget = targets.find(
(target) => target.id === id
);
if (matchingTarget?.id) {
deleteTarget(matchingTarget.id);
}
}}
/>
<SortableContext
items={targetOrderSetting.isSuccess ? targetOrderSetting.data : []}
strategy={rectSortingStrategy}
>
<DndGrid>
{targetOrderSetting.isSuccess &&
targetOrderSetting.data.map((id) => {
const matchingTarget = targets.find(
(target) => target.id === id
);
} else {
return null;
}
})}
<div ref={targetsEndRef} />
</DndGrid>
<DragOverlay>{activeId ? <Item id={activeId} /> : null}</DragOverlay>
</SortableContext>
</DndContext>
if (matchingTarget && matchingTarget.provider === provider) {
return (
<SortableItem
key={id}
id={id}
onEdit={() => {
if (matchingTarget) {
setCreateUpdateModalState(matchingTarget);
}
}}
onDelete={() => {
const matchingTarget = targets.find(
(target) => target.id === id
);
if (matchingTarget?.id) {
deleteTarget(matchingTarget.id);
}
}}
/>
);
} else {
return null;
}
})}
<div ref={targetsEndRef} />
</DndGrid>
<DragOverlay>
{activeId ? <Item id={activeId} /> : null}
</DragOverlay>
</SortableContext>
</DndContext>
</PageSection>
</>
);
};