-
Notifications
You must be signed in to change notification settings - Fork 2
GitHub Issue 1470: Manage Templates end up with sample type not usable in Apps #2067
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
Open
XingY
wants to merge
2
commits into
develop
Choose a base branch
from
fb_issue1470
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
87 changes: 87 additions & 0 deletions
87
packages/components/src/internal/components/entities/useEntityTypeParam.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,87 @@ | ||
| /* | ||
| * Copyright (c) 2026 LabKey Corporation. All rights reserved. No portion of this work may be reproduced in | ||
| * any form or by any electronic or mechanical means without written permission from LabKey Corporation. | ||
| */ | ||
| import { useEffect, useMemo, useState } from 'react'; | ||
| import { useParams } from 'react-router'; | ||
|
|
||
| import { isLoading, LoadingState } from '../../../public/LoadingState'; | ||
| import { QueryInfo } from '../../../public/QueryInfo'; | ||
| import { SchemaQuery } from '../../../public/SchemaQuery'; | ||
| import { useAppContext } from '../../AppContext'; | ||
| import { resolveErrorMessage } from '../../util/messaging'; | ||
| import { SCHEMAS } from '../../schemas'; | ||
|
|
||
| export interface UseCanonicalQueryName { | ||
| error?: string; | ||
| isLoaded: boolean; | ||
| notFound: boolean; | ||
| queryInfo?: QueryInfo; | ||
| queryName?: string; | ||
| schemaName?: string; | ||
| schemaQuery?: SchemaQuery; | ||
| } | ||
|
|
||
| /** | ||
| * Resolves a possibly wrong-case schema/query name (e.g. a route param) to the server's canonical case via the cached getQueryDetails. | ||
| * `notFound` is set when the type does not exist, to drive a NotFound page. | ||
| */ | ||
| export function useCanonicalQueryName( | ||
| schemaName: string, | ||
| rawQueryName: string, | ||
| containerPath?: string | ||
| ): UseCanonicalQueryName { | ||
| const { api } = useAppContext(); | ||
| const [queryInfo, setQueryInfo] = useState<QueryInfo>(); | ||
| const [error, setError] = useState<string>(); | ||
| const [notFound, setNotFound] = useState(false); | ||
| const [loadingState, setLoadingState] = useState<LoadingState>(LoadingState.INITIALIZED); | ||
|
|
||
| useEffect(() => { | ||
| setQueryInfo(undefined); | ||
| setError(undefined); | ||
| setNotFound(false); | ||
|
|
||
| if (!schemaName || !rawQueryName) return; | ||
|
|
||
| (async () => { | ||
| setLoadingState(LoadingState.LOADING); | ||
| try { | ||
| const queryInfo_ = await api.query.getQueryDetails({ | ||
| schemaName, | ||
| queryName: rawQueryName, | ||
| containerPath, | ||
| }); | ||
| setQueryInfo(queryInfo_); | ||
| } catch (e) { | ||
| setNotFound(true); | ||
| setError(resolveErrorMessage(e)); | ||
| } finally { | ||
| setLoadingState(LoadingState.LOADED); | ||
| } | ||
| })(); | ||
| }, [api, schemaName, rawQueryName, containerPath]); | ||
|
|
||
| return useMemo( | ||
| () => ({ | ||
| error, | ||
| isLoaded: !isLoading(loadingState), | ||
| notFound, | ||
| queryInfo, | ||
| queryName: queryInfo?.name, | ||
| schemaName: queryInfo?.schemaQuery?.schemaName, | ||
| schemaQuery: queryInfo?.schemaQuery, | ||
| }), | ||
| [error, loadingState, notFound, queryInfo] | ||
| ); | ||
| } | ||
|
|
||
| export function useSampleTypeParam(containerPath?: string): UseCanonicalQueryName { | ||
| const { sampleType } = useParams(); | ||
| return useCanonicalQueryName(SCHEMAS.SAMPLE_SETS.SCHEMA, sampleType, containerPath); | ||
| } | ||
|
|
||
| export function useSourceTypeParam(entityTypeKey = 'sourceType', containerPath?: string): UseCanonicalQueryName { | ||
| const params = useParams(); | ||
| return useCanonicalQueryName(SCHEMAS.DATA_CLASSES.SCHEMA, params[entityTypeKey], containerPath); | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend using
useLoadableStatewhich will handle most of the boilerplate in this hook around tracking loading state.Edit: Actually it would probably be even more concise to use
useQueryInfoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was going to say.
useQueryInfois very similar to this.