function GenerateDialog()

in src/web/src/views/cli/CLIModuleGenerator.tsx [314:409]


function GenerateDialog(props: {
  repoName: string;
  moduleName: string;
  profileCommandTrees: ProfileCommandTrees;
  open: boolean;
  onClose: (generated: boolean) => void;
}) {
  const [updating, setUpdating] = React.useState<boolean>(false);
  const [invalidText, setInvalidText] = React.useState<string | undefined>(undefined);

  const handleClose = () => {
    props.onClose(false);
  };

  const handleGenerateAll = () => {
    const profiles: CLIModViewProfiles = {};
    Object.values(props.profileCommandTrees).forEach((tree) => {
      profiles[tree.name] = ExportModViewProfile(tree);
    });
    const data = {
      name: props.moduleName,
      profiles: profiles,
    };

    setUpdating(true);
    axios
      .put(`/CLI/Az/${props.repoName}/Modules/${props.moduleName}`, data)
      .then(() => {
        setUpdating(false);
        props.onClose(true);
      })
      .catch((err) => {
        console.error(err);
        if (err.response?.data?.message) {
          const data = err.response!.data!;
          setInvalidText(`ResponseError: ${data.message!}: ${JSON.stringify(data.details)}`);
        }
        setUpdating(false);
      });
  };

  const handleGenerateModified = () => {
    const profiles: CLIModViewProfiles = {};
    Object.values(props.profileCommandTrees).forEach((tree) => {
      profiles[tree.name] = ExportModViewProfile(tree);
    });
    const data = {
      name: props.moduleName,
      profiles: profiles,
    };

    setUpdating(true);
    axios
      .patch(`/CLI/Az/${props.repoName}/Modules/${props.moduleName}`, data)
      .then(() => {
        setUpdating(false);
        props.onClose(true);
      })
      .catch((err) => {
        console.error(err);
        if (err.response?.data?.message) {
          const data = err.response!.data!;
          setInvalidText(`ResponseError: ${data.message!}: ${JSON.stringify(data.details)}`);
        }
        setUpdating(false);
      });
  };

  return (
    <Dialog disableEscapeKeyDown open={props.open}>
      <DialogTitle>Generate CLI commands to {props.moduleName}</DialogTitle>
      <DialogContent>
        {invalidText && (
          <Alert variant="filled" severity="error">
            {" "}
            {invalidText}{" "}
          </Alert>
        )}
      </DialogContent>
      <DialogActions>
        {updating && (
          <Box sx={{ width: "100%" }}>
            <LinearProgress color="secondary" />
          </Box>
        )}
        {!updating && (
          <React.Fragment>
            <Button onClick={handleClose}>Cancel</Button>
            <Button onClick={handleGenerateAll}>Generate All</Button>
            <Button onClick={handleGenerateModified}>Generate Edited Only</Button>
          </React.Fragment>
        )}
      </DialogActions>
    </Dialog>
  );
}