/*! * Copyright (c) Microsoft. All rights reserved. * Licensed under the MIT license. See LICENSE file in the project. */ import { isOutputColumnStep, NodeInput } from '@datashaper/workflow' import styled from '@essex/styled-components' import isNil from 'lodash-es/isNil.js' import { memo, useMemo } from 'react' import type { DescriptionRow, VerbDescriptionProps } from './types.js' import { getInputNode } from '../../../util.js' function VerbDescriptionFn({ step, rows, output, showInput, showOutput, showOutputColumn, style, }: VerbDescriptionProps) { const rws = useMemo(() => { function loop(rows: DescriptionRow[]) { return rows.map((row, index) => ( {row.before ? {row.before} : null} {isNil(row.value) ? ( ) : ( {row.value} )} {row.after ? {row.after} : null} {row.sub ? loop(row.sub) : null} )) } return loop(rows) }, [rows]) const shouldShowOutputColumn = showOutputColumn && isOutputColumnStep(step) const input = getInputNode(step, NodeInput.Source) return ( {step.verb} {showInput ? ( table {!input ? : {input}} ) : null} {rws} {showOutput ? ( into table {!output ? : {output}} ) : null} {shouldShowOutputColumn ? ( as column {!(step.args as any).to ? ( ) : ( {(step.args as any).to} )} ) : null} ) } export const VerbDescription = memo(VerbDescriptionFn) const Container = styled.div` display: flex; flex-direction: column; align-items: flex-start; min-height: 180px; ` const Verb = styled.div` text-transform: uppercase; font-weight: bold; align-items: center; width: 100%; color: ${({ theme }) => theme.palette.neutralTertiary}; ` const Row = styled.div` padding-left: 8px; display: flex; flex-direction: column; ` const KeyValue = styled.div` display: flex; justify-content: flex-start; gap: 4px; ` const Key = styled.div`` const Unset = styled.div` color: ${({ theme }) => theme.palette.neutralTertiaryAlt}; &:before { content: 'unset'; } ` const Value = styled.div` max-width: 240px; text-overflow: ellipsis; overflow: hidden; font-weight: bold; color: ${({ theme }) => theme.palette.neutralTertiary}; `