-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix D&D resource display names #5498
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
924742e
rewrite getResourceName
jpople ae796af
update changelog
jpople b29c8af
regenerate types
jpople 91dbbe6
update to use top_level_field_urn
jpople 561e1b0
add tests
jpople bd23678
Merge branch 'main' into jpople/hj-162/nested-field-display-names
jpople 3ca7ec5
add one additional test case
jpople File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 36 additions & 11 deletions
47
clients/admin-ui/src/features/data-discovery-and-detection/utils/getResourceName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,22 +1,47 @@ | ||||||||
import { DiscoveryMonitorItem } from "~/features/data-discovery-and-detection/types/DiscoveryMonitorItem"; | ||||||||
|
||||||||
const TOP_LEVEL_FIELD_URN_PARTS = 5; | ||||||||
const MAX_NON_NESTED_URN_LENGTH = 5; | ||||||||
const URN_SEPARATOR = "."; | ||||||||
/** | ||||||||
* Helper method for deriving a resource's display name from its URN | ||||||||
*/ | ||||||||
const getResourceName = ({ | ||||||||
name, | ||||||||
urn, | ||||||||
monitor_config_id, | ||||||||
database_name, | ||||||||
schema_name, | ||||||||
table_name, | ||||||||
top_level_field_name, | ||||||||
}: DiscoveryMonitorItem) => { | ||||||||
const splitUrn = urn.split(URN_SEPARATOR); | ||||||||
|
||||||||
const getResourceName = (resource: DiscoveryMonitorItem) => { | ||||||||
const URN_SEPARATOR = "."; | ||||||||
const splitUrn = resource.urn.split(URN_SEPARATOR); | ||||||||
if ( | ||||||||
!resource.parent_table_urn || | ||||||||
splitUrn.length === TOP_LEVEL_FIELD_URN_PARTS | ||||||||
!table_name || | ||||||||
!top_level_field_name || | ||||||||
splitUrn.length < MAX_NON_NESTED_URN_LENGTH | ||||||||
) { | ||||||||
// use name as-is if it's not a subfield | ||||||||
return resource.name; | ||||||||
return name; | ||||||||
} | ||||||||
// TODO HJ-162: better handle case where field name contains "." | ||||||||
// URN format is "monitor.project?.dataset.table.field.[any number of subfields]" | ||||||||
// we want to show all subfield names separated by "." | ||||||||
const partsToRemove = [ | ||||||||
monitor_config_id, | ||||||||
database_name, | ||||||||
schema_name, | ||||||||
table_name, | ||||||||
top_level_field_name, | ||||||||
]; | ||||||||
|
||||||||
// URN format is "monitor.project.dataset.field.[any number of subfields]" | ||||||||
// for a subfield, we want to show all subfield names separated by "." | ||||||||
return splitUrn.slice(TOP_LEVEL_FIELD_URN_PARTS).join(URN_SEPARATOR); | ||||||||
partsToRemove.forEach((part) => { | ||||||||
const index = splitUrn.indexOf(part!); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nitpicky: I would feel more comfortable with this if it were wrapped in an
Suggested change
Take this example:
returns |
||||||||
if (index > -1) { | ||||||||
splitUrn.splice(index, 1); | ||||||||
} | ||||||||
}); | ||||||||
|
||||||||
return splitUrn.join(URN_SEPARATOR); | ||||||||
}; | ||||||||
|
||||||||
export default getResourceName; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it would be helpful I am adding in
top_level_field_urn
as well in this PR: https://github.com/ethyca/fidesplus/pull/1727/files#diff-8bd50e59212bea55bbd599dd3564999eecbda0c718c2681318bbc990a29d28c9R354not sure if it's actually better or the same as
top_level_field_name
but I figured better to give as much info as possible now and then we can remove one later if it's not helpfulThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine
top_level_field_name
to be maybe a little tricky in structures likeetc etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for flagging-- yeah, that'll make this much cleaner if I can just elide that.