lodash#lowerFirst TypeScript Examples

The following examples show how to use lodash#lowerFirst. 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: ControllableRoundSettings.tsx    From fishbowl with MIT License 4 votes vote down vote up
function ControllableRoundSettings() {
  const currentGame = React.useContext(CurrentGameContext)
  const [updateAllRounds] = useUpdateAllRoundsMutation()
  const [deleteRound] = useDeleteRoundMutation()
  const [addRound] = useAddRoundMutation()
  const [showAddRoundForm, setShowAddRoundForm] = React.useState(false)
  const [addRoundValue, setAddRoundValue] = React.useState("")
  const ref = React.useRef<HTMLDivElement>(null)

  useOnClickOutside(ref, () => {
    if (showAddRoundForm) {
      setShowAddRoundForm(false)
      setAddRoundValue("")
    }
  })

  return (
    <div ref={ref}>
      <RoundSettingsList>
        <>
          {currentGame.rounds.map((round, index) => {
            return (
              <ListItem key={round.id}>
                <ListItemIcon>
                  <>
                    <IconButton
                      color="primary"
                      size="small"
                      disabled={index === 0}
                      onClick={() => {
                        const updatedRounds = arrayMove(
                          currentGame.rounds,
                          index,
                          index - 1
                        )
                        updateAllRounds({
                          variables: {
                            gameId: currentGame.id,
                            rounds: updatedRounds.map(
                              (updatedRound, updatedIndex) => {
                                return {
                                  id: updatedRound.id,
                                  value: updatedRound.value,
                                  order_sequence: updatedIndex,
                                }
                              }
                            ),
                          },
                        })
                      }}
                    >
                      <ArrowDropUpIcon></ArrowDropUpIcon>
                    </IconButton>
                    <IconButton
                      color="primary"
                      size="small"
                      disabled={index === currentGame.rounds.length - 1}
                      onClick={() => {
                        const updatedRounds = arrayMove(
                          currentGame.rounds,
                          index,
                          index + 1
                        )
                        updateAllRounds({
                          variables: {
                            gameId: currentGame.id,
                            rounds: updatedRounds.map(
                              (updatedRound, updatedIndex) => {
                                return {
                                  id: updatedRound.id,
                                  value: updatedRound.value,
                                  order_sequence: updatedIndex,
                                }
                              }
                            ),
                          },
                        })
                      }}
                    >
                      <ArrowDropDownIcon></ArrowDropDownIcon>
                    </IconButton>
                  </>
                </ListItemIcon>
                <ListItemText>
                  <Box pl={2}>
                    {index + 1}. {capitalize(round.value)}
                  </Box>
                </ListItemText>
                <ListItemSecondaryAction>
                  <IconButton
                    size="small"
                    onClick={async () => {
                      const updatedRounds = reject(
                        currentGame.rounds,
                        (_r) => _r.id === round.id
                      )
                      await deleteRound({
                        variables: {
                          id: round.id,
                          gameId: currentGame.id,
                          rounds: updatedRounds.map(
                            (updatedRound, updatedIndex) => {
                              return {
                                id: updatedRound.id,
                                value: updatedRound.value,
                                order_sequence: updatedIndex,
                              }
                            }
                          ),
                        },
                      })
                    }}
                  >
                    <CloseIcon></CloseIcon>
                  </IconButton>
                </ListItemSecondaryAction>
              </ListItem>
            )
          })}
          <ListItem>
            <ListItemText style={{ paddingLeft: "76px" }}>
              {showAddRoundForm ? (
                <TextField
                  value={addRoundValue}
                  onChange={({ target: { value } }) => setAddRoundValue(value)}
                  size="small"
                  autoFocus
                  InputProps={{
                    startAdornment: (
                      <InputAdornment position="start">
                        {currentGame.rounds.length + 1}.
                      </InputAdornment>
                    ),
                  }}
                ></TextField>
              ) : (
                <Box color="#fafafa">.</Box>
              )}
            </ListItemText>
            <ListItemSecondaryAction>
              <IconButton
                size="small"
                disabled={showAddRoundForm && addRoundValue.length === 0}
                color={addRoundValue.length > 0 ? "primary" : "default"}
                onClick={() => {
                  if (showAddRoundForm && addRoundValue.length > 0) {
                    addRound({
                      variables: {
                        object: {
                          game_id: currentGame.id,
                          value: lowerFirst(addRoundValue),
                          order_sequence: currentGame.rounds.length,
                        },
                      },
                    })
                    setShowAddRoundForm(false)
                    setAddRoundValue("")
                  } else {
                    setShowAddRoundForm(true)
                  }
                }}
              >
                <AddCircleIcon></AddCircleIcon>
              </IconButton>
            </ListItemSecondaryAction>
          </ListItem>
        </>
      </RoundSettingsList>
    </div>
  )
}
Example #2
Source File: setupCrudResolvers.ts    From ra-data-prisma with MIT License 4 votes vote down vote up
setupCrudResolvers = <
  ModelName extends keyof Helpers.GetGen<"outputs"> & string,
>(
  { extendType, arg, intArg },
  resourceName: ModelName,
  {
    printSecurityWarning = true,
    customize,
    aliasPrefix,
    enableOrderByRelation = false,
  }: ResourceOptions<ModelName> & CommonOptions = {},
) => {
  const typeName = upperFirst(resourceName);

  const queryName = lowerFirst(resourceName);
  const queryAllName = pluralize(queryName);
  const queryCountName = `${pluralize(queryName)}Count`;

  const mutations = [
    { name: `createOne${typeName}`, type: "createOne" },
    { name: `updateOne${typeName}`, type: "updateOne" },
    { name: `updateMany${typeName}`, type: "updateMany" },
    { name: `upsertOne${typeName}`, type: "upsertOne" },
    { name: `deleteOne${typeName}`, type: "deleteOne" },
    { name: `deleteMany${typeName}`, type: "deleteMany" },
  ];
  if (process.env.NODE_ENV === "development" && printSecurityWarning) {
    const queries = [queryName, queryAllName, queryCountName].map((n) =>
      makePrefixedFullName(n, aliasPrefix),
    );
    console.info("");
    console.info(
      `☝ The following resolvers were defined for the resource '${resourceName}' to make it compatible for react-admin`,
    );

    console.info(`Queries:     ${queries.join(" ")}`);
    console.info(`Mutations:   ${mutations.map((m) => m.name).join(" ")}`);

    console.info(
      "☝ please make sure to restirct unauthorized access to these queries using graphq-shield",
    );
    console.info("");
  }
  return {
    Query: extendType({
      type: "Query",
      definition(t) {
        const oneConfig = {
          alias: makePrefixedFullName(queryName, aliasPrefix),
        };
        t.crud[queryName](customize?.one?.(oneConfig as any) ?? oneConfig);
        const manyConfig = {
          filtering: true,
          pagination: true,
          ordering: true,
          alias: makePrefixedFullName(queryAllName, aliasPrefix),
        };
        t.crud[queryAllName](
          customize?.many?.(manyConfig as any) ?? manyConfig,
        );

        t.int(makePrefixedFullName(queryCountName, aliasPrefix), {
          args: {
            where: arg({
              type: `${typeName}WhereInput`,
            }),
            orderBy: arg({
              type: enableOrderByRelation
                ? `${typeName}OrderByWithRelationInput`
                : `${typeName}OrderByInput`,
            }),
            skip: intArg({}),

            cursor: arg({
              type: `${typeName}WhereUniqueInput`,
            }),
            take: intArg({}),
          },

          resolve(root, args, { prisma, db }) {
            return (prisma ?? db)[queryName].count(args);
          },
        });
      },
    }),

    Mutation: extendType({
      type: "Mutation",
      definition(t) {
        mutations.forEach((mutation) => {
          const options = {
            alias: makePrefixedFullName(mutation.name, aliasPrefix),
          };
          t.crud[mutation.name](
            customize?.[mutation.type]?.(options) ?? options,
          );
        });
      },
    }),
  };
}