@@ -46,7 +46,12 @@ interface PersistenceService extends api.PersistenceService {
4646 configs: Array <api .PersistenceItemConfiguration >
4747 aliases: Record <string , string >
4848 editable: boolean
49- persisted: api .PersistenceItemInfo | null
49+ /**
50+ * The information about the persisted Item,
51+ * or `not_persisted` if the Item is not persisted by the persistence service,
52+ * or `unsupported` if the persistence service doesn't support querying for persisted items.
53+ */
54+ persisted: api .PersistenceItemInfo | ' not_persisted' | ' unsupported'
5055}
5156
5257const services = ref <Array <PersistenceService >>([])
@@ -63,22 +68,22 @@ const persistedBadges = computed(() => {
6368 const badges: Record <string , string | null > = {}
6469 services .value .forEach ((service ) => {
6570 const persisted = service .persisted
66- if (! persisted ) {
71+ if (persisted === ' unsupported ' ) {
6772 // Query for persistence items not supported
6873 badges [service .id ] = null
69- } else if (persisted .count != null && Number .isInteger (Number (persisted .count ))) {
70- // Show numeric count when available
71- badges [service .id ] = String (persisted .count )
72- } else if (persisted .name ) {
73- // No numeric count, but persisted value(s): show a presence indicator (empty badge)
74- badges [service .id ] = ' '
75- } else {
74+ } else if (persisted === ' not_persisted' ) {
7675 // Item has not been persisted
7776 // badges[service.id] = '0'
7877 // TODO: Currently, the API call does not distinguish between API call not supported for service and item not persisted.
7978 // To avoid showing misleading information, don't show badge if we don't get anything back (should be covered by first case if REST API is fixed.)
8079 // This can be reverted to showing 0 if the API is fixed.
8180 badges [service .id ] = null
81+ } else if (persisted .count != null && Number .isInteger (Number (persisted .count ))) {
82+ // Show numeric count when available
83+ badges [service .id ] = String (persisted .count )
84+ } else {
85+ // No numeric count, but persisted value(s): show a presence indicator (empty badge)
86+ badges [service .id ] = ' '
8287 }
8388 })
8489 return badges
@@ -111,11 +116,11 @@ const loadService = async (service: api.PersistenceService): Promise<Persistence
111116 }
112117 }
113118
114- let itemsPersisted: Array <api .PersistenceItemInfo > = []
119+ let itemsPersisted: Array <api .PersistenceItemInfo > | ' not_persisted ' | ' unsupported ' = ' unsupported '
115120 try {
116- itemsPersisted = await api .getItemsForPersistenceService ({ serviceId: service .id }) ?? []
121+ itemsPersisted = await api .getItemsForPersistenceService ({ serviceId: service .id }) ?? ' unsupported '
117122 } catch (err : unknown ) {
118- if (err instanceof ApiError && (err .response .statusText === ' Not Found ' || err . response . status === 404 )) {
123+ if (err instanceof ApiError && (err .response .status === 400 )) {
119124 // Not supported for service, leave itemsPersisted null
120125 } else {
121126 console .debug (' Error loading persistence items for' , service .id , err )
@@ -130,7 +135,7 @@ const loadService = async (service: api.PersistenceService): Promise<Persistence
130135 configs: serviceConfig ?.configs ?? [],
131136 aliases: serviceConfig ?.aliases ?? {},
132137 editable: serviceConfig ?.editable === undefined ? true : serviceConfig ?.editable ,
133- persisted: itemsPersisted .find ((item ) => item .name === props .item .name ) ?? null
138+ persisted: Array . isArray ( itemsPersisted ) ? ( itemsPersisted .find ((item ) => item .name === props .item .name ) ?? ' not_persisted ' ) : itemsPersisted
134139 } satisfies PersistenceService
135140}
136141
0 commit comments