Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

109
Visualizações
Refactoring Alerts

hey I'm pretty new to coding. I'm working on a project and feel like I can refactor this code to make it less bulky but don't really know where to start. Maybe mapping could be helpful. Any Suggestions?

const CriticalAlertStatus = isCriticalAlertingEnabled
    ? allIcons.LMAlertSeverityCriticalOutline20Px
    : Disabled;

  const isCriticalStaticAlertSuppressed = R.path(
    ["children", "CRITICAL", "isStaticAlertSuppressed"],
    props
  );
  const CriticalStaticAlertStatus = isCriticalStaticAlertSuppressed
    ? allIcons.LMAlertsCritical20Px
    : Disabled;

  const isErrorAlertingEnabled = R.path(["children", "ERROR", "isAlertingEnabled"], props);

  const ErrorAlertStatus = isErrorAlertingEnabled
    ? allIcons.LMAlertSeverityErrorOutline20Px
    : Disabled;

  const isErrorStaticAlertSuppressed = R.path(
    ["children", "ERROR", "isStaticAlertSuppressed"],
    props
  );
  const ErrorStaticAlertStatus = isErrorStaticAlertSuppressed
    ? allIcons.LMAlertsError20Px
    : Disabled;

  const isWarningAlertingEnabled = R.path(["children", "WARNING", "isAlertingEnabled"], props);

  const WarningAlertStatus = isWarningAlertingEnabled
    ? allIcons.LMAlertSeverityWarningOutline20Px
    : Disabled;

  const isWarningStaticAlertSuppressed = R.path(
    ["children", "WARNING", "isStaticAlertSuppressed"],
    props
  );
  const WarningStaticAlertStatus = isWarningStaticAlertSuppressed
    ? allIcons.LMAlertsWarning20Px
    : Disabled;
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use R.ifElse to create a factory function that would generate a new alert stats function according to the parameters you pass:

const Disabled = 'Disabled' // Demo Disabled

const getAlertState = R.curry((path, icon, props) => 
  R.ifElse(R.path(path), R.always(icon), R.always(Disabled))
(props))

// Example of usage

// Demo icons
const allIcons = { LMAlertSeverityCriticalOutline20Px: 'LMAlertSeverityCriticalOutline20Px', LMAlertsCritical20Px: 'LMAlertsCritical20Px' };

// Create funnctions
const CriticalAlertStatus = getAlertState(["children", "CRITICAL", "isCriticalAlertingEnabled"], allIcons.LMAlertSeverityCriticalOutline20Px)
const CriticalStaticAlertStatus = getAlertState(["children", "CRITICAL", "isStaticAlertSuppressed"], allIcons.LMAlertsCritical20Px)

// Demo props
const props = { children: { CRITICAL: { isCriticalAlertingEnabled: false, 
isStaticAlertSuppressed: true } } }

console.log(CriticalAlertStatus(props)); // Disabled
console.log(CriticalStaticAlertStatus(props)); // LMAlertsCritical20Px
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.js" integrity="sha512-3sdB9mAxNh2MIo6YkY05uY1qjkywAlDfCf5u1cSotv6k9CZUSyHVf4BJSpTYgla+YHLaHG8LUpqV7MHctlYzlw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda