Skip to content
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
2 changes: 1 addition & 1 deletion packages/web/src/app/capture/Subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useGetSubscriptionQuery } from "../../features/http-client/freemiumd-ap
import ProgressBar from "./ProgressBar";
import Button from "../../new-components/Button";
import { useAppDispatch, useAppSelector } from "./store";
import { openLink } from "../../features/config/slice";
import { openLink } from "./slice";

export default function Subscription({
token,
Expand Down
2 changes: 0 additions & 2 deletions packages/web/src/app/capture/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { Webapp } from "@xliic/common/webapp/capture";

import { ThemeState } from "../../features/theme/slice";
import { RouterContext, Routes } from "../../features/router/RouterContext";
import GeneralError from "../../features/general-error/GeneralError";
import { showGeneralError } from "../../features/general-error/slice";
import { makeWebappMessageHandler, RouterApp } from "../webapp";
import { createListener } from "./listener";
import { initStore, messageHandlers } from "./store";
Expand Down
99 changes: 97 additions & 2 deletions packages/web/src/app/scanconf/authorizationTests/TestContents.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useFieldArray } from "react-hook-form";
import styled from "styled-components";

import { ThemeColorVariables } from "@xliic/common/theme";
import { Playbook } from "@xliic/scanconf";

import { Plus, TrashCan } from "../../../icons";
import DownshiftSelect from "../../../new-components/fat-fields/DownshiftSelect";

export default function TestContents({ credentials }: { credentials: Playbook.Credentials }) {
Expand All @@ -16,13 +21,54 @@ export default function TestContents({ credentials }: { credentials: Playbook.Cr
]}
/>

<DownshiftSelect label="Source" name="source.0" options={options} />
<AuthArrayField label="Source" name="source" options={options} />

<DownshiftSelect label="Target" name="target.0" options={options} />
<AuthArrayField label="Target" name="target" options={options} />
</>
);
}

function AuthArrayField({
label,
name,
options,
}: {
label: string;
name: string;
options: { label: string; value: string }[];
}) {
const { fields, append, remove } = useFieldArray({ name });

return (
<Group>
<GroupLabel>{label}</GroupLabel>
{fields.map((field, index) => (
<Row key={field.id}>
<DownshiftSelect name={`${name}.${index}`} options={options} />
<Remove
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
remove(index);
}}
Comment on lines +48 to +53
>
<TrashCan />
</Remove>
</Row>
))}
<Add
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
append("");
}}
>
Comment on lines +59 to +65
<Plus /> Add {label.toLowerCase()}
</Add>
</Group>
);
}

function flattenCredentials(credentials: Playbook.Credentials) {
return Object.entries(credentials)
.map(([credentialName, credential]) => {
Expand All @@ -33,3 +79,52 @@ function flattenCredentials(credentials: Playbook.Credentials) {
})
.flat();
}

const Group = styled.div`
display: flex;
flex-direction: column;
gap: 8px;
`;

const GroupLabel = styled.div`
font-weight: 500;
font-size: 12px;
line-height: 16px;
color: var(${ThemeColorVariables.inputPlaceholderForeground});
`;

const Row = styled.div`
display: flex;
align-items: center;
gap: 8px;
> :first-child {
flex: 1;
}
`;

const Remove = styled.button`
background: none;
border: none;
padding: 0;
width: 1.5em;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
> svg {
fill: var(${ThemeColorVariables.foreground});
}
`;

const Add = styled.div`
display: flex;
padding: 8px 12px;
gap: 4px;
cursor: pointer;
align-items: center;
border: 1px dashed var(${ThemeColorVariables.border});
color: var(${ThemeColorVariables.linkForeground});
> svg {
fill: var(${ThemeColorVariables.linkForeground});
}
`;
Comment on lines +119 to +130
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function DownshiftSelect<T>({
}: {
name: string;
options: SelectOption<T>[];
label: string;
label?: string;
description?: string;
placeholder?: string;
}) {
Expand All @@ -22,7 +22,7 @@ export default function DownshiftSelect<T>({

return (
<Container>
<div className="label">{label}</div>
{label !== undefined && <div className="label">{label}</div>}
<PlainDownshiftSelect
placeholder={placeholder}
options={options}
Expand Down