Skip to content

Commit

Permalink
add project Social media and replace relation in projectsTab
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed Dec 2, 2024
1 parent 7e812ff commit 5728a2a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class Project extends BaseEntity {

@Field(_type => [ProjectSocialMedia], { nullable: true })
@OneToMany(_type => ProjectSocialMedia, socialMedia => socialMedia.project, {
eager: false,
eager: true,
})
socialMedia?: ProjectSocialMedia[];

Expand Down
2 changes: 2 additions & 0 deletions src/server/adminJs/adminJs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { SybilTab } from './tabs/sybilTab';
import { ProjectFraudTab } from './tabs/projectFraudTab';
import { RecurringDonationTab } from './tabs/recurringDonationTab';
import { AnchorContractAddressTab } from './tabs/anchorContractAddressTab';
import { projectSocialMediaTab } from './tabs/projectSocialMediaTab';
// use redis for session data instead of in-memory storage
// eslint-disable-next-line @typescript-eslint/no-var-requires
const RedisStore = require('connect-redis').default;
Expand Down Expand Up @@ -151,6 +152,7 @@ const getResources = async (): Promise<AdminJsResources> => {
ProjectFraudTab,
RecurringDonationTab,
AnchorContractAddressTab,
projectSocialMediaTab,
];

const loggingHook = async (response, request, context) => {
Expand Down
64 changes: 64 additions & 0 deletions src/server/adminJs/tabs/projectSocialMediaTab.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ProjectSocialMedia } from '../../../entities/projectSocialMedia';
import {
canAccessMainCategoryAction,
ResourceActions,
} from '../adminJsPermissions';

export const projectSocialMediaTab = {
resource: ProjectSocialMedia,
options: {
actions: {
list: {
isVisible: true,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.LIST),
},
show: {
isVisible: true,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.SHOW),
},
delete: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.DELETE),
},
new: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.NEW),
},
edit: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.EDIT),
},
},
properties: {
id: {
isVisible: {
list: true,
filter: true,
show: true,
edit: false,
new: false,
},
},
type: {
isVisible: true,
},
link: {
isVisible: true,
},
slug: {
isVisible: true,
},
project: {
isVisible: true,
},
user: {
isVisible: true,
},
},
},
};
27 changes: 11 additions & 16 deletions src/server/adminJs/tabs/projectsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
refreshProjectPowerView,
} from '../../../repositories/projectPowerViewRepository';
import { logger } from '../../../utils/logger';
import { findSocialProfilesByProjectId } from '../../../repositories/socialProfileRepository';
import { findProjectUpdatesByProjectId } from '../../../repositories/projectUpdateRepository';
import {
AdminJsContextInterface,
Expand Down Expand Up @@ -451,7 +450,6 @@ export const fillSocialProfileAndQfRounds: After<
// both cases for projectVerificationForms and projects' ids
const projectId = record.params.projectId || record.params.id;

const socials = await findSocialProfilesByProjectId({ projectId });
const projectUpdates = await findProjectUpdatesByProjectId(projectId);
const project = await findProjectById(projectId);
const adminJsBaseUrl = process.env.SERVER_URL;
Expand All @@ -470,7 +468,6 @@ export const fillSocialProfileAndQfRounds: After<
projectUrl: `${process.env.GIVETH_IO_DAPP_BASE_URL}/project/${
project!.slug
}`,
socials,
qfRounds: project?.qfRounds,
projectUpdates,
adminJsBaseUrl,
Expand Down Expand Up @@ -674,19 +671,6 @@ export const projectsTab = {
statusId: {
isVisible: { list: true, filter: true, show: true, edit: true },
},
socials: {
type: 'mixed',
isVisible: {
list: false,
filter: false,
show: true,
edit: false,
new: false,
},
components: {
show: adminJs.bundle('./components/VerificationFormSocials'),
},
},
adminUserId: {
type: 'Number',
isVisible: {
Expand Down Expand Up @@ -814,6 +798,17 @@ export const projectsTab = {
edit: false,
},
},
socialMedia: {
type: 'reference',
isArray: true,
reference: 'ProjectSocialMedia',
isVisible: {
list: false,
filter: false,
show: true,
edit: false,
},
},
categoryIds: {
type: 'reference',
isArray: true,
Expand Down

0 comments on commit 5728a2a

Please sign in to comment.