Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(admin): display social posts count for sharable resources #1056

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions packages/@liexp/core/src/fp/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as A from "fp-ts/Array";
import * as E from "fp-ts/Either";
import * as Eq from 'fp-ts/Eq'
import * as Eq from "fp-ts/Eq";
import * as IOE from "fp-ts/IOEither";
import * as Json from "fp-ts/Json";
import * as Map from "fp-ts/Map";
Expand All @@ -13,6 +13,7 @@ import * as TE from "fp-ts/TaskEither";
import { pipe, flow } from "fp-ts/function";
import * as N from "fp-ts/number";
import * as S from "fp-ts/string";
import * as Void from "fp-ts/void";

export const fp = {
A,
Expand All @@ -28,7 +29,8 @@ export const fp = {
N,
Ord,
Json,
Eq
Eq,
Void,
};

export { pipe, flow };
14 changes: 2 additions & 12 deletions packages/@liexp/shared/src/helpers/event-suggestion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const getSuggestions = (
),
links: [],
keywords: relations.keywords,
socialPosts: [],
createdAt: new Date(),
updatedAt: new Date(),
deletedAt: undefined,
Expand All @@ -80,7 +81,7 @@ export const getSuggestions = (
actors: [],
groups: [],
} as any,
},
}
},
},
{
Expand Down Expand Up @@ -132,17 +133,6 @@ export const getSuggestions = (
},
},
},
// {
// type: http.EventSuggestion.EventSuggestionType.types[0].value,
// event: {
// ...commonSuggestion,
// type: http.Events.EventTypes.DEATH.value,
// payload: {
// victim: uuid() as any,
// location: undefined as any,
// },
// },
// },
{
type: http.EventSuggestion.EventSuggestionType.types[0].value,
event: {
Expand Down
1 change: 1 addition & 0 deletions packages/@liexp/shared/src/helpers/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const getRelationIds = (e: Events.Event): Events.EventRelationIds => {
keywords: e.keywords,
links: e.links,
areas: [],
socialPosts: []
};

switch (e.type) {
Expand Down
1 change: 1 addition & 0 deletions packages/@liexp/shared/src/helpers/event/search-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const getNewRelationIds = (
media: acc.media.concat(newMediaIds),
keywords: acc.keywords.concat(newKeywordIds),
links: acc.links.concat(newLinkIds),
socialPosts: []
};
}),
);
Expand Down
1 change: 1 addition & 0 deletions packages/@liexp/shared/src/io/http/Events/BaseEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const EventCommon = t.strict(
id: UUID,
media: t.array(UUID, "media"),
links: t.array(UUID, "links"),
socialPosts: t.union([t.array(UUID), t.undefined]),
createdAt: DateFromISOString,
updatedAt: DateFromISOString,
deletedAt: t.union([DateFromISOString, t.undefined], "deletedAt"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as t from "io-ts";
import { BooleanFromString } from "io-ts-types/BooleanFromString";
import { DateFromISOString } from "io-ts-types/DateFromISOString";
import { NumberFromString } from 'io-ts-types/NumberFromString';
import { UUID } from "io-ts-types/UUID";
import { optionFromUndefined } from "../../Common/optionFromUndefined";
import { GetListQuery } from "../Query";
Expand Down Expand Up @@ -30,6 +31,8 @@ export const GetSearchEventsQuery = t.strict(
emptyGroups: optionFromUndefined(BooleanFromString),
emptyMedia: optionFromUndefined(BooleanFromString),
emptyLinks: optionFromUndefined(BooleanFromString),
spCount: optionFromUndefined(NumberFromString),
onlyUnshared: optionFromUndefined(BooleanFromString)
},
"GetEventsQueryFilter",
);
Expand Down
2 changes: 2 additions & 0 deletions packages/@liexp/shared/src/io/http/Link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const GetListLinkQuery = t.type(
creator: optionFromNullable(UUID),
emptyEvents: optionFromNullable(BooleanFromString),
onlyDeleted: optionFromNullable(BooleanFromString),
onlyUnshared: optionFromNullable(BooleanFromString),
},
"GetListLinkQuery",
);
Expand Down Expand Up @@ -76,6 +77,7 @@ export const Link = t.strict(
provider: t.union([UUID, t.undefined]),
creator: t.union([UUID, t.undefined]),
events: t.array(UUID),
socialPosts: t.array(UUID),
createdAt: DateFromISOString,
updatedAt: DateFromISOString,
deletedAt: t.union([DateFromISOString, t.undefined]),
Expand Down
4 changes: 4 additions & 0 deletions packages/@liexp/shared/src/io/http/Media.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as t from "io-ts";
import { BooleanFromString } from "io-ts-types/lib/BooleanFromString";
import { DateFromISOString } from "io-ts-types/lib/DateFromISOString";
import { NumberFromString } from 'io-ts-types/lib/NumberFromString';
import { optionFromNullable } from "io-ts-types/lib/optionFromNullable";
import { UUID } from "./Common/UUID";
import { GetListQuery } from "./Query";
Expand Down Expand Up @@ -69,6 +70,8 @@ export const GetListMediaQuery = t.type(
deletedOnly: optionFromNullable(BooleanFromString),
creator: optionFromNullable(UUID),
keywords: optionFromNullable(t.array(UUID)),
spCount: optionFromNullable(NumberFromString),
onlyUnshared: optionFromNullable(BooleanFromString),
},
"MediaListQuery",
);
Expand Down Expand Up @@ -102,6 +105,7 @@ export const Media = t.strict(
type: MediaType,
creator: t.union([UUID, t.undefined]),
featuredIn: t.union([t.array(UUID), t.undefined]),
socialPosts: t.union([t.array(UUID), t.undefined]),
createdAt: DateFromISOString,
updatedAt: DateFromISOString,
deletedAt: t.union([DateFromISOString, t.undefined]),
Expand Down
2 changes: 2 additions & 0 deletions packages/@liexp/shared/src/tests/arbitrary/Event.arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const uncategorizedProps = propsOmit(http.Events.Uncategorized.Uncategorized, [
"media",
"links",
"keywords",
"socialPosts",
"createdAt",
"updatedAt",
"deletedAt",
Expand Down Expand Up @@ -109,4 +110,5 @@ export const UncategorizedArb: fc.Arbitrary<http.Events.Uncategorized.Uncategori
groupsMembers: fc.sample(fc.uuid(), 5) as any[],
endDate: undefined,
},
socialPosts: undefined
}));
2 changes: 2 additions & 0 deletions packages/@liexp/shared/src/tests/arbitrary/Link.arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const linksProps = propsOmit(http.Link.Link, [
"provider",
"keywords",
"events",
"socialPosts",
"createdAt",
"updatedAt",
"deletedAt",
Expand All @@ -40,6 +41,7 @@ export const LinkArb: tests.fc.Arbitrary<http.Link.Link> = tests
keywords: [],
provider: undefined,
creator: undefined,
socialPosts: [],
createdAt: tests.fc.sample(DateArb, 1)[0],
updatedAt: tests.fc.sample(DateArb, 1)[0],
deletedAt: undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/@liexp/shared/src/tests/arbitrary/Media.arbitrary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const mediaProps = propsOmit(http.Media.Media, [
"keywords",
"areas",
"featuredIn",
"socialPosts"
]);

export const placeKitten = (): string => {
Expand All @@ -43,6 +44,7 @@ export const MediaArb: tests.fc.Arbitrary<http.Media.Media> = tests
type: "image/png",
creator: undefined,
extra: undefined,
socialPosts: undefined,
location,
thumbnail,
id: tests.fc.sample(tests.fc.uuid(), 1)[0] as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const PatentEventArb = getArbitrary(
"links",
"keywords",
"payload",
"socialPosts",
"createdAt",
"updatedAt",
"deletedAt",
Expand All @@ -32,6 +33,7 @@ export const PatentEventArb = getArbitrary(
media: fc.sample(fc.uuid(), 5) as any[],
keywords: fc.sample(fc.uuid(), 5) as any[],
links: fc.sample(fc.uuid(), 5) as any[],
socialPosts: [],
payload: {
title: fc.sample(fc.string(), 1)[0],
owners: { groups: [], actors: [] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export const ShareModalContent: React.FC<ShareModalContentProps> = ({
keywords: [],
areas: [],
featuredIn: [],
socialPosts: undefined,
deletedAt: undefined,
label: m.media,
description: m.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { SocialPostDataGrid } from "./SocialPostDatagrid";

export const SocialPostFormTabContent: React.FC<{
source: string;
target: string;
target?: string;
type?: string;
}> = ({ source, target, type }) => {
}> = ({ source, target = 'entity', type }) => {
const record = useRecordContext();
if (!record) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const EditEventForm: React.FC<React.PropsWithChildren<EditProps>> = ({
<ReferenceLinkTab source="links" />
</FormTab>
<FormTab label="SocialPosts">
<SocialPostFormTabContent type="events" source="id" target="entity" />
<SocialPostFormTabContent type="events" source="id" />
</FormTab>
<FormTab label="Flow">
<LazyFormTabContent tab={5}>
Expand Down
9 changes: 9 additions & 0 deletions packages/@liexp/ui/src/components/admin/links/AdminLinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
type RaRecord,
} from "react-admin";
import { Box, Grid, Toolbar } from "../../mui";
import { SocialPostFormTabContent } from '../SocialPost/SocialPostFormTabContent';
import { DangerZoneField } from "../common/DangerZoneField";
import { EditForm } from "../common/EditForm";
import URLMetadataInput from "../common/URLMetadataInput";
Expand All @@ -55,6 +56,7 @@ const linksFilter = [
// </ReferenceArrayInput>,
<BooleanInput key="emptyEvents" source="emptyEvents" alwaysOn />,
<BooleanInput key="onlyDeleted" source="onlyDeleted" alwaysOn />,
<BooleanInput key="onlyUnshared" source="onlyUnshared" alwaysOn />,
];

export const LinkListActions: React.FC = () => {
Expand Down Expand Up @@ -110,6 +112,10 @@ export const LinkDatagrid: React.FC<DatagridProps> = (props) => {
label="resources.links.fields.events_length"
render={(r: any | undefined) => r?.events?.length ?? "-"}
/>
<FunctionField
label="resources.links.fields.social_posts_length"
render={(r: any | undefined) => r?.socialPosts?.length ?? "-"}
/>
<DateField source="updatedAt" />
<DateField source="createdAt" />
</Datagrid>
Expand Down Expand Up @@ -270,6 +276,9 @@ export const LinkEdit: React.FC = () => {
</Datagrid>
</ReferenceManyField>
</FormTab>
<FormTab label="Social Posts">
<SocialPostFormTabContent type='links' source="id" />
</FormTab>
</TabbedForm>
</EditForm>
);
Expand Down
28 changes: 18 additions & 10 deletions packages/@liexp/ui/src/components/admin/media/MediaEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
useRecordContext,
useRefresh,
type EditProps,
type FieldProps
type FieldProps,
} from "react-admin";
import { transformMedia } from "../../../client/admin/MediaAPI";
import { Box, Button, Grid, alpha } from "../../mui";
Expand Down Expand Up @@ -180,7 +180,7 @@ export const MediaEdit: React.FC<EditProps> = (props: EditProps) => {
<TabbedForm
toolbar={<MediaEditToolbar />}
style={{
background: record?.deletedAt ? alpha("#ff0000", .3) : undefined,
background: record?.deletedAt ? alpha("#ff0000", 0.3) : undefined,
}}
>
<FormTab label="general">
Expand All @@ -202,12 +202,24 @@ export const MediaEdit: React.FC<EditProps> = (props: EditProps) => {
<TextInput source="description" fullWidth multiline />
<Box>
<Box>
<DateField label="Updated At" source="updatedAt" showTime={true} />
<DateField
label="Updated At"
source="updatedAt"
showTime={true}
/>
</Box>
<Box>
<DateField label="Created At" source="createdAt" showTime={true} />
<DateField
label="Created At"
source="createdAt"
showTime={true}
/>
</Box>
<DateField label="Deleted At" source="deletedAt" showTime={true} />
<DateField
label="Deleted At"
source="deletedAt"
showTime={true}
/>
</Box>
</Grid>
</Grid>
Expand All @@ -224,11 +236,7 @@ export const MediaEdit: React.FC<EditProps> = (props: EditProps) => {
<ReferenceLinkTab source="links" />
</FormTab>
<FormTab label="social posts">
<SocialPostFormTabContent
target="entity"
source="id"
type={"media"}
/>
<SocialPostFormTabContent type="media" source="id" />
</FormTab>
</TabbedForm>
</EditForm>
Expand Down
9 changes: 9 additions & 0 deletions packages/@liexp/ui/src/components/admin/media/MediaList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
useGetIdentity,
usePermissions,
type ListProps,
NumberInput,
} from "react-admin";
import { Box, Typography, amber } from "../../mui";
import { toFormattedDuration } from "./DurationField";
Expand All @@ -25,6 +26,8 @@ const mediaFilters = [
<TextInput key="description" source="description" alwaysOn size="small" />,
<BooleanInput key="emptyEvents" source="emptyEvents" alwaysOn size="small" />,
<BooleanInput key="emptyLinks" source="emptyLinks" alwaysOn size="small" />,
<BooleanInput key="onlyUnshared" source="onlyUnshared" alwaysOn size="small" />,
<NumberInput key="spCount" label="Social Post Count" source="spCount" size="small" />,
<MediaTypeInput key="type" source="type" alwaysOn size="small" />,
<BooleanInput key="deletedOnly" source="deletedOnly" alwaysOn size="small" />,
];
Expand Down Expand Up @@ -108,6 +111,12 @@ export const MediaDataGrid: React.FC = () => {
return r.links.length;
}}
/>
<FunctionField
label="social_posts"
render={(r: any) => {
return r.socialPosts?.length ?? 0;
}}
/>

<DateField source="updatedAt" />
<DateField source="createdAt" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
import { uploadImages } from "../../../client/admin/MediaAPI";
import { Box, Grid } from "../../mui";
import ReactPageInput from "../ReactPageInput";
import { SocialPostFormTabContent } from '../SocialPost/SocialPostFormTabContent';
import { EditForm } from "../common/EditForm";
import ReferenceArrayKeywordInput from "../keywords/ReferenceArrayKeywordInput";
import ReferenceMediaInput from "../media/input/ReferenceMediaInput";
Expand Down Expand Up @@ -166,6 +167,9 @@ export const StoryEdit: React.FC<EditProps> = (props) => {
<FormTab label="Relations">
<StoryRelationsBox />
</FormTab>
<FormTab label="Social Posts">
<SocialPostFormTabContent type="stories" source='id' />
</FormTab>
</TabbedForm>
</EditForm>
);
Expand Down
1 change: 1 addition & 0 deletions packages/@liexp/ui/src/i18n/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default {
name: "Link |||| Links",
fields: {
events_length: "N of events",
social_posts_length: "N of social posts"
},
actions: {
update_metadata: "Update URL Metadata",
Expand Down
1 change: 1 addition & 0 deletions packages/@liexp/ui/src/templates/links/LinkTemplateUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const LinkTemplateUI: React.FC<LinkTemplateUIProps> = ({
updatedAt: new Date(),
deletedAt: undefined,
extra: undefined,
socialPosts: undefined,
}}
itemStyle={{ maxHeight: 200, minHeight: 200, width: "100%" }}
disableZoom
Expand Down
Loading