Make ICON section work consistently between old and new GUI. (#8369)

- Handle name mismatch in icons between old and new IDE.
- Set the default icon for a few types.
- If can't find and icon use the Enso logo.

![image](https://github.com/enso-org/enso/assets/4699705/43d828b4-58cf-429e-b659-b1c389953b23)
This commit is contained in:
James Dunkerley 2023-11-23 09:03:34 +00:00 committed by GitHub
parent 1cf5ea96d6
commit ed9e71c4eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View File

@ -8,7 +8,7 @@ import { injectGraphSelection } from '@/providers/graphSelection'
import { useGraphStore, type Node } from '@/stores/graph'
import { useApproach } from '@/util/animation'
import { usePointer, useResizeObserver } from '@/util/events'
import { methodNameToIcon, typeNameToIcon } from '@/util/getIconName'
import { mapOldIconName, typeNameToIcon } from '@/util/getIconName'
import type { Opt } from '@/util/opt'
import { Rect } from '@/util/rect'
import { Vec2 } from '@/util/vec2'
@ -124,15 +124,14 @@ const suggestionEntry = computed(() => graph.db.nodeMainSuggestion.lookup(nodeId
const color = computed(() => graph.db.getNodeColorStyle(nodeId.value))
const icon = computed(() => {
if (suggestionEntry.value?.iconName) {
return suggestionEntry.value.iconName
return mapOldIconName(suggestionEntry.value.iconName)
}
const methodName = expressionInfo.value?.methodCall?.methodPointer.name
if (methodName != null) {
return methodNameToIcon(methodName)
} else if (outputTypeName.value != null) {
if (methodName == null && outputTypeName.value != null) {
return typeNameToIcon(outputTypeName.value)
} else {
return 'in_out'
return 'enso_logo'
}
})

View File

@ -1,28 +1,37 @@
import type { Icon } from '@/util/iconName'
const methodNameToIconLookup: Record<string, Icon> = {
const oldIconNameToNewIconNameLookup: Record<string, string> = {
/* eslint-disable camelcase */
read: 'text',
join: 'join3',
union: 'union',
set: 'edit',
filter: 'preparation',
add_columns: 'add_column',
add_rows: 'add_row',
remove_columns: 'remove_column',
remove_rows: 'remove_row',
dataframe_clean: 'clean_dataframe',
dataframe_map_row: 'map_row',
dataframe_map_column: 'add_column',
dataframes_join: 'join3',
dataframes_union: 'union',
sigma: 'transform4',
io: 'in_out',
date_and_time: 'time',
spatial: 'location',
predictive: 'predict',
machine_learning: 'robot',
/* eslint-enable camelcase */
}
export function methodNameToIcon(methodName: string): Icon {
return methodNameToIconLookup[methodName] ?? 'in_out'
export function mapOldIconName(oldIconName: string): Icon {
const mappedName = oldIconNameToNewIconNameLookup[oldIconName] ?? oldIconName
return mappedName as Icon
}
const typeNameToIconLookup: Record<string, Icon> = {
'Standard.Base.Data.Table.Table': 'array_new',
'Standard.Base.Data.Vector.Vector': 'array_new2',
'Standard.Base.Data.Text.Text': 'text_input',
'Standard.Base.Data.Numbers.Integer': 'number_input',
'Standard.Base.Data.Numbers.Float': 'number_input',
'Standard.Base.Data.Array.Array': 'array_new',
'Standard.Base.Data.Vector.Vector': 'array_new',
'Standard.Base.Data.Time.Date.Date': 'calendar',
'Standard.Base.Data.Time.Date_Time.Date_Time': 'calendar',
'Standard.Base.Data.Time.Time_Of_Day.Time_Of_Day': 'time',
}
export function typeNameToIcon(typeName: string): Icon {
return typeNameToIconLookup[typeName] ?? 'in_out'
return typeNameToIconLookup[typeName] ?? 'enso_logo'
}