Mirror of https://github.com/roostorg/osprey github.com/roostorg/osprey
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 57 lines 2.4 kB view raw
1import DefaultFeature from '../models/DefaultFeature'; 2import { ApplicationConfig } from '../stores/ApplicationConfigStore'; 3import { RawUIConfig } from '../types/ConfigTypes'; 4import HTTPUtils, { HTTPResponse } from '../utils/HTTPUtils'; 5 6export async function getApplicationConfig(): Promise<ApplicationConfig> { 7 const response: HTTPResponse = await HTTPUtils.get('config'); 8 if (!response.ok) { 9 throw new Error('Failed to load initial application config: ' + response.error.message); 10 } 11 12 const rawConfigData: RawUIConfig = response.data; 13 const featureNameToEntityTypeMapping = new Map(Object.entries(rawConfigData.feature_name_to_entity_type_mapping)); 14 const entityToFeatureSetMapping = new Map(); 15 16 featureNameToEntityTypeMapping.forEach((val, key) => { 17 const newFeatureSet = entityToFeatureSetMapping.has(val) ? [...entityToFeatureSetMapping.get(val), key] : [key]; 18 entityToFeatureSetMapping.set(val, new Set(newFeatureSet)); 19 }); 20 21 const knownFeatureCategories: { [key: string]: string[] } = {}; 22 23 rawConfigData.known_feature_locations.forEach((feature) => { 24 const { source_path: category, name: featureName } = feature; 25 26 if (knownFeatureCategories.hasOwnProperty(category)) { 27 knownFeatureCategories[category].push(featureName); 28 } else { 29 knownFeatureCategories[category] = [featureName]; 30 } 31 }); 32 33 return { 34 defaultSummaryFeatures: rawConfigData.default_summary_features.map( 35 (feature) => new DefaultFeature(feature.actions, feature.features) 36 ), 37 featureNameToEntityTypeMapping, 38 featureNameToValueTypeMapping: new Map(Object.entries(rawConfigData.feature_name_to_value_type_mapping)), 39 entityToFeatureSetMapping, 40 externalLinks: new Map(Object.entries(rawConfigData.external_links)), 41 labelInfoMapping: new Map( 42 Object.entries(rawConfigData.label_info_mapping).map(([name, info]) => [ 43 name, 44 { 45 validFor: new Set(info.valid_for), 46 connotation: info.connotation, 47 description: info.description, 48 }, 49 ]) 50 ), 51 knownFeatureNames: new Set(rawConfigData.known_feature_locations.map((feature) => feature.name).sort()), 52 knownFeatureCategories, 53 knownActionNames: new Set(rawConfigData.known_action_names.sort()), 54 currentUser: rawConfigData.current_user, 55 ruleInfoMapping: new Map(Object.entries(rawConfigData.rule_info_mapping)), 56 }; 57}