-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
418 additions
and
43 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
60 changes: 60 additions & 0 deletions
60
frontend/src/concepts/pipelines/context/MlmdListContext.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
|
||
interface MlmdOrderBy { | ||
field: string; | ||
direction: 'asc' | 'desc'; | ||
} | ||
|
||
interface MlmdListContextProps { | ||
filterQuery: string | undefined; | ||
pageToken: string | undefined; | ||
maxResultSize: number; | ||
orderBy: MlmdOrderBy | undefined; | ||
setFilterQuery: (filterQuery: string | undefined) => void; | ||
setPageToken: (pageToken: string | undefined) => void; | ||
setMaxResultSize: (maxResultSize: number) => void; | ||
setOrderBy: (orderBy: MlmdOrderBy | undefined) => void; | ||
} | ||
|
||
const MlmdListContext = React.createContext({} as MlmdListContextProps); | ||
|
||
export const MlmdListContextProvider: React.FC<React.PropsWithChildren> = ({ children }) => { | ||
const [filterQuery, setFilterQuery] = React.useState<string>(); | ||
const [pageToken, setPageToken] = React.useState<string>(); | ||
const [maxResultSize, setMaxResultSize] = React.useState(10); | ||
const [orderBy, setOrderBy] = React.useState<MlmdOrderBy>(); | ||
const value = React.useMemo( | ||
() => ({ | ||
filterQuery, | ||
pageToken, | ||
maxResultSize, | ||
orderBy, | ||
setFilterQuery, | ||
setPageToken, | ||
setMaxResultSize, | ||
setOrderBy, | ||
}), | ||
[filterQuery, maxResultSize, orderBy, pageToken], | ||
); | ||
|
||
return <MlmdListContext.Provider value={value}>{children}</MlmdListContext.Provider>; | ||
}; | ||
|
||
export const useMlmdListContext = (nextPageToken?: string): MlmdListContextProps => { | ||
// Force disabled state to pagination when there is no nextPageToken | ||
React.useEffect(() => { | ||
const paginationNextButtons = document.querySelectorAll('button[aria-label="Go to next page"]'); | ||
|
||
if (paginationNextButtons.length > 0) { | ||
paginationNextButtons.forEach((button) => { | ||
if (!nextPageToken) { | ||
button.setAttribute('disabled', ''); | ||
} else { | ||
button.removeAttribute('disabled'); | ||
} | ||
}); | ||
} | ||
}, [nextPageToken]); | ||
|
||
return React.useContext(MlmdListContext); | ||
}; |
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 |
---|---|---|
|
@@ -6,3 +6,4 @@ export { | |
ViewServerModal, | ||
PipelineServerTimedOut, | ||
} from './PipelinesContext'; | ||
export * from './MlmdListContext'; |
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.