This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 833
Implement updated open dialog method of the Module API #11395
Merged
richvdh
merged 8 commits into
matrix-org:develop
from
nordeck:nic/feat/module-api-dialog-improvements
Aug 21, 2023
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
823c631
Implement updated open dialog method
dhenneke 739794e
Apply the review comments
dhenneke 39beba0
Add unit tests for the module system dialog
dhenneke 95cb998
Merge branch 'develop' into nic/feat/module-api-dialog-improvements
dhenneke e4b999a
Bump @matrix-org/react-sdk-module-api from 1.0.0 to 2.0.0
dhenneke 1a8e65b
Run prettier
dhenneke 2c7c0ed
Apply review comments
dhenneke 289c70c
Merge branch 'develop' into nic/feat/module-api-dialog-improvements
dhenneke 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -17,15 +17,18 @@ limitations under the License. | |||||
import React, { createRef } from "react"; | ||||||
import { DialogContent, DialogProps } from "@matrix-org/react-sdk-module-api/lib/components/DialogContent"; | ||||||
import { logger } from "matrix-js-sdk/src/logger"; | ||||||
import { ModuleApi } from "@matrix-org/react-sdk-module-api/lib/ModuleApi"; | ||||||
import { ModuleUiDialogOptions } from "@matrix-org/react-sdk-module-api/lib/types/ModuleUiDialogOptions"; | ||||||
|
||||||
import ScrollableBaseModal, { IScrollableBaseState } from "./ScrollableBaseModal"; | ||||||
import { _t } from "../../../languageHandler"; | ||||||
|
||||||
interface IProps<P extends DialogProps, C extends DialogContent<P>> { | ||||||
contentFactory: (props: P, ref: React.RefObject<C>) => React.ReactNode; | ||||||
contentProps: P; | ||||||
title: string; | ||||||
onFinished(ok?: boolean, model?: Awaited<ReturnType<DialogContent<P>["trySubmit"]>>): void; | ||||||
contentProps: Omit<P, keyof DialogProps> | undefined; | ||||||
initialOptions: ModuleUiDialogOptions; | ||||||
moduleApi: ModuleApi; | ||||||
onFinished(ok?: boolean, model?: Awaited<ReturnType<DialogContent<P & DialogProps>["trySubmit"]>>): void; | ||||||
} | ||||||
|
||||||
interface IState extends IScrollableBaseState { | ||||||
|
@@ -42,9 +45,10 @@ export class ModuleUiDialog<P extends DialogProps, C extends DialogContent<P>> e | |||||
super(props); | ||||||
|
||||||
this.state = { | ||||||
title: this.props.title, | ||||||
canSubmit: true, | ||||||
actionLabel: _t("OK"), | ||||||
title: this.props.initialOptions.title, | ||||||
actionLabel: this.props.initialOptions.actionLabel ?? _t("OK"), | ||||||
cancelLabel: this.props.initialOptions.cancelLabel, | ||||||
canSubmit: this.props.initialOptions.canSubmit ?? true, | ||||||
}; | ||||||
} | ||||||
|
||||||
|
@@ -61,11 +65,23 @@ export class ModuleUiDialog<P extends DialogProps, C extends DialogContent<P>> e | |||||
this.props.onFinished(false); | ||||||
} | ||||||
|
||||||
protected setOptions(options: ModuleUiDialogOptions): void { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be private? |
||||||
this.setState((state) => ({ ...state, ...options })); | ||||||
} | ||||||
|
||||||
protected renderContent(): React.ReactNode { | ||||||
return ( | ||||||
<div className="mx_ModuleUiDialog"> | ||||||
{this.props.contentFactory(this.props.contentProps, this.contentRef)} | ||||||
</div> | ||||||
); | ||||||
const dialogProps: DialogProps = { | ||||||
moduleApi: this.props.moduleApi, | ||||||
setOptions: this.setOptions.bind(this), | ||||||
cancel: this.cancel.bind(this), | ||||||
}; | ||||||
|
||||||
// Typescript isn't very happy understanding that `contentProps` satisfies `Omit<P, keyof DialogProps>` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const contentProps: P = { | ||||||
...this.props.contentProps, | ||||||
...dialogProps, | ||||||
} as unknown as P; | ||||||
|
||||||
return <div className="mx_ModuleUiDialog">{this.props.contentFactory(contentProps, this.contentRef)}</div>; | ||||||
} | ||||||
} |
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 was deleted.
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.
wonder if this should be called
additionalContentProps
to distinguish it from the actualcontentProps