(subject: string)
| 121 | * loaded, and add Error strings to shortname and description if something goes wrong. |
| 122 | */ |
| 123 | export 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 | |
| 169 | type setValue = (val: JSONValue) => Promise<void>; |
| 170 |
no test coverage detected