-
Notifications
You must be signed in to change notification settings - Fork 226
Improve grouping of libraries #2524
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a833f78
Sort libraries by supported and usages
koesie10 768c107
Make libraries collapsible
koesie10 32d8968
Use pluralize function for pluralization
koesie10 ddd97f0
Add chevron to show whether row is expanded
koesie10 2800ccb
Add extra sorting parameters for libraries
koesie10 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
125 changes: 125 additions & 0 deletions
125
extensions/ql-vscode/src/view/data-extensions-editor/LibraryRow.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import * as React from "react"; | ||
| import { useCallback, useMemo, useState } from "react"; | ||
| import styled from "styled-components"; | ||
| import { ExternalApiUsage } from "../../data-extensions-editor/external-api-usage"; | ||
| import { ModeledMethod } from "../../data-extensions-editor/modeled-method"; | ||
| import { pluralize } from "../../pure/word"; | ||
| import { ModeledMethodDataGrid } from "./ModeledMethodDataGrid"; | ||
| import { calculateModeledPercentage } from "./modeled"; | ||
| import { decimalFormatter, percentFormatter } from "./formatters"; | ||
| import { Codicon } from "../common"; | ||
|
|
||
| const LibraryContainer = styled.div` | ||
| margin-bottom: 1rem; | ||
| `; | ||
|
|
||
| const TitleContainer = styled.button` | ||
| display: flex; | ||
| gap: 0.5em; | ||
| align-items: center; | ||
| width: 100%; | ||
| font-size: 1.2em; | ||
| font-weight: bold; | ||
|
|
||
| color: var(--vscode-editor-foreground); | ||
| background-color: transparent; | ||
| border: none; | ||
| cursor: pointer; | ||
| `; | ||
|
|
||
| const StatusContainer = styled.div` | ||
| display: flex; | ||
| gap: 1em; | ||
| align-items: center; | ||
|
|
||
| margin-top: 0.5em; | ||
| margin-bottom: 0.5em; | ||
| margin-left: 1em; | ||
| `; | ||
|
|
||
| type Props = { | ||
| libraryName: string; | ||
| externalApiUsages: ExternalApiUsage[]; | ||
| modeledMethods: Record<string, ModeledMethod>; | ||
| onChange: ( | ||
| externalApiUsage: ExternalApiUsage, | ||
| modeledMethod: ModeledMethod, | ||
| ) => void; | ||
| }; | ||
|
|
||
| export const LibraryRow = ({ | ||
| libraryName, | ||
| externalApiUsages, | ||
| modeledMethods, | ||
| onChange, | ||
| }: Props) => { | ||
| const modeledPercentage = useMemo(() => { | ||
| return calculateModeledPercentage(externalApiUsages); | ||
| }, [externalApiUsages]); | ||
|
|
||
| const [isExpanded, setExpanded] = useState(modeledPercentage < 100); | ||
|
|
||
| const toggleExpanded = useCallback(async () => { | ||
| setExpanded((oldIsExpanded) => !oldIsExpanded); | ||
| }, []); | ||
|
|
||
| const usagesCount = useMemo(() => { | ||
| return externalApiUsages.reduce((acc, curr) => acc + curr.usages.length, 0); | ||
| }, [externalApiUsages]); | ||
|
|
||
| return ( | ||
| <LibraryContainer> | ||
| <TitleContainer onClick={toggleExpanded} aria-expanded={isExpanded}> | ||
| {isExpanded ? ( | ||
| <Codicon name="chevron-down" label="Collapse" /> | ||
| ) : ( | ||
| <Codicon name="chevron-right" label="Expand" /> | ||
| )} | ||
| {libraryName} | ||
| {isExpanded ? null : ( | ||
| <> | ||
| {" "} | ||
| ( | ||
| {pluralize( | ||
| externalApiUsages.length, | ||
| "method", | ||
| "methods", | ||
| decimalFormatter.format.bind(decimalFormatter), | ||
| )} | ||
| , {percentFormatter.format(modeledPercentage / 100)} modeled) | ||
| </> | ||
| )} | ||
| </TitleContainer> | ||
| {isExpanded && ( | ||
| <> | ||
| <StatusContainer> | ||
| <div> | ||
| {pluralize( | ||
| externalApiUsages.length, | ||
| "method", | ||
| "methods", | ||
| decimalFormatter.format.bind(decimalFormatter), | ||
| )} | ||
| </div> | ||
| <div> | ||
| {pluralize( | ||
| usagesCount, | ||
| "usage", | ||
| "usages", | ||
| decimalFormatter.format.bind(decimalFormatter), | ||
| )} | ||
| </div> | ||
| <div> | ||
| {percentFormatter.format(modeledPercentage / 100)} modeled | ||
| </div> | ||
| </StatusContainer> | ||
| <ModeledMethodDataGrid | ||
| externalApiUsages={externalApiUsages} | ||
| modeledMethods={modeledMethods} | ||
| onChange={onChange} | ||
| /> | ||
| </> | ||
| )} | ||
| </LibraryContainer> | ||
| ); | ||
| }; |
This file contains hidden or 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
This file contains hidden or 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
9 changes: 9 additions & 0 deletions
9
extensions/ql-vscode/src/view/data-extensions-editor/formatters.ts
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| export const decimalFormatter = new Intl.NumberFormat("en-US", { | ||
| style: "decimal", | ||
| maximumFractionDigits: 2, | ||
| }); | ||
|
|
||
| export const percentFormatter = new Intl.NumberFormat("en-US", { | ||
| style: "percent", | ||
| maximumFractionDigits: 2, | ||
| }); |
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.