// External modules import * as React from 'react'; import {connect} from 'react-redux'; // Types import {ASSET_STATE, IAssetItem, ISetItem} from '../../interfaces'; import {IApplicationState} from '../../store'; import {superdeskApi} from '../../apis'; // Redux Actions & Selectors import {getActiveSets} from '../../store/sets/selectors'; // UI import {FormLabel, Input, Option, Select} from 'superdesk-ui-framework/react'; import {FormGroup, FormRow} from '../../ui'; // Utils import {getHumanReadableFileSize} from '../../utils/ui'; interface IProps { asset: Partial; disabled?: boolean; onChange(field: string, value: string): void; sets: Array; fields?: Array; allowedStates?: Array; } const mapStateToProps = (state: IApplicationState) => ({ sets: getActiveSets(state), }); class AssetEditorComponent extends React.PureComponent { onChange: Dictionary void>; constructor(props: IProps) { super(props); this.onChange = { name: (value: string) => this.props.onChange('name', value.trim()), description: (value: string) => this.props.onChange('description', value.trim()), filename: (value: string) => this.props.onChange('filename', value.trim()), state: (value: string) => this.props.onChange('state', value), set_id: (value: string) => this.props.onChange('set_id', value), }; } fieldEnabled(field: keyof IAssetItem) { return (this.props.fields == null || this.props.fields.includes(field)) ? true : null; } render() { const {gettext} = superdeskApi.localization; const allowedStates = this.props.allowedStates ?? [ ASSET_STATE.DRAFT, ASSET_STATE.INTERNAL, ASSET_STATE.PUBLIC, ]; return ( {this.props.asset.filename} {this.props.asset.mimetype} {this.props.asset.length && getHumanReadableFileSize(this.props.asset.length)} {this.fieldEnabled('name') && ( )} {this.fieldEnabled('description') && ( )} {this.fieldEnabled('state') && ( )} {this.fieldEnabled('set_id') && ( )} ); } } export const AssetEditor = connect(mapStateToProps)(AssetEditorComponent);