Skip to content

Commit

Permalink
chore: sort templates in template picker
Browse files Browse the repository at this point in the history
fix: #1250
  • Loading branch information
windingwind committed Jan 6, 2025
1 parent 4726e7c commit b1fe4cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Addon {
templates: string[];
};
picker: {
mode: "insert" | "create" | "export";
mode: "insert" | "create" | "export" | "pick";
data: Record<string, any>;
};
};
Expand Down
3 changes: 2 additions & 1 deletion src/extras/templatePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ let args = window.arguments[0] as any;
if (!args._initPromise) {
args = args.wrappedJSObject;
}
const templateData = args.templates;
const templateData = (args.templates as string[]) || [];
templateData.sort();
const multiSelect = args.multiSelect;
let tableHelper: VirtualizedTableHelper;

Expand Down
9 changes: 7 additions & 2 deletions src/modules/template/picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ async function showTemplatePicker(
mode: "export",
data?: Record<string, never>,
): Promise<void>;
async function showTemplatePicker(): Promise<void>;
async function showTemplatePicker(mode: "pick"): Promise<string[]>;
async function showTemplatePicker(): Promise<any>;
async function showTemplatePicker(
mode: typeof addon.data.template.picker.mode = "insert",
data: Record<string, any> = {},
) {
): Promise<unknown> {
addon.data.template.picker.mode = mode;
addon.data.template.picker.data = data;
const selected = await openTemplatePicker();
// For pick mode, return selected templates
if (mode === "pick") {
return selected;
}
if (!selected.length) {
return;
}
Expand Down

0 comments on commit b1fe4cc

Please sign in to comment.