Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22395515
ResourceSelectPure.jsx
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
ResourceSelectPure.jsx
View Options
import
React
from
"react"
;
import
resourceTypeCollection
from
"./mixins/resourceTypeCollection.jsx"
;
import
merge
from
"merge"
;
const
default_props
=
{
displayAttr
:
"id"
,
valueAttr
:
"id"
,
noValueOptionName
:
"--"
,
allowNoValue
:
false
,
onValueChange
:
value
=>
alert
(
value
),
label
:
"Select resource:"
,
disabled
:
false
,
value
:
""
,
resources
:
[],
displayAttrIsSafe
:
false
,
};
function
getAttr
(
name
,
resource
,
props
)
{
const
propname
=
name
+
"Attr"
;
if
(
typeof
props
[
propname
]
===
"string"
)
{
return
resource
[
props
[
propname
]]
||
resource
.
body
[
props
[
propname
]];
}
else
if
(
typeof
props
[
propname
]
===
"function"
)
{
return
props
[
propname
](
resource
);
}
}
function
getOptionValue
(
resource
,
props
)
{
return
getAttr
(
"value"
,
resource
,
props
);
}
function
getOptionName
(
resource
,
props
)
{
return
getAttr
(
"display"
,
resource
,
props
);
}
function
ResourceSelectPure
(
props_arg
)
{
const
props
=
merge
(
true
,
default_props
,
props_arg
);
function
handleChange
(
e
)
{
props
.
onValueChange
(
e
.
target
.
value
);
}
const
options
=
props
.
resources
.
map
(
resource
=>
{
const
value
=
getOptionValue
(
resource
,
props
);
const
name
=
getOptionName
(
resource
,
props
);
const
key
=
resource
.
id
;
if
(
props
.
displayAttrIsSafe
)
{
return
(
<
option
value
=
{
value
}
key
=
{
key
}
dangerouslySetInnerHTML
=
{{
__html
:
name
}}
/>
);
}
else
{
return
(
<
option
value
=
{
value
}
key
=
{
key
}
>
{
name
}
<
/option>
);
}
});
if
(
props
.
allowNoValue
)
{
options
.
unshift
(
<
option
value
=
""
key
=
"empty"
>
{
props
.
noValueOptionName
}
<
/option>
);
}
return
(
<
label
className
=
{
props
.
labelClassName
}
>
{
props
.
label
}
<
select
onChange
=
{
handleChange
}
value
=
{
props
.
value
}
disabled
=
{
props
.
disabled
}
className
=
{
props
.
className
}
>
{
options
}
<
/select>
<
/label>
);
}
export
default
ResourceSelectPure
;
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 16:27 (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1209241
Default Alt Text
ResourceSelectPure.jsx (2 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline