|
5 | 5 | AccordionItemHeading, |
6 | 6 | AccordionItemPanel |
7 | 7 | } from "react-accessible-accordion"; |
8 | | -import { Button, Span } from "../YamlStyles"; |
| 8 | +import { Button, Input, Span } from "../YamlStyles"; |
9 | 9 | import { Har, HarEndpoint } from "../../util/yamlwriter"; |
10 | 10 | import { LogLevel, log } from "../../util/log"; |
11 | 11 | import { Modal, ModalObject, useEffectModal } from "../Modal"; |
@@ -169,6 +169,7 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { |
169 | 169 | const defaultFilename: string = ""; |
170 | 170 | const [filename, setFilename] = useState(defaultFilename); |
171 | 171 | const [state, setState] = useState(defaultState); |
| 172 | + const [urlFilter, setUrlFilter] = useState(""); |
172 | 173 | const fileModalRef = useRef<ModalObject| null>(null); |
173 | 174 | useEffectModal(fileModalRef); |
174 | 175 | const endpointModalRef = useRef<ModalObject| null>(null); |
@@ -398,6 +399,71 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { |
398 | 399 | }); |
399 | 400 | }; |
400 | 401 |
|
| 402 | + const handleSelectUrls = (selected?: "yes" | "no") => { |
| 403 | + const outputName = state.output[filename]; |
| 404 | + if (!outputName) { return; } |
| 405 | + |
| 406 | + const updatedUrls = { ...outputName.urls }; |
| 407 | + const updatedEndpoints = [...outputName.endpoints]; |
| 408 | + |
| 409 | + Object.keys(updatedUrls).forEach((key) => { |
| 410 | + if (selected) { |
| 411 | + updatedUrls[key]!.selected = selected; |
| 412 | + updatedUrls[key]!.index.forEach((url) => { |
| 413 | + const endpoint = updatedEndpoints.find((ep) => ep.id === url.id); |
| 414 | + if (endpoint) { endpoint.selected = selected; } |
| 415 | + }); |
| 416 | + } else if (urlFilter) { |
| 417 | + const selectedByFilter = key.includes(urlFilter) ? "yes" : "no"; |
| 418 | + updatedUrls[key]!.selected = selectedByFilter; |
| 419 | + updatedUrls[key]!.index.forEach((url) => { |
| 420 | + const endpoint = updatedEndpoints.find((ep) => ep.id === url.id); |
| 421 | + if (endpoint) { endpoint.selected = selectedByFilter; } |
| 422 | + }); |
| 423 | + } |
| 424 | + }); |
| 425 | + |
| 426 | + setState(({ output, ...prevState }: YamlWriterUploadState) => ({ |
| 427 | + ...prevState, |
| 428 | + output: { |
| 429 | + ...output, |
| 430 | + [filename]: { |
| 431 | + ...outputName, |
| 432 | + urls: updatedUrls, |
| 433 | + endpoints: updatedEndpoints |
| 434 | + } |
| 435 | + } |
| 436 | + })); |
| 437 | + }; |
| 438 | + |
| 439 | + const handleSelectAllHeaders = (selected: "yes" | "no") => { |
| 440 | + const outputName = state.output[filename]; |
| 441 | + if (!outputName) {return;} |
| 442 | + |
| 443 | + const updatedTypes = { ...outputName.types }; |
| 444 | + const updatedEndpoints = [...outputName.endpoints]; |
| 445 | + |
| 446 | + Object.keys(updatedTypes).forEach((key) => { |
| 447 | + updatedTypes[key]!.selected = selected; |
| 448 | + updatedTypes[key]!.index.forEach((type) => { |
| 449 | + const endpoint = updatedEndpoints.find((ep) => ep.id === type.id); |
| 450 | + if (endpoint) {endpoint.selected = selected;} |
| 451 | + }); |
| 452 | + }); |
| 453 | + |
| 454 | + setState(({ output, ...prevState }: YamlWriterUploadState) => ({ |
| 455 | + ...prevState, |
| 456 | + output: { |
| 457 | + ...output, |
| 458 | + [filename]: { |
| 459 | + ...outputName, |
| 460 | + types: updatedTypes, |
| 461 | + endpoints: updatedEndpoints |
| 462 | + } |
| 463 | + } |
| 464 | + })); |
| 465 | + }; |
| 466 | + |
401 | 467 | return ( |
402 | 468 | <HeaderMain> |
403 | 469 | <h2> Create from Har File </h2> |
@@ -447,7 +513,40 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { |
447 | 513 | <AccordianStyleDiv style={{paddingRight: "20px"}}> |
448 | 514 | <div> |
449 | 515 | <Span> |
450 | | - <h2>Urls</h2> |
| 516 | + <h2>Urls</h2> |
| 517 | + <div style={{ display: "flex", alignItems: "center", marginLeft: "10px" }}> |
| 518 | + <Input |
| 519 | + type="text" |
| 520 | + placeholder="Filter URLs" |
| 521 | + value={urlFilter} |
| 522 | + onChange={(e) => setUrlFilter(e.target.value)} |
| 523 | + /> |
| 524 | + <Button |
| 525 | + onClick={() => handleSelectUrls()} |
| 526 | + style={{ marginLeft: "0"}} |
| 527 | + disabled={!urlFilter.length} |
| 528 | + > |
| 529 | + Filter |
| 530 | + </Button> |
| 531 | + <Button |
| 532 | + onClick={() => handleSelectUrls("yes")} |
| 533 | + disabled={ |
| 534 | + state.output[filename]?.urls && |
| 535 | + Object.values(state.output[filename]!.urls).every((url) => url?.selected === "yes") |
| 536 | + } |
| 537 | + > |
| 538 | + Select All |
| 539 | + </Button> |
| 540 | + <Button |
| 541 | + onClick={() => handleSelectUrls("no")} |
| 542 | + disabled={ |
| 543 | + state.output[filename]?.urls && |
| 544 | + Object.values(state.output[filename]!.urls).every((url) => url?.selected === "no") |
| 545 | + } |
| 546 | + > |
| 547 | + Deselect All |
| 548 | + </Button> |
| 549 | + </div> |
451 | 550 | </Span> |
452 | 551 | <Accordion allowMultipleExpanded={true} allowZeroExpanded={true}> |
453 | 552 | {state.output[filename]?.urls && Object.keys(state.output[filename]!.urls).map((key, index) => { |
@@ -496,7 +595,29 @@ export const YamlWriterUpload = (props: YamlWriterUploadProps) => { |
496 | 595 | </Accordion> |
497 | 596 | </div> |
498 | 597 | <div style={{marginTop: "25px"}}> |
499 | | - <h2>Return Types</h2> |
| 598 | + <Span> |
| 599 | + <h2>Return Types</h2> |
| 600 | + <div style={{ display: "flex", alignItems: "center", marginLeft: "10px" }}> |
| 601 | + <Button |
| 602 | + onClick={() => handleSelectAllHeaders("yes")} |
| 603 | + disabled={ |
| 604 | + state.output[filename]?.types && |
| 605 | + Object.values(state.output[filename]!.types).every((type) => type?.selected === "yes") |
| 606 | + } |
| 607 | + > |
| 608 | + Select All |
| 609 | + </Button> |
| 610 | + <Button |
| 611 | + onClick={() => handleSelectAllHeaders("no")} |
| 612 | + disabled={ |
| 613 | + state.output[filename]?.types && |
| 614 | + Object.values(state.output[filename]!.types).every((type) => type?.selected === "no") |
| 615 | + } |
| 616 | + > |
| 617 | + Deselect All |
| 618 | + </Button> |
| 619 | + </div> |
| 620 | + </Span> |
500 | 621 | <Accordion allowMultipleExpanded={true} allowZeroExpanded={true}> |
501 | 622 | {state.output[filename]?.types && Object.keys(state.output[filename]!.types).map((key, index) => { |
502 | 623 | const type = state.output[filename]!.types[key]; |
|
0 commit comments