Skip to content

Commit

Permalink
refactor: metadata path change metadata.actions.<method> -> `metada…
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Oct 12, 2024
1 parent 0b7cddb commit 3bbdca7
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 122 deletions.
10 changes: 3 additions & 7 deletions src/components/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const Table = ({

const [metadata, setMetaData] = useState(null);

let [metadata_action, SetMetadataAction] = useState(null)

const [is_loaded, setLoaded] = useState(false);

const [page, setPage] = useState(0);
Expand Down Expand Up @@ -62,8 +60,6 @@ const Table = ({

setMetaData(data)

SetMetadataAction(Object.keys(data.actions)[0])


if( SetContentHeaderIcon ) {

Expand Down Expand Up @@ -177,7 +173,7 @@ const Table = ({

}

if( key in metadata.actions[metadata_action] ) {
if( key in metadata.fields ) {

if( typeof(key) === 'string' ) {

Expand All @@ -191,7 +187,7 @@ const Table = ({
} else {

return (
<th key={key}>{metadata.actions[metadata_action][key].label}</th>
<th key={key}>{metadata.fields[key].label}</th>
)
}
}
Expand Down Expand Up @@ -222,7 +218,7 @@ const Table = ({
{
metadata.table_fields.map(key => {

if (key in metadata.actions[metadata_action]) {
if (key in metadata.fields) {

if( typeof(key) === 'string' ) {

Expand Down
16 changes: 8 additions & 8 deletions src/components/page/detail/DoubleColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const DoubleColumn = ({
<label>
{
(
field in metadata.actions.PUT
field in metadata.fields
) ?
metadata.actions.PUT[field].label
metadata.fields[field].label
:
""
}
Expand All @@ -40,9 +40,9 @@ const DoubleColumn = ({
<label>
{
(
field in metadata.actions.PUT
field in metadata.fields
) ?
metadata.actions.PUT[field].label
metadata.fields[field].label
:
""
}
Expand All @@ -66,9 +66,9 @@ const DoubleColumn = ({
<label>
{
(
field in metadata.actions.PUT
field in metadata.fields
) ?
metadata.actions.PUT[field].label
metadata.fields.label
:
""
}
Expand All @@ -85,9 +85,9 @@ const DoubleColumn = ({
<label>
{
(
field in metadata.actions.PUT
field in metadata.fields
) ?
metadata.actions.PUT[field].label
metadata.fields[field].label
:
""
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/page/detail/SingleColumn.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SingleColumn = ({

if(
field == "model_notes"
|| String(metadata.actions.PUT[field].type).toLowerCase() == "json"
|| String(metadata.fields[field].type).toLowerCase() == "json"
) {

return(
Expand All @@ -26,9 +26,9 @@ const SingleColumn = ({
<label>
{
(
field in metadata.actions.PUT
field in metadata.fields
) ?
metadata.actions.PUT[field].label
metadata.fields[field].label
:
""
}
Expand All @@ -49,9 +49,9 @@ const SingleColumn = ({
<label>
{
(
field in metadata.actions.PUT
field in metadata.fields
) ?
metadata.actions.PUT[field].label
metadata.fields[field].label
:
""
}
Expand Down
65 changes: 31 additions & 34 deletions src/components/page/ticket/Comment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const TicketCommentForm = ({
console.log(post_url)
let comment_class = 'comment-type-default comment-form'

let action_keyword = Object.keys(metadata.actions)[0]


const [task_comment, setTaskComment] = useState(false)

const [form_data, setFormData] = useState({})
Expand All @@ -43,7 +40,7 @@ const TicketCommentForm = ({

if( ! form_data.comment_type ) {

for( let comment_type of metadata.actions[action_keyword]['comment_type'].choices) {
for( let comment_type of metadata.fields['comment_type'].choices) {

if( 'comment' === String(comment_type.display_name).toLowerCase() ) {
setFormData((prevState) => ({ ...prevState, ['comment_type']: comment_type.value }))
Expand Down Expand Up @@ -103,12 +100,12 @@ const TicketCommentForm = ({
<fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['source'].choices}
choices={metadata.fields['source'].choices}
id = 'source'
label = {metadata.actions[action_keyword]['source'].label}
helptext = {metadata.actions[action_keyword]['source'].help_text}
label = {metadata.fields['source'].label}
helptext = {metadata.fields['source'].help_text}
// error_text = {form_error && form_error[field_key]}
required = {metadata.actions[action_keyword]['source'].required}
required = {metadata.fields['source'].required}
// value={1}
onChange={handleChange}
/>
Expand All @@ -117,12 +114,12 @@ const TicketCommentForm = ({
{task_comment && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['status'].choices}
choices={metadata.fields['status'].choices}
id = 'status'
label = {metadata.actions[action_keyword]['status'].label}
helptext = {metadata.actions[action_keyword]['status'].help_text}
label = {metadata.fields['status'].label}
helptext = {metadata.fields['status'].help_text}
// error_text = {form_error && form_error[field_key]}
required = {metadata.actions[action_keyword]['status'].required}
required = {metadata.fields['status'].required}
value={1}
onChange={handleChange}
/>
Expand All @@ -131,12 +128,12 @@ const TicketCommentForm = ({
{task_comment && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['responsible_user'].choices}
choices={metadata.fields['responsible_user'].choices}
id = 'responsible_user'
label = {metadata.actions[action_keyword]['responsible_user'].label}
helptext = {metadata.actions[action_keyword]['responsible_user'].help_text}
label = {metadata.fields['responsible_user'].label}
helptext = {metadata.fields['responsible_user'].help_text}
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[action_keyword]['responsible_user'].required}
// required = {metadata.fields['responsible_user'].required}
// value={1}
onChange={handleChange}
/>
Expand All @@ -145,12 +142,12 @@ const TicketCommentForm = ({
{task_comment && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['responsible_team'].choices}
choices={metadata.fields['responsible_team'].choices}
id = 'responsible_team'
label = {metadata.actions[action_keyword]['responsible_team'].label}
helptext = {metadata.actions[action_keyword]['responsible_team'].help_text}
label = {metadata.fields['responsible_team'].label}
helptext = {metadata.fields['responsible_team'].help_text}
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[action_keyword]['responsible_user'].required}
// required = {metadata.fields['responsible_user'].required}
// value={1}
onChange={handleChange}
/>
Expand All @@ -159,12 +156,12 @@ const TicketCommentForm = ({
{ true && <fieldset className={comment_class}>
<span>
<Select
choices={metadata.actions[action_keyword]['category'].choices}
choices={metadata.fields['category'].choices}
id = 'category'
label = {metadata.actions[action_keyword]['category'].label}
helptext = {metadata.actions[action_keyword]['category'].help_text}
label = {metadata.fields['category'].label}
helptext = {metadata.fields['category'].help_text}
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[action_keyword]['responsible_user'].required}
// required = {metadata.fields['responsible_user'].required}
// value={1}
onChange={handleChange}
/>
Expand Down Expand Up @@ -194,8 +191,8 @@ const TicketCommentForm = ({
<span>
<TextField
id = 'planned_start_date'
label = {metadata.actions[action_keyword]['planned_start_date'].label}
helptext = {metadata.actions[action_keyword]['planned_start_date'].help_text}
label = {metadata.fields['planned_start_date'].label}
helptext = {metadata.fields['planned_start_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
Expand All @@ -209,8 +206,8 @@ const TicketCommentForm = ({
<span>
<TextField
id = 'planned_finish_date'
label = {metadata.actions[action_keyword]['planned_finish_date'].label}
helptext = {metadata.actions[action_keyword]['planned_finish_date'].help_text}
label = {metadata.fields['planned_finish_date'].label}
helptext = {metadata.fields['planned_finish_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
Expand All @@ -224,8 +221,8 @@ const TicketCommentForm = ({
<span>
<TextField
id = 'real_start_date'
label = {metadata.actions[action_keyword]['real_start_date'].label}
helptext = {metadata.actions[action_keyword]['real_start_date'].help_text}
label = {metadata.fields['real_start_date'].label}
helptext = {metadata.fields['real_start_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
Expand All @@ -239,8 +236,8 @@ const TicketCommentForm = ({
<span>
<TextField
id = 'real_start_date'
label = {metadata.actions[action_keyword]['real_finish_date'].label}
helptext = {metadata.actions[action_keyword]['real_finish_date'].help_text}
label = {metadata.fields['real_finish_date'].label}
helptext = {metadata.fields['real_finish_date'].help_text}
type='datetime-local'
// error_text = {form_error && form_error[field_key]}
// required = {metadata.actions[meta_action][field_key].required}
Expand All @@ -254,10 +251,10 @@ const TicketCommentForm = ({

<Button
button_text="Comment"
menu_entries={metadata.actions[action_keyword]['comment_type'].choices}
menu_entries={metadata.fields['comment_type'].choices}
MenuClickCallback={(menu_value) => {

const comment_types = metadata.actions[action_keyword]['comment_type'].choices
const comment_types = metadata.fields['comment_type'].choices
let menu_entry = ''

console.log(`menu entry click value ${menu_value}`)
Expand Down
2 changes: 1 addition & 1 deletion src/components/page/ticket/Comments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TicketComments = ({

try {

comment_type = String(metadata.actions.POST.comment_type.choices[Number(comment_data.comment_type)-1].display_name).toLowerCase()
comment_type = String(metadata.fields.comment_type.choices[Number(comment_data.comment_type)-1].display_name).toLowerCase()

}catch( e ) {

Expand Down
2 changes: 1 addition & 1 deletion src/components/page/ticket/RelatedTickets.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const RelatedTickets = ({

let related_name = ''

for( let choice of metadata.actions['POST']['how_related']['choices']) {
for( let choice of metadata.fields['how_related']['choices']) {

if( Number(related_ticket.how_related) === Number(choice.value) ) {
related_name = String(choice.display_name).toLowerCase()
Expand Down
25 changes: 4 additions & 21 deletions src/functions/FieldData.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,15 @@ export default function FieldData({

let field_data = '';

let fields = {}


if( 'POST' in metadata.actions ) {

fields = metadata.actions.POST

} else if( 'PUT' in metadata.actions ) {

fields = metadata.actions.PUT

} else if( 'GET' in metadata.actions ) {

fields = metadata.actions.GET

}

let data_field = field_lookup(field_name, data)

if( data_field ) {

let field_type = null

if( field_name in fields ) {
if( field_name in metadata.fields ) {

field_type = fields[field_name].type
field_type = metadata.fields[field_name].type

}

Expand Down Expand Up @@ -109,7 +92,7 @@ export default function FieldData({

case 'Choice':

for( const [key, choice] of Object.entries(fields[field_name].choices) ) {
for( const [key, choice] of Object.entries(metadata.fields[field_name].choices) ) {

if( Number(data_field) == Number(choice.value) ) {

Expand Down Expand Up @@ -143,7 +126,7 @@ export default function FieldData({
case 'Relationship':
case 'Serializer':

if( fields[field_name].relationship_type === 'ManyToMany' ) {
if( metadata.fields[field_name].relationship_type === 'ManyToMany' ) {

if( typeof (data_field) === 'object' ) {

Expand Down
Loading

0 comments on commit 3bbdca7

Please sign in to comment.