-
Notifications
You must be signed in to change notification settings - Fork 29
Custom Reproducibility Checklists , Attributes and their Unit testing. #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dibyanshu-pal-kushwaha
wants to merge
5
commits into
StatTag:master
Choose a base branch
from
dibyanshu-pal-kushwaha:osre26
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8e56993
Built Custom Template Builder
dibyanshu-pal-kushwaha 85ff24a
Added Tests for Custom Template Builder
dibyanshu-pal-kushwaha 4f6778b
Changes Done
dibyanshu-pal-kushwaha 996c984
Merge pull request #429 from dibyanshu-pal-kushwaha/osre26
lrasmus 7cceaa2
Custom Reproducibility Checklist and its units tests , Custom Attribu…
dibyanshu-pal-kushwaha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,37 +1,90 @@ | ||
| import React from 'react'; | ||
| import { Checkbox, FormControlLabel } from '@mui/material'; | ||
| import React, { useState } from 'react'; | ||
| import { Checkbox, FormControlLabel, IconButton, Dialog, DialogTitle, DialogContent, DialogActions, TextField, Button, Tooltip, } from '@mui/material'; | ||
| import { Add, Delete } from '@mui/icons-material'; | ||
| import styles from './AssetAttributes.css'; | ||
| import AssetsConfig from '../../constants/assets-config'; | ||
|
|
||
| const assetAttributes = (props) => { | ||
| const { asset, configuration, onUpdateAttribute } = props; | ||
| const { asset, configuration, onUpdateAttribute, customAttributes, onAddCustomAttribute, onDeleteCustomAttribute, } = props; | ||
|
|
||
| const [openAddDialog, setOpenAddDialog] = useState(false); | ||
| const [newAttributeName, setNewAttributeName] = useState(''); | ||
|
|
||
| const updateAttributeValue = (a) => { | ||
| if (onUpdateAttribute) { | ||
| onUpdateAttribute(a.target.name, a.target.checked); | ||
| } | ||
| }; | ||
|
|
||
| const handleAddCustomAttribute = () => { | ||
| const trimmedName = newAttributeName.trim(); | ||
| if(!trimmedName)return; | ||
|
|
||
| // Enforcing Attributes Name Length | ||
| const safeName = trimmedName.substring(0, AssetsConfig.CUSTOM_ATTRIBUTE_NAME_MAX_LENGTH); | ||
| const id = `custom_${safeName.toLowerCase().replace(/\s+/g, '_').replace(/[^a-z0-9_]/g, '')}`; | ||
|
|
||
| // Checking for the Duplicate IDs | ||
| const allAttributes = [...configuration, ...(customAttributes || [])]; | ||
| if (allAttributes.some((a) => a.id === id)) { | ||
| setOpenAddDialog(false); | ||
| setNewAttributeName(''); | ||
| return; | ||
| } | ||
|
|
||
| const newAttribute = { | ||
| id, | ||
| display: safeName, | ||
| type: 'bool', | ||
| default: false, | ||
| appliesTo: ['*'], | ||
| source: 'custom', | ||
| } | ||
|
|
||
| if (onAddCustomAttribute) { | ||
| onAddCustomAttribute(newAttribute); | ||
| } | ||
|
|
||
| setOpenAddDialog(false); | ||
| setNewAttributeName(''); | ||
| } | ||
|
|
||
| const handleDeleteCustomAttribute = (attributeId) => { | ||
| if (onDeleteCustomAttribute) { | ||
| onDeleteCustomAttribute(attributeId); | ||
| } | ||
| }; | ||
|
|
||
| const applicableAttributes = configuration | ||
| .map((a) => { | ||
| // If the asset doesn't have a content type (needed for attribute detection), | ||
| // or the attribute doesn't apply to this asset, skip it | ||
| if (asset.contentTypes == null || | ||
| (!a.appliesTo.includes('*') && !a.appliesTo.some((x) => asset.contentTypes.includes(x)))) { | ||
| return null; | ||
| if (a.appliesTo.includes('*')) { | ||
| return a; | ||
| } | ||
| if (asset.contentTypes == null || !a.appliesTo.some((x) => asset.contentTypes.includes(x))) { | ||
| return null; | ||
| } | ||
| return a; | ||
| }) | ||
| .filter((a) => a !== null); | ||
|
|
||
| const allApplicableAttributes = [ | ||
| ...applicableAttributes, | ||
| ...(customAttributes || []), | ||
| ]; | ||
|
|
||
| let controls = null; | ||
| if (asset) { | ||
| controls = applicableAttributes.map((a) => { | ||
| controls = allApplicableAttributes.map((a) => { | ||
| let control = <span>{a.display}</span>; | ||
| if (a.type === 'bool') { | ||
| const value = | ||
| asset.attributes && asset.attributes[a.id] !== undefined | ||
| ? asset.attributes[a.id] | ||
| : a.default; | ||
| control = ( | ||
| <div className={styles.attributeRow}> | ||
| <FormControlLabel | ||
| label={a.display} | ||
| control={ | ||
|
|
@@ -44,6 +97,18 @@ const assetAttributes = (props) => { | |
| /> | ||
| } | ||
| /> | ||
| {a.source === 'custom' && ( | ||
| <Tooltip title="Remove this custom attribute" enterDelay={300}> | ||
| <IconButton | ||
| size="small" | ||
| onClick={() => handleDeleteCustomAttribute(a.id)} | ||
| className={styles.deleteButton} | ||
| > | ||
| <Delete fontSize="small" /> | ||
| </IconButton> | ||
| </Tooltip> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| return <li key={a.id}>{control}</li>; | ||
|
|
@@ -52,7 +117,58 @@ const assetAttributes = (props) => { | |
|
|
||
| return ( | ||
| <div className={styles.container}> | ||
| <div className={styles.headerRow}> | ||
| <button | ||
| className={styles.addButton} | ||
| onClick={() => setOpenAddDialog(true)} | ||
| > | ||
| <Add fontSize="small" /> | ||
| <span>Add Attribute</span> | ||
| </button> | ||
| </div> | ||
| <ul className={styles.attributesList}>{controls}</ul> | ||
|
|
||
| { /*Custom Attribute Dialog */ } | ||
| <Dialog | ||
| open={openAddDialog} | ||
| onClose={() => { | ||
| setOpenAddDialog(false); | ||
| setNewAttributeName(''); | ||
| }} | ||
| maxWidth="sm" | ||
| fullWidth | ||
| > | ||
| <DialogTitle className={styles.dialogTitle}>Custom Attributes</DialogTitle> | ||
| <DialogContent className={styles.dialogContent}> | ||
| <label className={styles.formLabel}>Name of Attributes</label> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very minor - remove "s" on "Attributes" ("Name of Attribute") |
||
| <TextField | ||
| autoFocus | ||
| placeholder='Attributes like "Experimental"' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change to:
|
||
| value={newAttributeName} | ||
| onChange={(e) => setNewAttributeName(e.target.value)} | ||
| fullWidth | ||
| variant="outlined" | ||
| size="small" | ||
| inputProps={{ | ||
| maxLength: AssetsConfig.CUSTOM_ATTRIBUTE_NAME_MAX_LENGTH, | ||
| }} | ||
| /> | ||
| </DialogContent> | ||
| <DialogActions className={styles.dialogActions}> | ||
| <button className={styles.saveButton} onClick={handleAddCustomAttribute}> | ||
| Save | ||
| </button> | ||
| <button | ||
| className={styles.cancelButton} | ||
| onClick={() => { | ||
| setOpenAddDialog(false); | ||
| setNewAttributeName(''); | ||
| }} | ||
| > | ||
| Cancel | ||
| </button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to give the user a pop-up warning and confirmation here. Something like:
Are you sure you want to delete this custom attribute?
Note: This will delete the custom attribute for all assets in this project.
I want the user to be sure they know it's not deleting it for just a single attribute - that if they proceed, it disappears for everything.