-
Notifications
You must be signed in to change notification settings - Fork 334
FUI - APIs list Dropdown #2501
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
FUI - APIs list Dropdown #2501
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f250f27
APIs list - as Dropdown
JMach1 45d4851
APIs list Dropdown - links
JMach1 f1c2113
FUI Dropdown - loading default value & styling
JMach1 9701360
Merge remote-tracking branch 'refs/remotes/origin/fui/master' into fu…
JMach1 99a7e98
FUI - list-of-apis isRedesignEnabled
JMach1 2ceb2d0
mini fix
JMach1 c577111
FUI - product-list isRedesignEnabled
JMach1 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
<!-- ko if: layout() === 'list' --> | ||
<!-- ko if: isRedesignEnabled --> | ||
<fui-api-list-runtime data-bind="attr: { props: runtimeConfig }"></fui-api-list-runtime> | ||
<!-- /ko --> | ||
|
||
<!-- ko if: layout() === 'dropdown' --> | ||
<api-list-dropdown data-bind="attr: { params: runtimeConfig }"></api-list-dropdown> | ||
<!-- /ko --> | ||
<!-- ko ifnot: isRedesignEnabled --> | ||
<!-- ko if: layout() === 'list' --> | ||
<api-list data-bind="attr: { params: runtimeConfig }"></api-list> | ||
<!-- /ko --> | ||
|
||
<!-- ko if: layout() === 'tiles' --> | ||
<fui-api-list-runtime data-bind="attr: { props: runtimeConfig }"></fui-api-list-runtime> | ||
<!-- /ko --> | ||
<!-- ko if: layout() === 'dropdown' --> | ||
<api-list-dropdown data-bind="attr: { params: runtimeConfig }"></api-list-dropdown> | ||
<!-- /ko --> | ||
|
||
<!-- ko if: layout() === 'tiles' --> | ||
<api-list-tiles data-bind="attr: { params: runtimeConfig }"></api-list-tiles> | ||
<!-- /ko --> | ||
<!-- /ko --> |
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
214 changes: 214 additions & 0 deletions
214
src/components/apis/list-of-apis/react/runtime/ApiListDropdown.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,214 @@ | ||
import * as React from "react"; | ||
import { useState } from "react"; | ||
import { | ||
Body1Strong, | ||
Combobox, | ||
Link, | ||
Option, | ||
OptionGroup, | ||
Spinner, | ||
} from "@fluentui/react-components"; | ||
import { Resolve } from "@paperbits/react/decorators"; | ||
import { GroupByTag } from "../../../../utils/react/TableListInfo"; | ||
import { Pagination } from "../../../../utils/react/Pagination"; | ||
import * as Constants from "../../../../../constants"; | ||
import { Api } from "../../../../../models/api"; | ||
import { TApiListRuntimeFC } from "./ApiListRuntime"; | ||
import { | ||
isApisGrouped, | ||
TagGroupToggleBtn, | ||
TApisData, | ||
toggleValueInSet, | ||
} from "./utils"; | ||
import { RouteHelper } from "../../../../../routing/routeHelper"; | ||
import { ApiService } from "../../../../../services/apiService"; | ||
|
||
type TApiListDropdown = Omit< | ||
TApiListRuntimeFC, | ||
"apiService" | "layoutDefault" | "productName" | ||
> & { | ||
working: boolean; | ||
apis: TApisData; | ||
statePageNumber: ReturnType<typeof useState<number>>; | ||
statePattern: ReturnType<typeof useState<string>>; | ||
stateGroupByTag: ReturnType<typeof useState<boolean>>; | ||
}; | ||
|
||
const TagLabel = ({ | ||
tag, | ||
expanded, | ||
onClick, | ||
}: { | ||
tag: string; | ||
expanded: Set<string>; | ||
onClick(): void; | ||
}) => ( | ||
<button onClick={onClick} className={"no-border"}> | ||
<TagGroupToggleBtn expanded={expanded.has(tag)} /> | ||
<span style={{ marginLeft: ".575rem" }}>{tag}</span> | ||
</button> | ||
); | ||
|
||
const Options = ({ | ||
apis, | ||
getReferenceUrl, | ||
}: { | ||
apis: Api[]; | ||
getReferenceUrl: TApiListRuntimeFC["getReferenceUrl"]; | ||
}) => ( | ||
<> | ||
{apis.map((api) => ( | ||
<Option key={api.id} value={api.name} text={api.displayName}> | ||
<Link href={getReferenceUrl(api.name)}>{api.displayName}</Link> | ||
</Option> | ||
))} | ||
</> | ||
); | ||
|
||
const ApiListDropdownFC = ({ | ||
working, | ||
apis, | ||
getReferenceUrl, | ||
selectedApi, | ||
statePageNumber: [pageNumber, setPageNumber], | ||
statePattern: [_, setPattern], | ||
stateGroupByTag: [groupByTag, setGroupByTag], | ||
}: TApiListDropdown & { selectedApi?: Api }) => { | ||
const [expanded, setExpanded] = React.useState(new Set<string>()); | ||
|
||
const pageMax = Math.ceil(apis?.count / Constants.defaultPageSize); | ||
|
||
const toggleTag = (tag: string) => | ||
setExpanded((old) => toggleValueInSet(old, tag)); | ||
|
||
const content = !apis ? ( | ||
<>Loading APIs</> // if data are not loaded yet ComboBox sometimes fails to initialize properly - edge case, in most cases almost instant from the cache | ||
) : ( | ||
<Combobox | ||
style={{ width: "100%" }} | ||
onInput={(event) => setPattern(event.target?.["value"])} | ||
defaultValue={selectedApi?.displayName} | ||
defaultSelectedOptions={[selectedApi?.name]} | ||
onOptionSelect={(_, { optionValue }) => { | ||
if (!optionValue) return; | ||
window.location.hash = getReferenceUrl(optionValue); | ||
}} | ||
> | ||
{working ? ( | ||
<Spinner | ||
label={"Loading APIs"} | ||
labelPosition={"above"} | ||
size={"small"} | ||
style={{ padding: "1rem" }} | ||
/> | ||
) : ( | ||
<> | ||
<Option | ||
disabled | ||
value={"group by tag switch"} | ||
text={"group by tag switch"} | ||
> | ||
<GroupByTag | ||
groupByTag={groupByTag} | ||
setGroupByTag={setGroupByTag} | ||
/> | ||
</Option> | ||
|
||
{isApisGrouped(apis) ? ( | ||
apis?.value.map(({ tag, items }) => ( | ||
<OptionGroup | ||
key={tag} | ||
label={ | ||
<TagLabel | ||
onClick={() => toggleTag(tag)} | ||
tag={tag} | ||
expanded={expanded} | ||
/> | ||
} | ||
> | ||
{expanded.has(tag) && ( | ||
<Options | ||
apis={items} | ||
getReferenceUrl={getReferenceUrl} | ||
/> | ||
)} | ||
</OptionGroup> | ||
)) | ||
) : ( | ||
<Options | ||
apis={apis.value} | ||
getReferenceUrl={getReferenceUrl} | ||
/> | ||
)} | ||
|
||
{pageMax > 1 && ( | ||
<Option | ||
disabled | ||
value={"pagination"} | ||
text={"pagination"} | ||
> | ||
<Pagination | ||
pageNumber={pageNumber} | ||
setPageNumber={setPageNumber} | ||
pageMax={pageMax} | ||
/> | ||
</Option> | ||
)} | ||
</> | ||
)} | ||
</Combobox> | ||
); | ||
|
||
return ( | ||
<> | ||
<Body1Strong block>APIs</Body1Strong> | ||
<div style={{ padding: ".25rem 0 1rem" }}>{content}</div> | ||
</> | ||
); | ||
}; | ||
|
||
export class ApiListDropdown extends React.Component< | ||
TApiListDropdown, | ||
{ working: boolean; api?: Api } | ||
> { | ||
@Resolve("apiService") | ||
public apiService: ApiService; | ||
|
||
@Resolve("routeHelper") | ||
public routeHelper: RouteHelper; | ||
|
||
constructor(props: TApiListDropdown) { | ||
super(props); | ||
|
||
this.state = { | ||
working: false, | ||
api: undefined, | ||
}; | ||
} | ||
|
||
public componentDidMount() { | ||
this.loadSelectedApi(); | ||
} | ||
|
||
async loadSelectedApi() { | ||
const apiName = this.routeHelper.getApiName(); | ||
if (!apiName) return; | ||
|
||
this.setState({ working: true, api: undefined }); | ||
|
||
return this.apiService | ||
.getApi(`apis/${apiName}`) | ||
.then((api) => this.setState({ api })) | ||
.finally(() => this.setState({ working: false })); | ||
} | ||
|
||
render() { | ||
return ( | ||
<ApiListDropdownFC | ||
{...this.props} | ||
working={this.props.working || this.state.working} | ||
selectedApi={this.state.api} | ||
/> | ||
); | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.