-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added util to update page title and added empty data check on environ…
…ment page (#4162) * Added util to update page title and fixed env page loader Signed-off-by: Hrishav <[email protected]> * Fixed issues found while testing Signed-off-by: Hrishav <[email protected]> * Fixed UI issues found Signed-off-by: Hrishav <[email protected]> --------- Signed-off-by: Hrishav <[email protected]> Co-authored-by: Saranya Jena <[email protected]>
- Loading branch information
1 parent
7bcbd7c
commit ac6ebe4
Showing
37 changed files
with
308 additions
and
150 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,39 @@ | ||
import React from 'react'; | ||
import { useToaster } from '@harnessio/uicore'; | ||
import ApiTokensView from '@views/ApiTokens'; | ||
import { useGetApiTokensQuery } from '@api/auth'; | ||
import { getUserDetails } from '@utils'; | ||
|
||
interface APITokensControllerProps { | ||
setApiTokensCount: React.Dispatch<React.SetStateAction<number>>; | ||
} | ||
|
||
export default function APITokensController(props: APITokensControllerProps): React.ReactElement { | ||
const { setApiTokensCount } = props; | ||
const { showError } = useToaster(); | ||
const { accountID } = getUserDetails(); | ||
|
||
const { | ||
data: apiTokensData, | ||
isLoading: apiTokensLoading, | ||
refetch: apiTokensRefetch | ||
} = useGetApiTokensQuery( | ||
{ user_id: accountID }, | ||
{ | ||
onError: error => { | ||
showError(error.error); | ||
}, | ||
onSuccess: data => { | ||
setApiTokensCount(data.apiTokens.length); | ||
} | ||
} | ||
); | ||
|
||
return ( | ||
<ApiTokensView | ||
apiTokensData={apiTokensData} | ||
apiTokensRefetch={apiTokensRefetch} | ||
getApiTokensQueryLoading={apiTokensLoading} | ||
/> | ||
); | ||
} |
This file contains 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,3 @@ | ||
import APITokensController from './APITokens'; | ||
|
||
export default APITokensController; |
This file contains 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
4 changes: 2 additions & 2 deletions
4
chaoscenter/web/src/controllers/CreateNewToken/CreateNewToken.tsx
This file contains 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
4 changes: 2 additions & 2 deletions
4
chaoscenter/web/src/controllers/DeleteApiToken/DeleteApiToken.tsx
This file contains 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 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,6 +1,6 @@ | ||
export interface InviteUserDetails { | ||
username: string; | ||
id: string; | ||
userID: string; | ||
email: string; | ||
name: string; | ||
} |
This file contains 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 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 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,42 @@ | ||
import React from 'react'; | ||
import { isEqualWith } from 'lodash-es'; | ||
|
||
/** | ||
* Custom version of isEqual to handle function comparison | ||
*/ | ||
function isEqual(a: unknown, b: unknown): boolean { | ||
return isEqualWith(a, b, (x: unknown, y: unknown): boolean | undefined => { | ||
// Deal with the function comparison case | ||
if (typeof x === 'function' && typeof y === 'function') { | ||
return x.toString() === y.toString(); | ||
} | ||
|
||
// Fallback on the method | ||
return undefined; | ||
}); | ||
} | ||
|
||
function useDeepCompareMemoize(value: React.DependencyList): React.DependencyList | undefined { | ||
const ref = React.useRef<React.DependencyList>(); | ||
|
||
if (!isEqual(value, ref.current)) { | ||
ref.current = value; | ||
} | ||
|
||
return ref.current; | ||
} | ||
|
||
/** | ||
* Accepts a function that contains imperative, possibly effectful code. | ||
* | ||
* This is the deepCompare version of the `React.useEffect` hooks (that is shallowed compare) | ||
* | ||
* @param effect Imperative function that can return a cleanup function | ||
* @param deps If present, effect will only activate if the values in the list change. | ||
* | ||
* @see https://gist.github.com/kentcdodds/fb8540a05c43faf636dd68647747b074#gistcomment-2830503 | ||
*/ | ||
export function useDeepCompareEffect(effect: React.EffectCallback, deps: React.DependencyList): void { | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
React.useEffect(effect, useDeepCompareMemoize(deps)); | ||
} |
This file contains 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,59 @@ | ||
import { useParams } from 'react-router-dom'; | ||
import { useStrings } from '@strings'; | ||
import { useAppStore } from '@context'; | ||
import { useDeepCompareEffect } from './useDeepCompareEffect'; | ||
|
||
export type Title = string | string[]; | ||
|
||
export interface UseDocumentTitleReturn { | ||
updateTitle: (newTitle: Title) => void; | ||
} | ||
|
||
export function useDocumentTitle(title: Title): UseDocumentTitleReturn { | ||
const { getString } = useStrings(); | ||
const { projectID: projectIdFromParams, accountID } = useParams<{ projectID: string; accountID: string }>(); | ||
const projectIdFromLocalStorage = localStorage.getItem('projectID'); | ||
const { projectName, currentUserInfo } = useAppStore(); | ||
|
||
const getStringFromTitle = (str: Title): string => (Array.isArray(str) ? str.filter(s => s).join(' | ') : str); | ||
|
||
const updateTitle = (newTitle: Title): void => { | ||
const titleArray = [getStringFromTitle(newTitle), getString('litmusChaos')]; | ||
|
||
if (accountID && projectIdFromParams) { | ||
// If you're in project scoped routes, add project name to title from appStore | ||
let projectTitle = ''; | ||
if (projectIdFromParams === projectIdFromLocalStorage) { | ||
projectTitle = projectName || projectIdFromParams; | ||
} else { | ||
projectTitle = projectIdFromParams; | ||
} | ||
|
||
titleArray.splice(1, 0, projectTitle); | ||
} else if (accountID && !projectIdFromParams) { | ||
// If you're in account scoped routes, add account ID to title | ||
let accountTitle = ''; | ||
if (accountID === currentUserInfo?.ID) { | ||
accountTitle = currentUserInfo?.username || accountID; | ||
} else { | ||
accountTitle = accountID; | ||
} | ||
titleArray.splice(1, 0, accountTitle); | ||
} | ||
|
||
document.title = titleArray.filter(s => s).join(' | '); | ||
}; | ||
|
||
useDeepCompareEffect(() => { | ||
updateTitle(title); | ||
|
||
return () => { | ||
// reset title on unmount | ||
document.title = getString('litmusChaos'); | ||
}; | ||
}, [title]); | ||
|
||
return { | ||
updateTitle | ||
}; | ||
} |
This file contains 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
Oops, something went wrong.