Skip to content

Commit

Permalink
[fix] when pressing esc in a property search box (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
sijav authored May 13, 2024
1 parent 16f33d2 commit bff654a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
14 changes: 7 additions & 7 deletions src/locales/de-DE/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ msgstr "Business"
msgid "Cancel"
msgstr "Stornieren"

#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:211
#: src/pages/panel/inventory/inventory-form/InventoryFormMoreValue.tsx:161
#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:213
#: src/pages/panel/inventory/inventory-form/InventoryFormMoreValue.tsx:163
#: src/pages/panel/inventory/inventory-form/InventoryFormTagsValue.tsx:150
msgid "Change"
msgstr ""
Expand Down Expand Up @@ -1156,7 +1156,7 @@ msgstr "Nächste Synchronisierung"
msgid "No"
msgstr ""

#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:202
#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:204
msgid "No {label} found for {typed}"
msgstr ""

Expand Down Expand Up @@ -1444,7 +1444,7 @@ msgstr "Risiko"
msgid "Roles"
msgstr "Rollen"

#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:167
#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:169
msgid "Search {0}"
msgstr ""

Expand Down Expand Up @@ -1499,12 +1499,12 @@ msgstr "Sende Einladung"
msgid "Setting Up Email Notifications"
msgstr "E-Mail-Benachrichtigungen einrichten"

#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:43
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:59
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:45
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:61
msgid "Severities"
msgstr ""

#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:53
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:55
#: src/pages/panel/inventory/inventory-form/utils/getAutoCompleteFromKey.tsx:150
#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:157
#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:205
Expand Down
14 changes: 7 additions & 7 deletions src/locales/en-US/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ msgstr "Business"
msgid "Cancel"
msgstr "Cancel"

#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:211
#: src/pages/panel/inventory/inventory-form/InventoryFormMoreValue.tsx:161
#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:213
#: src/pages/panel/inventory/inventory-form/InventoryFormMoreValue.tsx:163
#: src/pages/panel/inventory/inventory-form/InventoryFormTagsValue.tsx:150
msgid "Change"
msgstr "Change"
Expand Down Expand Up @@ -1156,7 +1156,7 @@ msgstr "Next Sync"
msgid "No"
msgstr "No"

#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:202
#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:204
msgid "No {label} found for {typed}"
msgstr "No {label} found for {typed}"

Expand Down Expand Up @@ -1444,7 +1444,7 @@ msgstr "Risk"
msgid "Roles"
msgstr "Roles"

#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:167
#: src/pages/panel/inventory/inventory-form/InventoryFormDefaultValue.tsx:169
msgid "Search {0}"
msgstr "Search {0}"

Expand Down Expand Up @@ -1499,12 +1499,12 @@ msgstr "Send Invite"
msgid "Setting Up Email Notifications"
msgstr "Setting Up Email Notifications"

#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:43
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:59
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:45
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:61
msgid "Severities"
msgstr "Severities"

#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:53
#: src/pages/panel/inventory/inventory-form/InventoryFormSeverity.tsx:55
#: src/pages/panel/inventory/inventory-form/utils/getAutoCompleteFromKey.tsx:150
#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:157
#: src/pages/panel/workspace-settings/workspace-alerting-settings/WorkspaceAlertingSettings.tsx:205
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,10 @@ export const InventoryFormDefaultValue = ({
setSelectedValues(values)
}, [values])

const onSubmit = () => {
onChange(selectedValues)
const onSubmit = (_?: unknown, reason?: 'backdropClick' | 'escapeKeyDown') => {
if (reason !== 'escapeKeyDown') {
onChange(selectedValues)
}
onClose()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export const InventoryFormMoreValue = ({
const { is } = useFixQueryParser()
const [fqn, setFqn] = useState(defaultFqn)
const [value, setValue] = useState(defaultValue)
const onSubmit = () => {
onChange(value)
const handleSubmit = (_?: unknown, reason?: 'backdropClick' | 'escapeKeyDown') => {
if (reason !== 'escapeKeyDown') {
onChange(value)
}
setFqn(defaultFqn)
setValue(defaultValue)
onClose()
Expand Down Expand Up @@ -77,7 +79,7 @@ export const InventoryFormMoreValue = ({
open={!!open}
anchorEl={open}
anchorOrigin={{ horizontal: 'left', vertical: 'bottom' }}
onClose={onSubmit}
onClose={handleSubmit}
sx={{
[`& .${backdropClasses.root}`]: { bgcolor: 'transparent' },
maxHeight: `calc(100% - ${(open?.offsetTop ?? 0) + (open?.offsetHeight ?? 0) + panelUI.headerHeight}px)`,
Expand All @@ -90,7 +92,7 @@ export const InventoryFormMoreValue = ({
component="form"
onSubmit={(e) => {
e.preventDefault()
onSubmit()
handleSubmit()
}}
>
<Stack direction="row" flexWrap="wrap" pt={2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useMemo, useState } from 'react'
import { getColorBySeverity } from 'src/pages/panel/shared/utils'
import { DefaultPropertiesKeys, useFixQueryParser } from 'src/shared/fix-query-parser'
import { SeverityType } from 'src/shared/types/server'
import { snakeCaseToUFStr } from 'src/shared/utils/snakeCaseToUFStr'
import { InventoryFormDefaultValue } from './InventoryFormDefaultValue'
import { InventoryFormField } from './InventoryFormField'
import { termValueToStringArray } from './utils'
Expand Down Expand Up @@ -36,6 +37,7 @@ export const InventoryFormSeverity = ({ preItems }: { preItems: AutoCompletePreD
return result
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [JSON.stringify(values), preItems.severities])

return (
<>
<InventoryFormField
Expand All @@ -53,7 +55,7 @@ export const InventoryFormSeverity = ({ preItems }: { preItems: AutoCompletePreD
label={t`Severity`}
showItemLabel={(item) => (
<Typography color={getColorBySeverity(item.value as SeverityType)} component="span">
{item.label}
{snakeCaseToUFStr(item.label)}
</Typography>
)}
labelPlural={t`Severities`}
Expand Down

0 comments on commit bff654a

Please sign in to comment.