-
Notifications
You must be signed in to change notification settings - Fork 173
Add support for rendering the prompt-screen's settings - EA #998
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
kushalshit27
merged 18 commits into
master
from
DXCDT-662-deployCli-support-for-prompt-screen-settings
Dec 9, 2024
Merged
Changes from 7 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
3a897dc
Initial commit
ramya18101 c71bd1d
FIx getPromptScreenSettings func and include the dump logic
ramya18101 43fccbf
updated directory dump, and deploy
kushalshit27 0e843e5
Added: updated screenRenderers
kushalshit27 f0eeb8f
Added: unit tesr for handlers prompts.tests screen renderer
kushalshit27 b442561
Add dump logic for yaml context
ramya18101 2874e66
Added parse logic in yaml
ramya18101 7fab7ca
Fix failing unit tests in test_directory
ramya18101 df92aec
Format files & constants
ramya18101 b8e0214
fix: screen renderers yaml dump and deploy
kushalshit27 6ad6c85
resolve merge conflicts
ramya18101 b78aae0
Fix failing unit tests
ramya18101 f0c12cc
fix: screen renderers yaml unit tests
kushalshit27 9335d95
refactor: update screen render settings directory to use constants
kushalshit27 dcbf0d0
handle error: screen render
kushalshit27 830afbf
refactor: rename PromptScreenMap to PROMPT_SCREEN_MAPPINGS for consis…
kushalshit27 ee007ca
fix: improve error logging for screen renderers and clean up unused p…
kushalshit27 ac99156
update auth0 4.15.0
kushalshit27 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,23 +1,134 @@ | ||
| import path from 'path'; | ||
| import { ensureDirSync } from 'fs-extra'; | ||
| import fs from 'fs'; | ||
| import { GetRendering200Response } from 'auth0'; | ||
| import { YAMLHandler } from '.'; | ||
| import YAMLContext from '..'; | ||
| import { constants } from '../../../tools'; | ||
| import { ParsedAsset } from '../../../types'; | ||
| import { Prompts } from '../../../tools/auth0/handlers/prompts'; | ||
| import { existsMustBeDir } from '../../../utils'; | ||
|
|
||
| const getPromptsDirectory = (filePath: string) => path.join(filePath, constants.PROMPTS_DIRECTORY); | ||
|
|
||
| type ParsedPrompts = ParsedAsset<'prompts', Prompts>; | ||
|
|
||
| async function parseAndDump(context: YAMLContext): Promise<ParsedPrompts> { | ||
| // Type for the screen render array | ||
| type ScreenRenderArray = Array<{ | ||
| [prompt: string]: { | ||
| [screen: string]: string // filename | ||
| } | ||
| }>; | ||
|
|
||
| const loadScreenRenderers = (screenRenderArray: ScreenRenderArray, inputDir: string): GetRendering200Response[] => { | ||
| // Array to store loaded renderers | ||
| const loadedRenderers: GetRendering200Response[] = []; | ||
|
|
||
| // Iterate through each entry in the ScreenRenderArray | ||
| screenRenderArray.forEach(promptEntry => { | ||
| // Get the prompt (there will be only one key in each entry) | ||
| const prompt = Object.keys(promptEntry)[0]; | ||
|
|
||
| // Get the screens for this prompt | ||
| const screens = promptEntry[prompt]; | ||
|
|
||
| // Iterate through each screen for this prompt | ||
| Object.entries(screens).forEach(([, fileName]) => { | ||
| // Construct full file path | ||
| const filePath = fileName; | ||
|
|
||
| try { | ||
| // Read and parse the JSON file | ||
| const fileContent = fs.readFileSync(filePath, 'utf8'); | ||
| const rendererData = JSON.parse(fileContent); | ||
|
|
||
| // Add to the loadedRenderers array | ||
| loadedRenderers.push(rendererData); | ||
| } catch (error) { | ||
| console.error(`Error loading file ${fileName}:`, error); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| return loadedRenderers; | ||
| }; | ||
|
|
||
| async function parse(context: YAMLContext): Promise<ParsedPrompts> { | ||
| const { prompts } = context.assets; | ||
| if (!prompts) return { prompts: null }; | ||
|
|
||
| const promptsDirectory = getPromptsDirectory(context.basePath); | ||
| const renderSettingsDir = path.join(promptsDirectory, 'renderSettings'); | ||
|
|
||
| if (!existsMustBeDir(renderSettingsDir)) { | ||
| prompts.screenRenderers = []; | ||
| return { prompts: null }; | ||
| } // Skip | ||
|
|
||
| const a = prompts.screenRenderers as ScreenRenderArray; | ||
| console.log(a); | ||
|
|
||
| prompts.screenRenderers = loadScreenRenderers(a,renderSettingsDir); | ||
|
|
||
| return { | ||
| prompts, | ||
| }; | ||
| } | ||
|
|
||
| const processScreenRenderers = (screenRenderers: any[], outputDir: string) => { | ||
kushalshit27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Resulting ScreenRenderArray to be returned | ||
| const screenRenderArray: ScreenRenderArray = []; | ||
|
|
||
| console.log(outputDir); | ||
kushalshit27 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Process each renderer | ||
| screenRenderers.forEach(renderer => { | ||
| // Create filename in the format: promptName_screenName.json | ||
| const fileName = `${renderer.prompt}_${renderer.screen}.json`; | ||
| const filePath = path.join(outputDir, fileName); | ||
|
|
||
| // Write individual file | ||
| fs.writeFileSync(filePath, JSON.stringify(renderer, null, 2)); | ||
|
|
||
| // Find or create entry for this prompt in the screenRenderArray | ||
| let promptEntry = screenRenderArray.find(entry => entry[renderer.prompt]); | ||
|
|
||
| if (!promptEntry) { | ||
| // If no entry exists for this prompt, create a new one | ||
| promptEntry = { [renderer.prompt]: {} }; | ||
| screenRenderArray.push(promptEntry); | ||
| } | ||
|
|
||
| // Add screen to the prompt entry | ||
| promptEntry[renderer.prompt][renderer.screen] = filePath; | ||
| }); | ||
|
|
||
| return screenRenderArray; | ||
| }; | ||
|
|
||
| async function dump(context: YAMLContext): Promise<ParsedPrompts> { | ||
| const { prompts } = context.assets; | ||
|
|
||
| if (!prompts) return { prompts: null }; | ||
|
|
||
| const promptsDirectory = getPromptsDirectory(context.basePath); | ||
| ensureDirSync(promptsDirectory); | ||
|
|
||
| // Create the directory for render settings if it doesn't exist | ||
| const renderSettingsDir = path.join(promptsDirectory, 'renderSettings'); | ||
| ensureDirSync(renderSettingsDir); | ||
|
|
||
| // @ts-ignore | ||
| prompts.screenRenderers = processScreenRenderers(prompts.screenRenderers,renderSettingsDir); | ||
|
|
||
| return { | ||
| prompts, | ||
| }; | ||
| } | ||
|
|
||
| const promptsHandler: YAMLHandler<ParsedPrompts> = { | ||
| parse: parseAndDump, | ||
| dump: parseAndDump, | ||
| parse, | ||
| dump, | ||
| }; | ||
|
|
||
| export default promptsHandler; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.