diff --git a/src/locales/de-DE/messages.po b/src/locales/de-DE/messages.po index d979c0ae..70e8af49 100644 --- a/src/locales/de-DE/messages.po +++ b/src/locales/de-DE/messages.po @@ -81,11 +81,11 @@ msgstr "Alter" msgid "Already have an account? Click here to Log in." msgstr "Sie haben bereits ein Konto? Klicken Sie hier, um sich einzuloggen." -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:73 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:107 msgid "Alternatively if you would like to deploy the stack manually, you can use the following CloudFormation template" msgstr "Wenn Sie den Stack alternativ manuell bereitstellen möchten, können Sie folgendes CloudFormation-Template verwenden" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:68 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:102 msgid "Alternatively: Manual Cloud Setup" msgstr "Alternativ: Manuelles Cloud Setup" @@ -97,7 +97,7 @@ msgstr "und" msgid "Are you sure?" msgstr "Bist du sicher?" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:35 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:45 msgid "Automatic Cloud Setup" msgstr "Automatisches Cloud Setup" @@ -180,11 +180,11 @@ msgstr "Kritisch" msgid "Dashboard" msgstr "Dashboard" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:116 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:151 msgid "Date Picker" msgstr "Datumsauswahl" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:108 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:143 msgid "Date Time Picker" msgstr "Datum-/Uhrzeitauswahl" @@ -196,7 +196,7 @@ msgid "Delete" msgstr "Löschen" #: src/pages/panel/setup-cloud/SetupCloudButton.tsx:15 -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:49 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:83 msgid "Deploy Stack" msgstr "Deploy Stack" @@ -230,7 +230,7 @@ msgstr "Ermöglicht" msgid "Events" msgstr "Veranstaltungen" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:92 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:126 msgid "External Id" msgstr "External Id" @@ -238,7 +238,7 @@ msgstr "External Id" #~ msgid "Failed Checks" #~ msgstr "Fehlgeschlagene Prüfungen" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:100 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:135 msgid "False" msgstr "FALSCH" @@ -279,12 +279,12 @@ msgstr "ID" msgid "Improved" msgstr "Verbessert" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:38 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:48 msgid "In the next step we are going to set up the trust between FIX and your AWS cloud account." msgstr "Im nächsten Schritt richten wir einen Trust zwischen FIX und Ihrem AWS Konto ein." #: src/pages/panel/inventory/InventoryFormFilterRowProperty.tsx:282 -#: src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx:159 +#: src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx:193 msgid "Invalid Value" msgstr "Ungültiger Wert" @@ -300,7 +300,7 @@ msgstr "Inventar" msgid "Kind" msgstr "Art" -#: src/pages/panel/inventory/InventoryForm.tsx:213 +#: src/pages/panel/inventory/InventoryForm.tsx:212 msgid "Kinds" msgstr "Arten" @@ -321,7 +321,7 @@ msgstr "Ausloggen" msgid "Low" msgstr "Niedrig" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:41 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:51 msgid "Make sure that you are already logged into the correct AWS account, before pressing the DEPLOY STACK button." msgstr "Stellen Sie sicher, dass Sie bereits beim richtigen AWS Konto angemeldet sind, bevor Sie auf die Schaltfläche DEPLOY STACK klicken." @@ -368,11 +368,11 @@ msgstr "Sie löschen gerade ein Management- oder delegiertes Admin-Konto. Beacht msgid "Nothing to show yet" msgstr "Noch nichts zu zeigen" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:94 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:129 msgid "Null" msgstr "Null" -#: src/pages/panel/inventory/InventoryAdvanceSearch.tsx:133 +#: src/pages/panel/inventory/InventoryAdvanceSearch.tsx:109 msgid "Oops! It looks like your query didn't match our format. Please check and try again." msgstr "Ups! Ihre Eingabe entspricht nicht unserem Format. Bitte überprüfen Sie sie und versuchen Sie es erneut." @@ -491,11 +491,11 @@ msgstr "Stichworte" #~ msgid "Task \"{0}\" with workflow \"{1}\" failed: {2}" #~ msgstr "Aufgabe \"{0}\" mit Workflow \"{1}\" ist fehlgeschlagen: {2}" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:110 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:144 msgid "Tenant Id" msgstr "Tenant Id" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:81 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:115 msgid "The Stack requires the following parameters" msgstr "Der Stack erfordert die folgenden Parameter" @@ -503,7 +503,7 @@ msgstr "Der Stack erfordert die folgenden Parameter" msgid "There's no account configured for this workspace." msgstr "Für diesen Arbeitsbereich ist kein Konto konfiguriert." -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:59 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:93 msgid "This will deploy a CloudFormation stack that creates a new IAM role in your AWS account. This role will be used by FIX to perform security scans in your AWS account." msgstr "Hiermit wird ein CloudFormation-Stack bereitgestellt, der eine neue IAM Rolle in Ihrem AWS Konto erstellt. Diese Rolle wird von FIX verwendet, um in Ihrem AWS Konto Sicherheitsscans durchzuführen." @@ -524,7 +524,7 @@ msgstr "Die fünf wichtigsten Sicherheitsverbesserungen" msgid "Top Non-Compliant Resources" msgstr "Top Ressourcen mit Compliance-Verstößen" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:97 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:132 msgid "True" msgstr "WAHR" @@ -532,7 +532,7 @@ msgstr "WAHR" msgid "Try again" msgstr "Versuchen Sie es erneut" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:129 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:164 #: src/pages/panel/inventory/utils/getAutoCompleteFromKey.tsx:118 msgid "Value" msgstr "Wert" diff --git a/src/locales/en-US/messages.po b/src/locales/en-US/messages.po index c30afcce..f81bc204 100644 --- a/src/locales/en-US/messages.po +++ b/src/locales/en-US/messages.po @@ -81,11 +81,11 @@ msgstr "Age" msgid "Already have an account? Click here to Log in." msgstr "Already have an account? Click here to Log in." -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:73 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:107 msgid "Alternatively if you would like to deploy the stack manually, you can use the following CloudFormation template" msgstr "Alternatively if you would like to deploy the stack manually, you can use the following CloudFormation template" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:68 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:102 msgid "Alternatively: Manual Cloud Setup" msgstr "Alternatively: Manual Cloud Setup" @@ -97,7 +97,7 @@ msgstr "and" msgid "Are you sure?" msgstr "Are you sure?" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:35 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:45 msgid "Automatic Cloud Setup" msgstr "Automatic Cloud Setup" @@ -180,11 +180,11 @@ msgstr "Critical" msgid "Dashboard" msgstr "Dashboard" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:116 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:151 msgid "Date Picker" msgstr "Date Picker" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:108 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:143 msgid "Date Time Picker" msgstr "Date Time Picker" @@ -196,7 +196,7 @@ msgid "Delete" msgstr "Delete" #: src/pages/panel/setup-cloud/SetupCloudButton.tsx:15 -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:49 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:83 msgid "Deploy Stack" msgstr "Deploy Stack" @@ -230,7 +230,7 @@ msgstr "Enabled" msgid "Events" msgstr "Events" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:92 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:126 msgid "External Id" msgstr "External Id" @@ -238,7 +238,7 @@ msgstr "External Id" #~ msgid "Failed Checks" #~ msgstr "Failed Checks" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:100 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:135 msgid "False" msgstr "False" @@ -279,12 +279,12 @@ msgstr "ID" msgid "Improved" msgstr "Improved" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:38 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:48 msgid "In the next step we are going to set up the trust between FIX and your AWS cloud account." msgstr "In the next step we are going to set up the trust between FIX and your AWS cloud account." #: src/pages/panel/inventory/InventoryFormFilterRowProperty.tsx:282 -#: src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx:159 +#: src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx:193 msgid "Invalid Value" msgstr "Invalid Value" @@ -300,7 +300,7 @@ msgstr "Inventory" msgid "Kind" msgstr "Kind" -#: src/pages/panel/inventory/InventoryForm.tsx:213 +#: src/pages/panel/inventory/InventoryForm.tsx:212 msgid "Kinds" msgstr "Kinds" @@ -321,7 +321,7 @@ msgstr "Logout" msgid "Low" msgstr "Low" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:41 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:51 msgid "Make sure that you are already logged into the correct AWS account, before pressing the DEPLOY STACK button." msgstr "Make sure that you are already logged into the correct AWS account, before pressing the DEPLOY STACK button." @@ -368,11 +368,11 @@ msgstr "Note: You are about to delete a management or delegated admin account. P msgid "Nothing to show yet" msgstr "Nothing to show yet" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:94 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:129 msgid "Null" msgstr "Null" -#: src/pages/panel/inventory/InventoryAdvanceSearch.tsx:133 +#: src/pages/panel/inventory/InventoryAdvanceSearch.tsx:109 msgid "Oops! It looks like your query didn't match our format. Please check and try again." msgstr "Oops! It looks like your query didn't match our format. Please check and try again." @@ -491,11 +491,11 @@ msgstr "Tags" #~ msgid "Task \"{0}\" with workflow \"{1}\" failed: {2}" #~ msgstr "Task \"{0}\" with workflow \"{1}\" failed: {2}" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:110 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:144 msgid "Tenant Id" msgstr "Tenant Id" -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:81 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:115 msgid "The Stack requires the following parameters" msgstr "The Stack requires the following parameters" @@ -503,7 +503,7 @@ msgstr "The Stack requires the following parameters" msgid "There's no account configured for this workspace." msgstr "There's no account configured for this workspace." -#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:59 +#: src/pages/panel/setup-cloud/SetupCloudPage.tsx:93 msgid "This will deploy a CloudFormation stack that creates a new IAM role in your AWS account. This role will be used by FIX to perform security scans in your AWS account." msgstr "This will deploy a CloudFormation stack that creates a new IAM role in your AWS account. This role will be used by FIX to perform security scans in your AWS account." @@ -524,7 +524,7 @@ msgstr "Top 5 Security Enhancements" msgid "Top Non-Compliant Resources" msgstr "Top Non-Compliant Resources" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:97 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:132 msgid "True" msgstr "True" @@ -532,7 +532,7 @@ msgstr "True" msgid "Try again" msgstr "Try again" -#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:129 +#: src/pages/panel/inventory/InventoryFormFilterRowValues.tsx:164 #: src/pages/panel/inventory/utils/getAutoCompleteFromKey.tsx:118 msgid "Value" msgstr "Value" diff --git a/src/pages/panel/inventory/InventoryAdvanceSearch.tsx b/src/pages/panel/inventory/InventoryAdvanceSearch.tsx index 8ed5c581..81446437 100644 --- a/src/pages/panel/inventory/InventoryAdvanceSearch.tsx +++ b/src/pages/panel/inventory/InventoryAdvanceSearch.tsx @@ -4,22 +4,12 @@ import SearchIcon from '@mui/icons-material/Search' import { Box, Collapse, Divider, FormHelperText, IconButton, TextField, Typography, styled } from '@mui/material' import { ChangeEvent, Suspense, useCallback, useEffect, useRef, useState } from 'react' import { useSearchParams } from 'react-router-dom' -import { OPType, stringSimpleTypes } from 'src/pages/panel/shared/constants' import { panelUI } from 'src/shared/constants' import { ErrorBoundaryFallback, NetworkErrorBoundary } from 'src/shared/error-boundary-fallback' -import { ResourceComplexKindSimpleTypeDefinitions } from 'src/shared/types/server' import { shouldForwardProp } from 'src/shared/utils/shouldForwardProp' import { InventoryForm } from './InventoryForm' import { InventoryFormsSkeleton } from './InventoryForms.skeleton' -import { getArrayFromInOP } from './utils' - -export interface InventoryAdvanceSearchConfig { - id: number - property: string | null - op: OPType | null - value: string | null - fqn: ResourceComplexKindSimpleTypeDefinitions | null -} +import { InventoryAdvanceSearchConfig, inventoryAdvanceSearchConfigToString } from './utils' interface InventoryAdvanceSearchProps { value: string @@ -76,21 +66,7 @@ export const InventoryAdvanceSearch = ({ value: searchCrit, onChange, hasError } useEffect(() => { if (initializedRef.current) { const configJoined = config - .map((item) => { - if (typeof item === 'string' || !item) { - return item - } - if (item.property && item.op && item.value && item.fqn) { - const value = - stringSimpleTypes.includes(item.fqn as (typeof stringSimpleTypes)[number]) && item.value !== 'null' - ? item.op === 'in' || item.op === 'not in' - ? JSON.stringify(getArrayFromInOP(item.value, true)) - : `"${item.value}"` - : item.value - return `${item.property} ${item.op} ${value}` - } - return null - }) + .map(inventoryAdvanceSearchConfigToString) .filter((filter) => filter) .join(' and ') const result = (kind ? `is(${kind})${configJoined ? ' and ' : ''}` : '') + configJoined diff --git a/src/pages/panel/inventory/InventoryForm.tsx b/src/pages/panel/inventory/InventoryForm.tsx index 3f582993..990c59ea 100644 --- a/src/pages/panel/inventory/InventoryForm.tsx +++ b/src/pages/panel/inventory/InventoryForm.tsx @@ -7,10 +7,9 @@ import { DefaultPropertiesKeys } from 'src/pages/panel/shared/constants' import { getWorkspaceInventorySearchStartQuery } from 'src/pages/panel/shared/queries' import { isValidProp } from 'src/pages/panel/shared/utils' import { ErrorBoundaryFallback, NetworkErrorBoundary } from 'src/shared/error-boundary-fallback' -import { InventoryAdvanceSearchConfig } from './InventoryAdvanceSearch' import { InventoryFormFilterRow } from './InventoryFormFilterRow' import { InventoryFormTemplateObject, InventoryFormTemplates } from './InventoryFormTemplates' -import { getArrayFromInOP } from './utils' +import { InventoryAdvanceSearchConfig, getArrayFromInOP } from './utils' interface InventoryFormProps { setConfig: Dispatch> diff --git a/src/pages/panel/inventory/InventoryFormFilterRow.tsx b/src/pages/panel/inventory/InventoryFormFilterRow.tsx index cb0e92ec..7b3e2e39 100644 --- a/src/pages/panel/inventory/InventoryFormFilterRow.tsx +++ b/src/pages/panel/inventory/InventoryFormFilterRow.tsx @@ -13,10 +13,9 @@ import { stringOPTypes, } from 'src/pages/panel/shared/constants' import { ResourceComplexKindSimpleTypeDefinitions } from 'src/shared/types/server' -import { InventoryAdvanceSearchConfig } from './InventoryAdvanceSearch' import { InventoryFormFilterRowProperty } from './InventoryFormFilterRowProperty' import { InventoryFormFilterRowValues } from './InventoryFormFilterRowValues' -import { AutoCompletePreDefinedItems, getArrayFromInOP } from './utils' +import { AutoCompletePreDefinedItems, InventoryAdvanceSearchConfig, getArrayFromInOP } from './utils' interface InventoryFormFilterRowProps { item: InventoryAdvanceSearchConfig diff --git a/src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx b/src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx index 2e77a9bf..3178ab44 100644 --- a/src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx +++ b/src/pages/panel/inventory/InventoryFormFilterRowStringValue.tsx @@ -1,7 +1,7 @@ import { t } from '@lingui/macro' import { Autocomplete, AutocompleteProps, CircularProgress, TextField, TypographyProps } from '@mui/material' import { useInfiniteQuery } from '@tanstack/react-query' -import { ChangeEvent, ReactNode, UIEvent as ReactUIEvent, useMemo, useState } from 'react' +import { ChangeEvent, ReactNode, UIEvent as ReactUIEvent, useMemo, useRef, useState } from 'react' import { useUserProfile } from 'src/core/auth' import { getWorkspaceInventoryPropertyValuesQuery } from 'src/pages/panel/shared/queries' import { panelUI } from 'src/shared/constants' @@ -37,6 +37,7 @@ export function InventoryFormFilterRowStringValue i.label === typed) : value.label !== typed)) + ? `${searchCrit} and ${propertyName} ~ ".*${typed}.*"` + : searchCrit, propertyName, ] as const, initialPageParam: { @@ -112,7 +117,9 @@ export function InventoryFormFilterRowStringValue { - setTyped(typeof option === 'string' ? option : !Array.isArray(option) ? option?.label ?? '' : '') + const newTyped = typeof option === 'string' ? option : !Array.isArray(option) ? option?.label ?? '' : '' + setTyped(newTyped) + slectedTyped.current = newTyped const newOption = (typeof option === 'string' ? options.find((i) => i.label === option) @@ -121,6 +128,9 @@ export function InventoryFormFilterRowStringValue (typeof i === 'string' ? options.find((j) => j.label === i) : i)) .filter((i) => i) as AutoCompleteValue[]) : option) || null + if (!Array.isArray(option)) { + setHasFocus(false) + } onChange( (props.multiple ? Array.isArray(newOption) @@ -133,10 +143,12 @@ export function InventoryFormFilterRowStringValue option.value === value.value} ListboxComponent={ListboxComponent} ListboxProps={{ onScroll: handleScroll, }} + loading={isLoading} options={options} filterOptions={ networkDisabled @@ -159,6 +171,7 @@ export function InventoryFormFilterRowStringValue i.label === e.currentTarget.innerText) if (found) { + slectedTyped.current = e.currentTarget.innerText onChange(found as typeof value) } } @@ -179,6 +192,7 @@ export function InventoryFormFilterRowStringValue setHasFocus(true), @@ -186,6 +200,7 @@ export function InventoryFormFilterRowStringValue i.label === typed) if (found) { + slectedTyped.current = typed onChange(found as typeof value) } } @@ -202,7 +217,9 @@ export function InventoryFormFilterRowStringValue ), }} + onClick={() => setHasFocus(true)} onChange={(e) => { + slectedTyped.current = '' if (isNumber) { const curValue = e.currentTarget.value const num = Number(curValue) diff --git a/src/pages/panel/inventory/InventoryFormFilterRowValues.tsx b/src/pages/panel/inventory/InventoryFormFilterRowValues.tsx index b82dd471..4f7c73f1 100644 --- a/src/pages/panel/inventory/InventoryFormFilterRowValues.tsx +++ b/src/pages/panel/inventory/InventoryFormFilterRowValues.tsx @@ -2,17 +2,19 @@ import { Trans } from '@lingui/macro' import { MenuItem, Select, TextField } from '@mui/material' import { DatePicker, DateTimePicker } from '@mui/x-date-pickers' import dayjs from 'dayjs' +import { useRef } from 'react' import { OPType } from 'src/pages/panel/shared/constants' import { DurationPicker } from 'src/shared/duration-picker' import { ResourceComplexKindSimpleTypeDefinitions } from 'src/shared/types/server' -import { InventoryAdvanceSearchConfig } from './InventoryAdvanceSearch' import { InventoryFormFilterRowStringValue } from './InventoryFormFilterRowStringValue' import { AutoCompletePreDefinedItems, + InventoryAdvanceSearchConfig, getArrayFromInOP, getAutoCompletePropsFromKey, getAutocompleteDataFromKey, getAutocompleteValueFromKey, + inventoryAdvanceSearchConfigToString, } from './utils' interface InventoryFormFilterRowValuesProps { @@ -28,6 +30,16 @@ interface InventoryFormFilterRowValuesProps { + let crit = currentSearchCrit ? searchCrit.replace(currentSearchCrit, '').replace('and and', 'and') || 'all' : searchCrit + if (crit.endsWith(' and ')) { + crit = crit.substring(0, crit.length - 5) + } else if (crit.startsWith(' and ')) { + crit = crit.substring(5) + } + return crit +} + export function InventoryFormFilterRowValues({ data, hasDefaultProperties, @@ -35,9 +47,32 @@ export function InventoryFormFilterRowValues) { + const prev = useRef([data, searchCrit] as const) + const { + current: [prevData, prevSearchCrit], + } = prev const multiple = data.op === 'in' || data.op === 'not in' const currentValue = (data.value?.[0] === '[' ? getArrayFromInOP(data.value) : data.value) || (multiple ? ([] as string[]) : null) + let dataToProcess = data + + if ( + prevData.fqn === data.fqn && + prevData.id === data.id && + prevData.op === data.op && + prevData.property === data.property && + prevData.value !== data.value && + prevSearchCrit === searchCrit + ) { + dataToProcess = prevData + } else { + prev.current = [data, searchCrit] + } + + const currentSearchCrit = inventoryAdvanceSearchConfigToString(dataToProcess) + + const crit = removeCurrectSearchCrit(currentSearchCrit, searchCrit) + let isDouble = false let isNumber = false switch (data.fqn) { @@ -75,7 +110,7 @@ export function InventoryFormFilterRowValues ({ label: value, value }))) || null } defaultOptions={hasDefaultProperties ? getAutocompleteDataFromKey(data.property || '', preItems) : undefined} - searchCrit={searchCrit} + searchCrit={crit} propertyName={data.property || ''} autoFocus={!data.value} {...(hasDefaultProperties ? getAutoCompletePropsFromKey(data.property || '') : {})} diff --git a/src/pages/panel/inventory/utils/index.ts b/src/pages/panel/inventory/utils/index.ts index e7e3bef2..e296275e 100644 --- a/src/pages/panel/inventory/utils/index.ts +++ b/src/pages/panel/inventory/utils/index.ts @@ -2,4 +2,6 @@ export { getArrayFromInOP } from './getArrayFromInOP' export { getAutoCompletePropsFromKey, getAutocompleteDataFromKey, getAutocompleteValueFromKey } from './getAutoCompleteFromKey' export type { AutoCompletePreDefinedItems } from './getAutoCompleteFromKey' export { getCustomedWorkspaceInventoryPropertyAttributesQuery } from './getCustomedWorkspaceInventoryPropertyAttributes.query' +export { inventoryAdvanceSearchConfigToString } from './inventoryAdvanceSearchConfigToString' +export type { InventoryAdvanceSearchConfig } from './inventoryAdvanceSearchConfigToString' export { rowStrFromColumnKind } from './rowStrFromColumnKind' diff --git a/src/pages/panel/inventory/utils/inventoryAdvanceSearchConfigToString.ts b/src/pages/panel/inventory/utils/inventoryAdvanceSearchConfigToString.ts new file mode 100644 index 00000000..2adb5aca --- /dev/null +++ b/src/pages/panel/inventory/utils/inventoryAdvanceSearchConfigToString.ts @@ -0,0 +1,27 @@ +import { OPType, stringSimpleTypes } from 'src/pages/panel/shared/constants' +import { ResourceComplexKindSimpleTypeDefinitions } from 'src/shared/types/server' +import { getArrayFromInOP } from './getArrayFromInOP' + +export interface InventoryAdvanceSearchConfig { + id: number + property: string | null + op: OPType | null + value: string | null + fqn: ResourceComplexKindSimpleTypeDefinitions | null +} + +export const inventoryAdvanceSearchConfigToString = (config: InventoryAdvanceSearchConfig | string | null) => { + if (typeof config === 'string' || !config) { + return config + } + if (config.property && config.op && config.value && config.fqn) { + const value = + stringSimpleTypes.includes(config.fqn as (typeof stringSimpleTypes)[number]) && config.value !== 'null' + ? config.op === 'in' || config.op === 'not in' + ? JSON.stringify(getArrayFromInOP(config.value, true)) + : `"${config.value}"` + : config.value + return `${config.property} ${config.op} ${value}` + } + return null +}