MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / useProperty

Function useProperty

react/src/hooks.ts:123–167  ·  view source on GitHub ↗
(subject: string)

Source from the content-addressed store, hash-verified

121 * loaded, and add Error strings to shortname and description if something goes wrong.
122 */
123export function useProperty(subject: string): Property {
124 const propertyResource = useResource(subject);
125
126 if (propertyResource.loading) {
127 return {
128 subject,
129 datatype: Datatype.UNKNOWN,
130 shortname: 'loading',
131 description: `Loading property ${subject}`,
132 loading: true,
133 };
134 }
135
136 if (propertyResource.error) {
137 return {
138 subject,
139 datatype: Datatype.UNKNOWN,
140 shortname: 'error',
141 description:
142 'Error getting Property. ' + propertyResource.getError().message,
143 error: propertyResource.getError(),
144 };
145 }
146
147 const datatypeUrl = propertyResource.get(urls.properties.datatype) as string;
148 const datatype = datatypeFromUrl(datatypeUrl);
149 const shortname = propertyResource.get(urls.properties.shortname) as string;
150 const description = propertyResource.get(
151 urls.properties.description,
152 ) as string;
153 const classType = propertyResource.get(urls.properties.classType) as string;
154 const isDynamic = !!propertyResource.get(
155 urls.properties.isDynamic,
156 ) as boolean;
157
158 const property: Property = {
159 subject,
160 datatype,
161 shortname,
162 description,
163 classType,
164 isDynamic,
165 };
166 return property;
167}
168
169type setValue = (val: JSONValue) => Promise<void>;
170

Callers 4

HeaderItemFunction · 0.90
PropValFunction · 0.90
ResourceFieldFunction · 0.90
ValueFormFunction · 0.90

Calls 4

datatypeFromUrlFunction · 0.90
useResourceFunction · 0.85
getErrorMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected