Skip to content

Commit

Permalink
fix: added displayname
Browse files Browse the repository at this point in the history
  • Loading branch information
pksorensen committed Sep 5, 2024
1 parent 8539edf commit 345da8d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
6 changes: 3 additions & 3 deletions packages/designer/src/Components/Drawers/QuestionTreeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const QuestionTreeItem: React.FC<QuestionTreeItemProps> = ({ setView, setActiveQ
const styles = useNavDrawerStyles();
const sortedQuestions = useMemo(() => {

return Object.entries(quickformpayload.questions ?? {}).map(([key, question], index) => [key, question, index] as [string, QuestionJsonModel, number])
return Object.entries(quickformpayload.questions ?? {}).map(([key, question], index) => [key, question, index] as [string, typeof question, number])
.sort(([_, qa, ai], [__, qb, bi]) => (qa.order ?? ai) - (qb.order ?? bi));

}, [quickformpayload])
Expand Down Expand Up @@ -119,8 +119,8 @@ const QuestionTreeItem: React.FC<QuestionTreeItemProps> = ({ setView, setActiveQ
icon={<TrashCanIcon />}
/>
</>
}}>
{question.logicalName ? key : question.text}
}}>
{question.displayName ?? question.text}
</TreeItemLayout>
</TreeItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,25 @@ export const QuickFormSettingsViewHeader: React.FC = () => {
const { view, activeQuestion, activeSlide, quickformpayload: { layout, questions }, updateQuickFormPayload, designerLocale } = useQuickFormDefinition();

const [questionKey, setQuestionKey] = useState(activeQuestion ?? '');
const [displayName, setDisplayName] = useState(questions[activeQuestion!]?.displayName ?? questions[activeQuestion!]?.text);



useEffect(() => { setQuestionKey(activeQuestion ?? ''); }, [activeQuestion])

const segments = [designerLocale.Title, view, activeQuestion, activeSlide && layout?.slides?.[activeSlide]?.schemaName].filter(x => !!x) as string[];
const segments = [designerLocale.Title, view, questions[activeQuestion!]?.displayName?? activeQuestion, activeSlide && layout?.slides?.[activeSlide]?.schemaName].filter(x => !!x) as string[];
const handleSubmit: React.MouseEventHandler<HTMLButtonElement> = (ev) => {

if (activeQuestion) {
updateQuickFormPayload(old => {

let text = questionKey;
let text = displayName;
let schemaName = removeNonAlphanumeric(text);
let logicalName = schemaName.toLowerCase();

old.questions[text] = { ...old.questions[activeQuestion], schemaName, logicalName };
if (text !== activeQuestion)
delete old.questions[activeQuestion];
old.questions[activeQuestion] = { ...old.questions[activeQuestion], schemaName, logicalName, displayName };
// if (text !== activeQuestion)
// delete old.questions[activeQuestion];

if (!old.__designer)
old.__designer = {};
Expand All @@ -83,8 +87,11 @@ export const QuickFormSettingsViewHeader: React.FC = () => {
<DialogBody>
<DialogTitle>Question Settings</DialogTitle>
<DialogContent className={dialogstyles.content}>
<Field label="Question Key">
<Input value={questionKey} required type="text" id={"question-schema-name"} onChange={(e, d) => setQuestionKey(d.value)} />
<Field label="Question Key" aria-readonly>
<Input readOnly value={questionKey} required type="text" id={"question-key"} onChange={(e, d) => setQuestionKey(d.value)} />
</Field>
<Field label="Display Name" aria-readonly>
<Input readOnly value={displayName ?? questions[activeQuestion!]?.text} required type="text" id={"question-display-name"} onChange={(e, d) => setDisplayName(d.value)} />
</Field>
{activeQuestion &&
<Field label="Question Order">
Expand Down
5 changes: 4 additions & 1 deletion packages/designer/src/Types/QuickFormDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export type QuickFormDesignerDefinition = {
/**
* If this question has been generated by some tool/framework and be used in designer if ediable.
*/
generated?: boolean
generated?: boolean;

schemaName?: string;
displayName?: string;
}
}
} & QuickFormDefinition;

0 comments on commit 345da8d

Please sign in to comment.