Skip to content

Commit 9ecd737

Browse files
committed
feat: add underLoginInjection and order prop for login injection components
1 parent 023425d commit 9ecd737

File tree

4 files changed

+29
-12
lines changed

4 files changed

+29
-12
lines changed

adminforth/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ class AdminForth implements IAdminForth {
157157
this.activatePlugins();
158158
process.env.HEAVY_DEBUG && console.log('🔧 Plugins activated');
159159

160+
process.env.HEAVY_DEBUG && console.log('🔧 Validating after plugin activation...');
161+
this.configValidator.validateAfterPluginsActivation();
162+
process.env.HEAVY_DEBUG && console.log('🔧 Config validated');
163+
160164
process.env.HEAVY_DEBUG && console.log('🔧 Creating ExpressServer...');
161165
this.express = new ExpressServer(this);
162166
process.env.HEAVY_DEBUG && console.log('🔧 ExpressServer created');

adminforth/modules/configValidator.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,9 @@ export default class ConfigValidator implements IConfigValidator {
5757
}
5858
injections.forEach((target, i) => {
5959
injections[i] = this.validateComponent(target, errors);
60-
injections[i].meta.afInitialOrder = injections.length - i; // to keep initial order for sorting later
6160
});
62-
// sort by (injection.meta?.afOrder || 0) * 1000 desc, fallback to initial order in array
63-
return injections.sort(
64-
(a, b) => (
65-
(b.meta?.afOrder ?? 0) * 1000 || b.meta?.afInitialOrder
66-
) - (
67-
(a.meta?.afOrder ?? 0) * 1000 || a.meta?.afInitialOrder
68-
)
69-
);
61+
// sort by injection.meta?.afOrder || 0 desc
62+
return injections;
7063
}
7164

7265
checkCustomFileExists(filePath: string): Array<string> {
@@ -122,11 +115,12 @@ export default class ConfigValidator implements IConfigValidator {
122115

123116
const loginPageInjections: AdminForthConfigCustomization['loginPageInjections'] = {
124117
underInputs: [],
118+
underLoginButton: [],
125119
panelHeader: [],
126120
};
127121

128122
if (this.inputConfig.customization?.loginPageInjections) {
129-
const ALLOWED_LOGIN_INJECTIONS = ['underInputs', 'panelHeader']
123+
const ALLOWED_LOGIN_INJECTIONS = ['underInputs', 'underLoginButton', 'panelHeader']
130124
Object.keys(this.inputConfig.customization.loginPageInjections).forEach((injection) => {
131125
if (ALLOWED_LOGIN_INJECTIONS.includes(injection)) {
132126
loginPageInjections[injection] = this.validateAndListifyInjectionNew(this.inputConfig.customization.loginPageInjections, injection, errors);
@@ -136,7 +130,6 @@ export default class ConfigValidator implements IConfigValidator {
136130
}
137131
});
138132
}
139-
140133
const globalInjections: AdminForthConfigCustomization['globalInjections'] = {
141134
userMenu: [],
142135
header: [],
@@ -814,7 +807,7 @@ export default class ConfigValidator implements IConfigValidator {
814807
});
815808

816809
// if pageInjection is a string, make array with one element. Also check file exists
817-
const possibleInjections = ['beforeBreadcrumbs', 'beforeActionButtons', 'afterBreadcrumbs', 'bottom', 'threeDotsDropdownItems', 'customActionIcons'];
810+
const possibleInjections = ['beforeBreadcrumbs', 'beforeActionButtons', 'afterBreadcrumbs', 'bottom', 'threeDotsDropdownItems', 'customActionIcons'];
818811
const possiblePages = ['list', 'show', 'create', 'edit'];
819812

820813
if (options.pageInjections) {
@@ -904,6 +897,17 @@ export default class ConfigValidator implements IConfigValidator {
904897

905898
}
906899

900+
validateAfterPluginsActivation() {
901+
const ALLOWED_LOGIN_INJECTIONS = ['underInputs', 'underLoginButton', 'panelHeader']
902+
Object.entries(this.adminforth.config.customization).map(([key, value]) => {
903+
Object.entries(value).map(([injection, target]) => {
904+
if (ALLOWED_LOGIN_INJECTIONS.includes(injection)) {
905+
(target as Array<AdminForthComponentDeclarationFull>).sort((a, b) => (b.meta?.afOrder ?? 0) - (a.meta?.afOrder ?? 0));
906+
}
907+
});
908+
})
909+
}
910+
907911
validateConfig() {
908912
const errors = [];
909913
const warnings = [];

adminforth/spa/src/views/LoginView.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
<Button @click="login" :loader="inProgress" :disabled="inProgress || disableLoginButton" class="w-full">
106106
{{ $t('Login to your account') }}
107107
</Button>
108+
<component
109+
v-for="c in coreStore?.config?.loginPageInjections?.underLoginButton || []"
110+
:is="getCustomComponent(c)"
111+
:meta="c.meta"
112+
@update:disableLoginButton="setDisableLoginButton($event)"
113+
/>
108114
</form>
109115
</div>
110116
</div>

adminforth/types/Back.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface ICodeInjector {
2828

2929
export interface IConfigValidator {
3030
validateConfig(): void;
31+
validateAfterPluginsActivation(): void;
3132
postProcessAfterDiscover(resource: AdminForthResource): void;
3233
}
3334

@@ -794,6 +795,7 @@ interface AdminForthInputConfigCustomization {
794795
*/
795796
loginPageInjections?: {
796797
underInputs?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
798+
underLoginButton?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
797799
panelHeader?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
798800
}
799801

@@ -1131,6 +1133,7 @@ export interface AdminForthConfigCustomization extends Omit<AdminForthInputConfi
11311133

11321134
loginPageInjections: {
11331135
underInputs: Array<AdminForthComponentDeclarationFull>,
1136+
underLoginButton?: AdminForthComponentDeclaration | Array<AdminForthComponentDeclaration>,
11341137
panelHeader: Array<AdminForthComponentDeclarationFull>,
11351138
},
11361139

0 commit comments

Comments
 (0)