-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(ui) Add framework for template/module state and editing templates/modules to UI #14029
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
9 commits
Select commit
Hold shift + click to select a range
8dd7e42
WIP - ability to add modules to rows for our default modules at least…
chriscollins3456 68676dd
after first round of cleaning up the code
chriscollins3456 778285d
add tests, fix linting, format
chriscollins3456 913260d
fix up tests and linting
chriscollins3456 505b0c8
last second tweaks
chriscollins3456 2cd3ede
format gms graphql enging
chriscollins3456 4ceb568
merge in master, resolve conflicts
chriscollins3456 cbe946f
Merge branch 'master' into cc--ch-530-edit-template-in-ui
chriscollins3456 cd0b4e5
fix linting
chriscollins3456 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
86 changes: 86 additions & 0 deletions
86
datahub-web-react/src/app/homeV3/context/PageTemplateContext.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,86 @@ | ||
import React, { ReactNode, createContext, useContext, useMemo } from 'react'; | ||
|
||
import { useModuleOperations } from '@app/homeV3/context/hooks/useModuleOperations'; | ||
import { useTemplateOperations } from '@app/homeV3/context/hooks/useTemplateOperations'; | ||
import { useTemplateState } from '@app/homeV3/context/hooks/useTemplateState'; | ||
import { PageTemplateContextState } from '@app/homeV3/context/types'; | ||
|
||
import { PageTemplateFragment } from '@graphql/template.generated'; | ||
|
||
const PageTemplateContext = createContext<PageTemplateContextState | undefined>(undefined); | ||
|
||
export const PageTemplateProvider = ({ | ||
personalTemplate: initialPersonalTemplate, | ||
globalTemplate: initialGlobalTemplate, | ||
children, | ||
}: { | ||
personalTemplate: PageTemplateFragment | null | undefined; | ||
globalTemplate: PageTemplateFragment | null | undefined; | ||
children: ReactNode; | ||
}) => { | ||
// Template state management | ||
const { | ||
personalTemplate, | ||
globalTemplate, | ||
template, | ||
isEditingGlobalTemplate, | ||
setIsEditingGlobalTemplate, | ||
setPersonalTemplate, | ||
setGlobalTemplate, | ||
setTemplate, | ||
} = useTemplateState(initialPersonalTemplate, initialGlobalTemplate); | ||
|
||
// Template operations | ||
const { updateTemplateWithModule, upsertTemplate } = useTemplateOperations(); | ||
|
||
// Module operations | ||
const { addModule, createModule } = useModuleOperations( | ||
isEditingGlobalTemplate, | ||
personalTemplate, | ||
globalTemplate, | ||
setPersonalTemplate, | ||
setGlobalTemplate, | ||
updateTemplateWithModule, | ||
upsertTemplate, | ||
); | ||
|
||
const value = useMemo( | ||
() => ({ | ||
personalTemplate, | ||
globalTemplate, | ||
template, | ||
isEditingGlobalTemplate, | ||
setIsEditingGlobalTemplate, | ||
setPersonalTemplate, | ||
setGlobalTemplate, | ||
setTemplate, | ||
addModule, | ||
createModule, | ||
}), | ||
[ | ||
personalTemplate, | ||
globalTemplate, | ||
template, | ||
isEditingGlobalTemplate, | ||
setIsEditingGlobalTemplate, | ||
setPersonalTemplate, | ||
setGlobalTemplate, | ||
setTemplate, | ||
addModule, | ||
createModule, | ||
], | ||
); | ||
|
||
return <PageTemplateContext.Provider value={value}>{children}</PageTemplateContext.Provider>; | ||
}; | ||
|
||
export function usePageTemplateContext() { | ||
const context = useContext(PageTemplateContext); | ||
if (!context) { | ||
throw new Error('usePageTemplateContext must be used within a PageTemplateProvider'); | ||
} | ||
return context; | ||
} | ||
|
||
// Re-export types for convenience | ||
export type { CreateModuleInput, AddModuleInput } from './types'; |
Oops, something went wrong.
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.
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.
we'll probably want to add some loading state here later