mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-31 01:16:01 +02:00
chore: suggest nested properties in action filters (#6533)
https://linear.app/unleash/issue/2-2029/support-filtering-on-nested-properties Suggests nested properties in action filters. Also sorts them alphabetically. Follow up to https://github.com/Unleash/unleash/pull/6531 <img width="381" alt="image" src="https://github.com/Unleash/unleash/assets/14320932/4e2c900d-335b-4360-8be4-186f3887e42b">
This commit is contained in:
parent
f7062e2296
commit
bc6a96cf6b
@ -13,6 +13,7 @@ import Add from '@mui/icons-material/Add';
|
|||||||
import { ProjectActionsPreviewPayload } from './ProjectActionsPreviewPayload';
|
import { ProjectActionsPreviewPayload } from './ProjectActionsPreviewPayload';
|
||||||
import { useSignalEndpointSignals } from 'hooks/api/getters/useSignalEndpointSignals/useSignalEndpointSignals';
|
import { useSignalEndpointSignals } from 'hooks/api/getters/useSignalEndpointSignals/useSignalEndpointSignals';
|
||||||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
||||||
|
import { flattenPayload } from '@server/util/flattenPayload';
|
||||||
|
|
||||||
const StyledDivider = styled(Divider)(({ theme }) => ({
|
const StyledDivider = styled(Divider)(({ theme }) => ({
|
||||||
margin: theme.spacing(2, 0),
|
margin: theme.spacing(2, 0),
|
||||||
@ -86,7 +87,9 @@ export const ProjectActionsFormStepSource = ({
|
|||||||
const lastSourcePayload = signalEndpointSignals[0]?.payload;
|
const lastSourcePayload = signalEndpointSignals[0]?.payload;
|
||||||
return {
|
return {
|
||||||
lastSourcePayload,
|
lastSourcePayload,
|
||||||
filterSuggestions: Object.keys(lastSourcePayload || {}),
|
filterSuggestions: Object.keys(
|
||||||
|
flattenPayload(lastSourcePayload) || {},
|
||||||
|
).sort(),
|
||||||
};
|
};
|
||||||
}, [signalEndpointSignals]);
|
}, [signalEndpointSignals]);
|
||||||
|
|
||||||
|
@ -1,32 +1,38 @@
|
|||||||
export const flattenPayload = (
|
export const flattenPayload = (
|
||||||
payload = {},
|
payload: Record<string, unknown> = {},
|
||||||
parentKey = '',
|
parentKey = '',
|
||||||
): Record<string, unknown> =>
|
): Record<string, unknown> =>
|
||||||
Object.entries(payload).reduce((acc, [key, value]) => {
|
Object.entries(payload).reduce(
|
||||||
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
(acc, [key, value]) => {
|
||||||
|
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
typeof value === 'object' &&
|
typeof value === 'object' &&
|
||||||
value !== null &&
|
value !== null &&
|
||||||
!Array.isArray(value)
|
!Array.isArray(value)
|
||||||
) {
|
) {
|
||||||
// If it's an object, recurse and merge the results
|
// If it's an object, recurse and merge the results
|
||||||
Object.assign(acc, flattenPayload(value, newKey));
|
Object.assign(
|
||||||
} else if (Array.isArray(value)) {
|
acc,
|
||||||
// If it's an array, map through it and handle objects and non-objects differently
|
flattenPayload(value as Record<string, unknown>, newKey),
|
||||||
value.forEach((item, index) => {
|
);
|
||||||
if (typeof item === 'object' && item !== null) {
|
} else if (Array.isArray(value)) {
|
||||||
Object.assign(
|
// If it's an array, map through it and handle objects and non-objects differently
|
||||||
acc,
|
value.forEach((item, index) => {
|
||||||
flattenPayload(item, `${newKey}[${index}]`),
|
if (typeof item === 'object' && item !== null) {
|
||||||
);
|
Object.assign(
|
||||||
} else {
|
acc,
|
||||||
acc[`${newKey}[${index}]`] = item;
|
flattenPayload(item, `${newKey}[${index}]`),
|
||||||
}
|
);
|
||||||
});
|
} else {
|
||||||
} else {
|
acc[`${newKey}[${index}]`] = item;
|
||||||
acc[newKey] = value;
|
}
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
acc[newKey] = value;
|
||||||
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {});
|
},
|
||||||
|
{} as Record<string, unknown>,
|
||||||
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user