lodash-es#fromPairs TypeScript Examples

The following examples show how to use lodash-es#fromPairs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeploymentDialog.tsx    From github-deploy-center with MIT License 4 votes vote down vote up
DeploymentDialog = () => {
  const { deploymentDialog } = useAppState()
  const { updateDeployWorkflowDialog, cancelEditDeployment, saveDeployment } =
    useActions()

  const valid = Boolean(
    deploymentDialog &&
      deploymentDialog.workflowId &&
      deploymentDialog.releaseKey &&
      deploymentDialog.ref
  )
  return (
    <Dialog open={!!deploymentDialog} fullWidth onClose={cancelEditDeployment}>
      {deploymentDialog ? (
        <form
          onSubmit={(event) => {
            event.preventDefault()
            if (valid) {
              saveDeployment()
            }
          }}>
          <DialogTitle>Deploy workflow settings</DialogTitle>
          <DialogContent
            style={{ display: 'flex', gap: '1rem', flexDirection: 'column' }}>
            <SelectWorkflow
              workflowId={deploymentDialog.workflowId}
              onChange={(id) =>
                updateDeployWorkflowDialog((state) => (state.workflowId = id))
              }
            />
            <TextField
              label="Release input name"
              value={deploymentDialog.releaseKey}
              onChange={(e) =>
                updateDeployWorkflowDialog(
                  (settings) => (settings.releaseKey = e.target.value)
                )
              }
            />
            <TextField
              label="Environment input name (optional)"
              value={deploymentDialog.environmentKey}
              onChange={(e) =>
                updateDeployWorkflowDialog(
                  (settings) => (settings.environmentKey = e.target.value)
                )
              }
            />
            <TextField
              label="Run workflow from branch"
              value={deploymentDialog.ref}
              onChange={(e) =>
                updateDeployWorkflowDialog(
                  (settings) => (settings.ref = e.target.value)
                )
              }
            />
            <Autocomplete
              style={{ gridColumn: '1 / span 5' }}
              multiple
              options={[]}
              freeSolo
              value={Object.entries(deploymentDialog.extraArgs).map(
                ([key, value]) => `${key}=${value}`
              )}
              renderInput={(params) => (
                <TextField
                  label="Extra workflow args (press Enter to add)"
                  placeholder="key=value"
                  {...params}
                />
              )}
              onChange={(_, newValue) => {
                const pairs = newValue
                  .filter((x): x is string => typeof x === 'string')
                  .map((x) => x.split('='))
                  .filter(([key, value]) => key && value)
                const newArgs = fromPairs(pairs)
                updateDeployWorkflowDialog(
                  (settings) => (settings.extraArgs = newArgs)
                )
              }}
            />
          </DialogContent>
          <DialogActions style={{ padding: '2rem' }}>
            <Button
              type="submit"
              disabled={!valid}
              variant="contained"
              color="primary">
              Save
            </Button>
            <Button onClick={cancelEditDeployment}>Cancel</Button>
          </DialogActions>
        </form>
      ) : null}
    </Dialog>
  )
}