feat(configuration): Adds missing implermentations
This commit is contained in:
parent
b82ab7dbc4
commit
ec0aa5654c
7 changed files with 150 additions and 32 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import {
|
||||
AnyMenuItem, FieldMenuItem,
|
||||
FieldMenuItemContext, FieldMenuItemSaveValue,
|
||||
MenuItemType,
|
||||
FieldMenuItemContext, FieldMenuItemSaveValue, MenuItem,
|
||||
MenuItemType, PromptMenuItem,
|
||||
RowBuilderFieldMenuItemContext
|
||||
} from "../Menu/MenuRenderer.types";
|
||||
import {GroupConfigurationTransformers} from "./GroupConfigurationTransformers";
|
||||
|
|
@ -18,6 +18,7 @@ import {
|
|||
} from "discord.js";
|
||||
import {ChannelId} from "../types/DiscordTypes";
|
||||
import {MessageActionRowComponentBuilder} from "@discordjs/builders";
|
||||
import {Prompt} from "../Menu/Modals/Prompt";
|
||||
|
||||
export class ConfigurationMenuHandler {
|
||||
|
||||
|
|
@ -56,15 +57,6 @@ export class ConfigurationMenuHandler {
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
traversalKey: "locale",
|
||||
label: "Locale",
|
||||
description: "Provides locale to be used for this group.",
|
||||
type: MenuItemType.Field,
|
||||
getCurrentValue: this.getLocaleValue.bind(this),
|
||||
getActionRowBuilder: this.getLocaleMenuBuilder.bind(this),
|
||||
setValue: this.setValue.bind(this)
|
||||
},
|
||||
{
|
||||
traversalKey: "permissions",
|
||||
label: "Permissions",
|
||||
|
|
@ -88,20 +80,45 @@ export class ConfigurationMenuHandler {
|
|||
description: "Provides settings for the metadata contained in the playdate exports.",
|
||||
type: MenuItemType.Collection,
|
||||
children: [
|
||||
{
|
||||
this.createStringMenuItem({
|
||||
traversalKey: "title",
|
||||
label: "Title",
|
||||
description: "Defines how the calendar entry should be called.",
|
||||
type: MenuItemType.Prompt,
|
||||
getCurrentValue: this.getStringValue.bind(this),
|
||||
getActionRowBuilder: this.getStringBuilder.bind(this),
|
||||
setValue: this.setValue.bind(this)
|
||||
}
|
||||
}),
|
||||
this.createTextareaMenuItem({
|
||||
traversalKey: "description",
|
||||
label: "Description",
|
||||
description: "Sets the description for the calendar entry.",
|
||||
}),
|
||||
this.createStringMenuItem({
|
||||
traversalKey: "location",
|
||||
label: "Location",
|
||||
description: "Sets the location where the calendar should point to."
|
||||
}),
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
private createStringMenuItem(metadata: MenuItem): PromptMenuItem {
|
||||
return {
|
||||
...metadata,
|
||||
type: MenuItemType.Prompt,
|
||||
getCurrentValue: this.getStringValue.bind(this),
|
||||
getActionRowBuilder: this.getStringBuilder.bind(this),
|
||||
setValue: this.setValue.bind(this)
|
||||
};
|
||||
}
|
||||
private createTextareaMenuItem(metadata: MenuItem): PromptMenuItem {
|
||||
return {
|
||||
...metadata,
|
||||
type: MenuItemType.Prompt,
|
||||
getCurrentValue: this.getStringValue.bind(this),
|
||||
getActionRowBuilder: this.getTextareaBuilder.bind(this),
|
||||
setValue: this.setValue.bind(this)
|
||||
};
|
||||
}
|
||||
|
||||
private getChannelValue(context: FieldMenuItemContext): string {
|
||||
const value = this.configuration.getConfigurationByPath(context.path.join('.'));
|
||||
if (value === undefined) {
|
||||
|
|
@ -193,6 +210,11 @@ export class ConfigurationMenuHandler {
|
|||
return new TextInputBuilder()
|
||||
.setStyle(TextInputStyle.Short)
|
||||
}
|
||||
private getTextareaBuilder(context: FieldMenuItemContext): TextInputBuilder {
|
||||
return new TextInputBuilder()
|
||||
.setStyle(TextInputStyle.Paragraph)
|
||||
}
|
||||
|
||||
|
||||
private setValue(value: FieldMenuItemSaveValue[]|string, context: FieldMenuItemContext): void {
|
||||
const savedValue = typeof value !== 'string' ?
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@ import {isPlainObject} from "is-plain-object";
|
|||
export class GroupConfigurationHandler {
|
||||
static DEFAULT_CONFIGURATION: RuntimeGroupConfiguration = {
|
||||
channels: null,
|
||||
locale: new Intl.Locale('en-GB'),
|
||||
permissions: {
|
||||
allowMemberManagingPlaydates: false
|
||||
},
|
||||
calendar: {
|
||||
title: null
|
||||
title: null,
|
||||
description: null,
|
||||
location: null
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ type GroupConfigurationTransformer = {
|
|||
}
|
||||
|
||||
export type GroupConfigurationResult =
|
||||
ChannelId | Intl.Locale | boolean | string
|
||||
ChannelId | Intl.Locale | boolean | string | null
|
||||
|
||||
export class GroupConfigurationTransformers {
|
||||
static TRANSFORMERS: GroupConfigurationTransformer[] = [
|
||||
|
|
@ -28,10 +28,6 @@ export class GroupConfigurationTransformers {
|
|||
path: ['channels', 'playdateReminders'],
|
||||
type: TransformerType.Channel,
|
||||
},
|
||||
{
|
||||
path: ['locale'],
|
||||
type: TransformerType.Locale,
|
||||
},
|
||||
{
|
||||
path: ['permissions', 'allowMemberManagingPlaydates'],
|
||||
type: TransformerType.PermissionBoolean
|
||||
|
|
@ -39,6 +35,14 @@ export class GroupConfigurationTransformers {
|
|||
{
|
||||
path: ['calendar', 'title'],
|
||||
type: TransformerType.String
|
||||
},
|
||||
{
|
||||
path: ['calendar', 'description'],
|
||||
type: TransformerType.String,
|
||||
},
|
||||
{
|
||||
path: ['calendar', 'location'],
|
||||
type: TransformerType.String
|
||||
}
|
||||
];
|
||||
|
||||
|
|
|
|||
5
source/Groups/RuntimeGroupConfiguration.d.ts
vendored
5
source/Groups/RuntimeGroupConfiguration.d.ts
vendored
|
|
@ -3,7 +3,6 @@ import {Nullable} from "../types/Nullable";
|
|||
|
||||
export type RuntimeGroupConfiguration = {
|
||||
channels: Nullable<ChannelRuntimeGroupConfiguration>,
|
||||
locale: Intl.Locale,
|
||||
permissions: PermissionRuntimeGroupConfiguration,
|
||||
calendar: CalendarRuntimeGroupConfiguration
|
||||
};
|
||||
|
|
@ -18,5 +17,7 @@ export type PermissionRuntimeGroupConfiguration = {
|
|||
}
|
||||
|
||||
export type CalendarRuntimeGroupConfiguration = {
|
||||
title: null|string
|
||||
title: null|string,
|
||||
description: null|string,
|
||||
location: null|string
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue