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

fix: move slack channel to top of table description #1446

Merged
merged 14 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
} from 'const/metastore';
import { useMounted } from 'hooks/useMounted';
import { Nullable } from 'lib/typescript';
import { titleize } from 'lib/utils';
import { isValidUrl, titleize } from 'lib/utils';
import { generateFormattedDate } from 'lib/utils/datetime';
import { getAppName } from 'lib/utils/global';
import { getHumanReadableByteSize } from 'lib/utils/number';
Expand All @@ -34,6 +34,7 @@
import { SoftButton, TextButton } from 'ui/Button/Button';
import { EditableTextField } from 'ui/EditableTextField/EditableTextField';
import { KeyContentDisplay } from 'ui/KeyContentDisplay/KeyContentDisplay';
import { KeyContentDisplayLink } from 'ui/KeyContentDisplay/KeyContentDisplayLink';
import { Link } from 'ui/Link/Link';
import { LoadingRow } from 'ui/Loading/Loading';
import { Message } from 'ui/Message/Message';
Expand All @@ -56,6 +57,11 @@
'column_count',
];

/**
* Any custom properties in this array will be shown on top following the order of the array
*/
const pinnedCustomProperties = ['channels'];

function useRefreshMetastore(table: IDataTable) {
const dispatch = useDispatch();
const isMounted = useMounted();
Expand Down Expand Up @@ -151,22 +157,21 @@
);
});

const customPropertiesDOM = Object.entries(
table.custom_properties ?? {}
).map(([key, value]) => {
const valueStr = value?.toString() ?? '';
return (
<KeyContentDisplay key={key} keyString={titleize(key, '_', ' ')}>
{valueStr && /https?:\/\/[^\s]+/.test(valueStr.trim()) ? (
<Link to={valueStr} newTab>
{valueStr}
</Link>
) : (
valueStr
)}
</KeyContentDisplay>
);
});
const customProperties = table.custom_properties ?? {};

// Get pinned custom properties and display based on order of pinnedCustomProperties
const pinnedPropertiesDOM = pinnedCustomProperties
.filter((p) => p in customProperties)
.map((key) => {
const value = customProperties[key];

Check failure on line 166 in querybook/webapp/components/DataTableViewOverview/DataTableViewOverview.tsx

View workflow job for this annotation

GitHub Actions / nodetests

Missing "key" prop for element in iterator
return <KeyContentDisplayLink keyString={key} value={value} />;
});

const otherPropertiesDOM = Object.entries(customProperties)
.filter(([key]) => !pinnedCustomProperties.includes(key))

Check failure on line 171 in querybook/webapp/components/DataTableViewOverview/DataTableViewOverview.tsx

View workflow job for this annotation

GitHub Actions / nodetests

Missing "key" prop for element in iterator
.map(([key, value]) => {
return <KeyContentDisplayLink keyString={key} value={value} />;
});

const rawMetastoreInfoDOM = table.hive_metastore_description ? (
<pre className="raw-metastore-info">
Expand Down Expand Up @@ -209,8 +214,9 @@
);
const detailsSection = (
<DataTableViewOverviewSection title="Details">
{pinnedPropertiesDOM}
{detailsDOM}
{customPropertiesDOM}
{otherPropertiesDOM}
</DataTableViewOverviewSection>
);

Expand Down
27 changes: 27 additions & 0 deletions querybook/webapp/ui/KeyContentDisplay/KeyContentDisplayLink.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';

import { isValidUrl, titleize } from 'lib/utils';
import { Link } from 'ui/Link/Link';

import { KeyContentDisplay } from './KeyContentDisplay';

export const KeyContentDisplayLink: React.FunctionComponent<{
keyString: string;
value: string | number;
}> = ({ keyString, value }) => {
const valueStr = value?.toString() ?? '';
return (
<KeyContentDisplay
key={keyString}
keyString={titleize(keyString, '_', ' ')}
>
{valueStr && isValidUrl(valueStr.trim()) ? (
<Link to={valueStr} newTab>
{valueStr}
</Link>
) : (
valueStr
)}
</KeyContentDisplay>
);
};
Loading