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

feat: better columns display for related charts #239

Merged
merged 6 commits into from
May 18, 2024
Merged

feat: better columns display for related charts #239

merged 6 commits into from
May 18, 2024

Conversation

duyet
Copy link
Owner

@duyet duyet commented May 18, 2024

No description provided.

Copy link

vercel bot commented May 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clickhouse-monitoring ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 18, 2024 3:52pm

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @duyet - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 9 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

@@ -18,13 +18,16 @@ export async function RelatedCharts({
className,
}: RelatedChartsProps) {
// Related charts
const charts: [ComponentType<ChartProps>, ChartProps][] = []
type ChartName = string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a more descriptive type name.

The type alias ChartName could be more descriptive to improve readability. For example, ChartComponentName might be clearer.

Suggested change
type ChartName = string
type ChartComponentName = string

components/related-charts.tsx Outdated Show resolved Hide resolved
</ServerComponentLazy>
))}
{charts.map(([_name, Chart, props], i) => {
let className = ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a more descriptive variable name.

The variable className could be more descriptive, such as chartClassName, to better convey its purpose.

Suggested change
let className = ''
let chartClassName = ''

// | chart1 |
// | chart2 | chart3 |
// -----------------------
if (charts[i + 1] && charts[i + 1][0] === 'break') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider extracting logic to a helper function.

The logic for determining the className could be extracted to a helper function to improve readability and maintainability.

Suggested change
if (charts[i + 1] && charts[i + 1][0] === 'break') {
const shouldSpanTwoColumns = (charts, index) => charts[index + 1] && charts[index + 1][0] === 'break';
if (shouldSpanTwoColumns(charts, i)) {
className = 'col-span-2';
}

// | chart1 | chart2 |
// | chart3 |
// -----------------------
if (charts.length > 2 && i === charts.length - 1 && col === 2) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Clarify the TODO comment.

The TODO comment mentions implementing for maxChartsPerRow > 2. Consider adding more details or creating a task to ensure this is addressed.

@@ -21,6 +21,9 @@ interface ReloadButtonProps {
className?: string
}

const SECOND = 1000
const MINUTE = 60 * SECOND
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Consider using a more descriptive constant name.

The constant MINUTE could be renamed to MILLISECONDS_IN_MINUTE for better clarity.

Suggested change
const MINUTE = 60 * SECOND
const MILLISECONDS_IN_MINUTE = 60 * SECOND

relatedCharts?:
| string[]
| [string, ChartProps][]
| (string | [string, ChartProps])[]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Clarify the new type definition.

The new type definition for relatedCharts is more complex. Consider adding a comment to explain the different possible structures for better readability.

Suggested change
| (string | [string, ChartProps])[]
// relatedCharts can be:
// 1. An array of strings
// 2. An array of tuples, where each tuple contains a string and ChartProps
// 3. An array containing both strings and tuples
| (string | [string, ChartProps])[]

components/charts/break.tsx Show resolved Hide resolved
props = {}
props: ChartProps = {}

if (!chart) continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!chart) continue
if (!chart) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

@@ -33,24 +36,53 @@ export async function RelatedCharts({
props = chart[1]
}

if (!component) continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (!component) continue
if (!component) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Signed-off-by: Duyet Le <5009534+duyet@users.noreply.github.com>
duyet and others added 2 commits May 18, 2024 22:50
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Signed-off-by: Duyet Le <5009534+duyet@users.noreply.github.com>
@duyet duyet merged commit c734d9e into main May 18, 2024
10 checks passed
@duyet duyet deleted the chore/ui branch May 18, 2024 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant