-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preview - reduce cognitive complexity
- Loading branch information
1 parent
1cc6e76
commit 2281fab
Showing
5 changed files
with
233 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { FC } from 'react'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import classNames from 'classnames'; | ||
import Lightbulb16 from '@src/assets/lightbulb-shining-16.svg?react'; | ||
import { RESOURCE_TEMPLATE_IDS } from '@common/constants/bibframe.constants'; | ||
import { BLOCKS_BFLITE } from '@common/constants/bibframeMapping.constants'; | ||
import { getRecordId } from '@common/helpers/record.helper'; | ||
import { Button, ButtonType } from '@components/Button'; | ||
import { PreviewActionsDropdown } from '@components/PreviewActionsDropdown'; | ||
|
||
type LabelProps = { | ||
isEntity: boolean; | ||
isBlock: boolean; | ||
isGroupable: boolean; | ||
isInstance: boolean; | ||
altDisplayNames?: Record<string, string>; | ||
displayNameWithAltValue: string; | ||
showEntityActions: boolean; | ||
bfid: string; | ||
handleNavigateToEditPage: VoidFunction; | ||
record: RecordEntry<RecursiveRecordSchema> | null; | ||
}; | ||
|
||
export const Labels: FC<LabelProps> = ({ | ||
isEntity, | ||
isBlock, | ||
isGroupable, | ||
isInstance, | ||
altDisplayNames, | ||
displayNameWithAltValue, | ||
showEntityActions, | ||
bfid, | ||
handleNavigateToEditPage, | ||
record, | ||
}) => { | ||
return ( | ||
<strong | ||
className={classNames({ | ||
'entity-heading': isEntity, | ||
'sub-heading': isBlock, | ||
'value-heading': !isGroupable, | ||
})} | ||
> | ||
{isEntity && !isInstance && !altDisplayNames && <Lightbulb16 />} | ||
{displayNameWithAltValue} | ||
{showEntityActions && !isInstance && ( | ||
<Button type={ButtonType.Primary} className="toggle-entity-edit" onClick={handleNavigateToEditPage}> | ||
<FormattedMessage id={`ld.edit${RESOURCE_TEMPLATE_IDS[bfid]}`} /> | ||
</Button> | ||
)} | ||
{showEntityActions && isInstance && ( | ||
<PreviewActionsDropdown | ||
ownId={getRecordId(record, BLOCKS_BFLITE.WORK.uri, BLOCKS_BFLITE.INSTANCE.referenceKey)} | ||
referenceId={getRecordId(record, BLOCKS_BFLITE.WORK.uri)} | ||
entityType={BLOCKS_BFLITE.INSTANCE.resourceType} | ||
handleNavigateToEditPage={handleNavigateToEditPage} | ||
/> | ||
)} | ||
</strong> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { FC } from 'react'; | ||
|
||
type ValuesProps = { | ||
userValues: UserValues; | ||
uuid: string; | ||
shouldRenderPlaceholders: boolean; | ||
isDependentDropdown: boolean; | ||
htmlId?: string; | ||
}; | ||
|
||
export const Values: FC<ValuesProps> = ({ | ||
userValues, | ||
uuid, | ||
shouldRenderPlaceholders, | ||
isDependentDropdown, | ||
htmlId, | ||
}) => { | ||
return userValues[uuid] | ||
? userValues[uuid]?.contents?.map(({ label, meta: { uri, parentUri, basicLabel } = {} } = {}) => { | ||
if (!label && !basicLabel) return; | ||
|
||
const selectedLabel = basicLabel ?? label; | ||
|
||
return ( | ||
selectedLabel && ( | ||
<div key={`${selectedLabel}${uri}`}> | ||
{uri || parentUri ? ( | ||
<a className="preview-value-link" target="blank" href={uri ?? parentUri}> | ||
{selectedLabel} | ||
</a> | ||
) : ( | ||
<>{selectedLabel}</> | ||
)} | ||
</div> | ||
) | ||
); | ||
}) | ||
: shouldRenderPlaceholders && !isDependentDropdown && ( | ||
<div id={htmlId} className="value-group-wrapper"> | ||
- | ||
</div> | ||
); | ||
}; |