Skip to content
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

User metadata on one line #3284

Merged
merged 18 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions catalog/app/containers/Bucket/PackageList/PackageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,30 @@ interface RevisionMetaProps {

function RevisionMeta({ revision }: RevisionMetaProps) {
const classes = useRevisionMetaStyles()
const { preferences } = BucketPreferences.use()
return (
<div className={classes.root}>
{!!revision.message && <div className={classes.section}>{revision.message}</div>}
{!!revision.userMeta && (
<div className={classes.section}>
{Object.entries(revision.userMeta).map(([name, value]) => (
/* @ts-expect-error */
{preferences?.ui.packageDescription.userMetaMultiline ? (
Object.entries(revision.userMeta).map(([name, value]) => (
// @ts-expect-error
<JsonDisplay
className={cx({ [classes.sectionWithToggle]: typeof value === 'object' })}
key={`user-meta-section-${name}`}
name={name}
value={value}
/>
))
) : (
// @ts-expect-error
<JsonDisplay
className={cx({ [classes.sectionWithToggle]: typeof value === 'object' })}
key={`user-meta-section-${name}`}
name={name}
value={value}
className={classes.sectionWithToggle}
name="User metadata"
value={revision.userMeta}
/>
))}
)}
</div>
)}
</div>
Expand All @@ -259,9 +269,9 @@ function usePackageDescription(
): BucketPreferences.PackagePreferences | null {
const { preferences } = BucketPreferences.use()
return React.useMemo(() => {
if (!preferences?.ui.package_description) return null
if (!preferences?.ui.packageDescription.packages) return null
return (
Object.entries(preferences?.ui.package_description)
Object.entries(preferences?.ui.packageDescription.packages)
.reverse() // The last found config wins
.find(([nameRegex]) => new RegExp(nameRegex).test(name))?.[1] || {}
)
Expand Down
9 changes: 6 additions & 3 deletions catalog/app/utils/BucketPreferences/BucketPreferences.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ const expectedDefaults = {
packages: true,
queries: true,
},
package_description: {
'.*': {
message: true,
packageDescription: {
packages: {
'.*': {
message: true,
},
},
userMetaMultiline: false,
},
sourceBuckets: {
list: [],
Expand Down
50 changes: 35 additions & 15 deletions catalog/app/utils/BucketPreferences/BucketPreferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ export interface PackagePreferences {
userMeta?: ReadonlyArray<string>
}
type PackagesListPreferencesInput = Record<string, PackagePreferencesInput>
type PackagesListPreferences = Record<string, PackagePreferences>
interface PackagesListPreferences {
packages: Record<string, PackagePreferences>
userMetaMultiline: boolean
}

type DefaultSourceBucketInput = string
type PackageDescriptionMultiline = boolean
type SourceBucketsInput = Record<string, null>

export interface AthenaPreferencesInput {
Expand All @@ -77,6 +81,7 @@ interface UiPreferencesInput {
defaultSourceBucket?: DefaultSourceBucketInput
nav?: Partial<NavPreferences>
package_description?: PackagesListPreferencesInput
package_description_multiline?: PackageDescriptionMultiline
sourceBuckets?: SourceBucketsInput
}

Expand All @@ -94,7 +99,7 @@ interface UiPreferences {
athena: AthenaPreferences
blocks: BlocksPreferences
nav: NavPreferences
package_description: PackagesListPreferences
packageDescription: PackagesListPreferences
sourceBuckets: SourceBuckets
}

Expand Down Expand Up @@ -132,10 +137,13 @@ const defaultPreferences: BucketPreferences = {
packages: true,
queries: true,
},
package_description: {
'.*': {
message: true,
packageDescription: {
packages: {
'.*': {
message: true,
},
},
userMetaMultiline: false,
},
sourceBuckets: {
getDefault: () => '',
Expand Down Expand Up @@ -186,16 +194,25 @@ function parseBlocks(blocks?: BlocksPreferencesInput): BlocksPreferences {
}
}

function parsePackages(packages?: PackagesListPreferencesInput): PackagesListPreferences {
function parsePackages(
packages?: PackagesListPreferencesInput,
userMetaMultiline: boolean = false,
): PackagesListPreferences {
return Object.entries(packages || {}).reduce(
(memo, [name, { message, user_meta }]) => ({
...memo,
[name]: {
message,
userMeta: user_meta,
},
}),
defaultPreferences.ui.package_description,
(memo, [name, { message, user_meta }]) =>
R.assocPath(
['packages', name],
{
message,
userMeta: user_meta,
},
memo,
),
{
packages: defaultPreferences.ui.packageDescription.packages,
userMetaMultiline:
userMetaMultiline || defaultPreferences.ui.packageDescription.userMetaMultiline,
},
)
}

Expand Down Expand Up @@ -232,7 +249,10 @@ export function extendDefaults(
...R.mergeDeepRight(defaultPreferences.ui, data?.ui || {}),
athena: parseAthena(data?.ui?.athena),
blocks: parseBlocks(data?.ui?.blocks),
package_description: parsePackages(data?.ui?.package_description),
packageDescription: parsePackages(
data?.ui?.package_description,
data?.ui?.package_description_multiline,
),
sourceBuckets: parseSourceBuckets(
sentry,
data?.ui?.sourceBuckets,
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Entries inside each section should be ordered by type:
* [Changed] Show collapsed values in JSON viewer ([#3249](https://github.com/quiltdata/quilt/pull/3249))
* [Changed] Rename "Metadata" to "User metadata" ([#3255](https://github.com/quiltdata/quilt/pull/3255))
* [Changed] Show selective metadata for packages as JSON ([#3259](https://github.com/quiltdata/quilt/pull/3259))
* [Changed] Show selective metadata on one line and optionaly on multiple lines ([#3284](https://github.com/quiltdata/quilt/pull/3284))

# 5.1.0 - 2022-12-09
## Python API
Expand Down
2 changes: 2 additions & 0 deletions docs/Catalog/Preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ ui:
package_description:
.*:
message: True
package_description_multiline: False
```

### Properties
Expand Down Expand Up @@ -62,6 +63,7 @@ that is selected by default; if it doesn't match any bucket then it's ignored
that maps package handle regular expressions
or literals to JSONPath expressions of fields to show from package metadata
in the package list view.
* `ui.package_description_multiline: True` - expands package metadata's root key/values
* `ui.athena.defaultWorkgroup` - default workgroup to select on the Athena page

#### `ui.sourceBuckets` example
Expand Down
Binary file modified docs/imgs/package-list-selective-metadata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions shared/schemas/bucketConfig.yml.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@
}
]
},
"package_description_multiline": {
"type": "boolean",
"description": "Expands package metadata's root key/values",
"default": false
},
"sourceBuckets": {
"type": "object",
"description": "Buckets usable as sources for adding objects from while editing a package via web UI.",
Expand Down