Skip to content

Commit

Permalink
actually revert
Browse files Browse the repository at this point in the history
  • Loading branch information
ncovercash committed Dec 21, 2023
1 parent 3199f9b commit 0b36f6f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 96 deletions.
34 changes: 15 additions & 19 deletions src/views/AllCalendarView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import {
Icon,
LoadingPane,
MenuSection,
Pane,
Pane
} from '@folio/stripes/components';
import { IfPermission, useStripes } from '@folio/stripes/core';
import { IfPermission, useStripes, TitleManager } from '@folio/stripes/core';
import React, { FunctionComponent, ReactNode, useRef, useState } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import {
Route,
RouteComponentProps,
Switch,
useHistory,
useRouteMatch,
useRouteMatch
} from 'react-router-dom';
import SortableMultiColumnList from '../components/SortableMultiColumnList';
import useDataRepository from '../data/useDataRepository';
Expand All @@ -26,8 +26,6 @@ import ifPermissionOr from '../utils/ifPermissionOr';
import CreateEditCalendarLayer from './CreateEditCalendarLayer';
import InfoPane from './panes/InfoPane';

const TitleManager = (props: any) => <>{props.children}</>;

const AllCalendarView: FunctionComponent<Record<string, never>> = () => {
const intl = useIntl();
const stripes = useStripes();
Expand All @@ -37,22 +35,22 @@ const AllCalendarView: FunctionComponent<Record<string, never>> = () => {
const showCreateLayerButtonRef = useRef<HTMLButtonElement>(null);
const history = useHistory();
const currentRouteId = useRouteMatch<{ calendarId: string }>(
'/settings/calendar/all/:calendarId',
'/settings/calendar/all/:calendarId'
)?.params?.calendarId;

if (!dataRepository.isLoaded()) {
return (
<LoadingPane
paneTitle={intl.formatMessage({
id: 'ui-calendar.allCalendarView.title',
id: 'ui-calendar.allCalendarView.title'
})}
/>
);
}

const rows = dataRepository.getCalendars().map((calendar) => {
const servicePointNames = dataRepository.getServicePointNamesFromIds(
calendar.assignments,
calendar.assignments
);
return {
name: calendar.name,
Expand All @@ -67,21 +65,19 @@ const AllCalendarView: FunctionComponent<Record<string, never>> = () => {
<FormattedMessage id="ui-calendar.allCalendarView.noAssignments" />
</div>
),
calendar,
calendar
};
});

const calendarName = dataRepository
.getCalendars()
.filter((c) => c.id === currentRouteId)[0]?.name;

const pageTitle =
intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' }) +
' - ' +
intl.formatMessage({
id: 'ui-calendar.allCalendarView.title',
}) +
(calendarName ? ` - ${calendarName}` : '');
const pageTitle = intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' }) +
' - ' + intl.formatMessage({
id: 'ui-calendar.allCalendarView.title'
}) + (calendarName ? ` - ${calendarName}` : '');


return (
<TitleManager page={pageTitle} stripes={stripes}>
Expand Down Expand Up @@ -122,7 +118,7 @@ const AllCalendarView: FunctionComponent<Record<string, never>> = () => {
</Icon>
</Button>
</IfPermission>
</MenuSection>,
</MenuSection>
);
}}
>
Expand Down Expand Up @@ -154,7 +150,7 @@ const AllCalendarView: FunctionComponent<Record<string, never>> = () => {
),
assignments: (
<FormattedMessage id="ui-calendar.allCalendarView.column.assignments" />
),
)
}}
contentData={rows}
rowMetadata={['calendar', 'startDateObj', 'endDateObj']}
Expand All @@ -180,7 +176,7 @@ const AllCalendarView: FunctionComponent<Record<string, never>> = () => {
<CreateEditCalendarLayer
dataRepository={dataRepository}
initialValue={dataRepository.getCalendar(
new URLSearchParams(location.search).get('source'),
new URLSearchParams(location.search).get('source')
)}
onClose={(id = '') => {
history.push(`/settings/calendar/all/${id}`);
Expand Down
21 changes: 7 additions & 14 deletions src/views/CalendarSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { ErrorBoundary } from '@folio/stripes/components';
import { Settings, SettingsProps } from '@folio/stripes/smart-components';
import React, { FunctionComponent } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import {
FooBar as TitleManager,
IfPermission,
useStripes,
} from '@folio/stripes/core';
import { TitleManager, useStripes } from '@folio/stripes/core';
import AllCalendarView from './AllCalendarView';
import CurrentAssignmentView from './CurrentAssignmentView';
import MonthlyCalendarPickerView from './MonthlyCalendarPickerView';
Expand All @@ -17,17 +13,14 @@ export type CalendarSettingsProps = Omit<
>;

export const CalendarSettings: FunctionComponent<CalendarSettingsProps> = (
props: CalendarSettingsProps,
props: CalendarSettingsProps
) => {
const intl = useIntl();
const stripes = useStripes();
const paneTitle = intl.formatMessage({
id: 'ui-calendar.meta.titleSettings',
});
const paneTitle = intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' });

return (
<ErrorBoundary>
<IfPermission perm="foo">bar</IfPermission>
<Settings
{...props}
navPaneWidth="30%"
Expand All @@ -40,24 +33,24 @@ export const CalendarSettings: FunctionComponent<CalendarSettingsProps> = (
</TitleManager>
),
component: AllCalendarView,
perm: 'ui-calendar.view',
perm: 'ui-calendar.view'
},
{
route: 'active/',
label: (
<FormattedMessage id="ui-calendar.currentAssignmentView.title" />
),
component: CurrentAssignmentView,
perm: 'ui-calendar.view',
perm: 'ui-calendar.view'
},
{
route: 'monthly/',
label: (
<FormattedMessage id="ui-calendar.monthlyCalendarView.title" />
),
component: MonthlyCalendarPickerView,
perm: 'ui-calendar.view',
},
perm: 'ui-calendar.view'
}
]}
paneTitle={<FormattedMessage id="ui-calendar.meta.title" />}
/>
Expand Down
20 changes: 8 additions & 12 deletions src/views/CreateEditCalendarLayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import {
PaneFooter,
Paneset,
} from '@folio/stripes/components';
import { useStripes } from '@folio/stripes/core';
import { TitleManager, useStripes } from '@folio/stripes/core';
import React, { FunctionComponent, useState } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import DataRepository from '../data/DataRepository';
import CalendarForm, { FORM_ID } from '../forms/CalendarForm/CalendarForm';
import { Calendar } from '../types/types';

const TitleManager = (props: any) => <>{props.children}</>;

export interface CreateEditCalendarLayerProps {
dataRepository: DataRepository;
onClose: (id?: string) => void;
Expand Down Expand Up @@ -113,15 +111,13 @@ export const CreateEditCalendarLayer: FunctionComponent<
);
}

const pageTitle =
intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' }) +
' - ' +
intl.formatMessage({
id:
getOpType(props.initialValue, props.isEdit) === OpType.EDIT
? 'ui-calendar.calendarForm.title.edit'
: 'ui-calendar.calendarForm.title.create',
});
const pageTitle = intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' }) +
' - ' + intl.formatMessage({
id:
getOpType(props.initialValue, props.isEdit) === OpType.EDIT
? 'ui-calendar.calendarForm.title.edit'
: 'ui-calendar.calendarForm.title.create',
});

return (
<TitleManager page={pageTitle} stripes={stripes}>
Expand Down
50 changes: 20 additions & 30 deletions src/views/CurrentAssignmentView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Button, LoadingPane, Pane, PaneMenu } from '@folio/stripes/components';
import { IfPermission, useStripes } from '@folio/stripes/core';
import { IfPermission, TitleManager, useStripes } from '@folio/stripes/core';
import React, { FunctionComponent, ReactNode, useRef } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import {
Route,
RouteComponentProps,
Switch,
useHistory,
useRouteMatch,
useRouteMatch
} from 'react-router-dom';
import SortableMultiColumnList from '../components/SortableMultiColumnList';
import useDataRepository from '../data/useDataRepository';
Expand All @@ -16,15 +16,13 @@ import { Calendar } from '../types/types';
import {
dateFromYYYYMMDD,
getLocalizedDate,
isBetweenDatesByDay,
isBetweenDatesByDay
} from '../utils/DateUtils';
import getStatus from '../utils/getCurrentStatus';
import { useLocaleWeekdays } from '../utils/WeekdayUtils';
import CreateEditCalendarLayer from './CreateEditCalendarLayer';
import InfoPane from './panes/InfoPane';

const TitleManager = (props: any) => <>{props.children}</>;

export const CurrentAssignmentView: FunctionComponent<
Record<string, never>
> = () => {
Expand All @@ -35,10 +33,9 @@ export const CurrentAssignmentView: FunctionComponent<

const showCreateLayerButtonRef = useRef<HTMLButtonElement>(null);
const history = useHistory();
const currentRouteId =
useRouteMatch<{ servicePointId: string }>(
'/settings/calendar/active/:servicePointId',
)?.params?.servicePointId ?? '';
const currentRouteId = useRouteMatch<{ servicePointId: string }>(
'/settings/calendar/active/:servicePointId'
)?.params?.servicePointId ?? '';

if (!dataRepository.isLoaded()) {
return (
Expand All @@ -56,14 +53,14 @@ export const CurrentAssignmentView: FunctionComponent<
isBetweenDatesByDay(
new Date(),
dateFromYYYYMMDD(calendar.startDate),
dateFromYYYYMMDD(calendar.endDate),
dateFromYYYYMMDD(calendar.endDate)
) && calendar.assignments.includes(servicePoint.id)
);
});
if (calendars.length === 0) {
return {
servicePoint: servicePoint.name.concat(
servicePoint.inactive ? ' (inactive)' : '',
servicePoint.inactive ? ' (inactive)' : ''
),
servicePointId: servicePoint.id,
calendarName: (
Expand All @@ -76,38 +73,31 @@ export const CurrentAssignmentView: FunctionComponent<
endDate: '',
endDateObj: undefined,
currentStatus: intl.formatMessage({
id: 'ui-calendar.currentStatus.closed.noNext',
id: 'ui-calendar.currentStatus.closed.noNext'
}),
calendar: null,
calendar: null
};
}
return {
servicePointId: servicePoint.id,
servicePoint: servicePoint.name.concat(
servicePoint.inactive ? ' (inactive)' : '',
servicePoint.inactive ? ' (inactive)' : ''
),
calendarName: calendars[0].name,
startDate: getLocalizedDate(intl, calendars[0].startDate),
startDateObj: dateFromYYYYMMDD(calendars[0].startDate),
endDate: getLocalizedDate(intl, calendars[0].endDate),
endDateObj: dateFromYYYYMMDD(calendars[0].endDate),
currentStatus: getStatus(intl, localeWeekdays, new Date(), calendars[0]),
calendar: calendars[0],
calendar: calendars[0]
};
});

const calendarName =
dataRepository
.getCalendars()
.filter((c) => c.assignments.includes(currentRouteId))[0]?.name ?? '';
const calendarName = dataRepository.getCalendars().filter((c) => c.assignments.includes(currentRouteId))[0]?.name ?? '';

const pageTitle =
intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' }) +
' - ' +
intl.formatMessage({
id: 'ui-calendar.currentAssignmentView.title',
}) +
(calendarName ? ` - ${calendarName}` : '');
const pageTitle = intl.formatMessage({ id: 'ui-calendar.meta.titleSettings' }) + ' - ' + intl.formatMessage({
id: 'ui-calendar.currentAssignmentView.title'
}) + (calendarName ? ` - ${calendarName}` : '');

return (
<TitleManager page={pageTitle} stripes={stripes}>
Expand Down Expand Up @@ -163,15 +153,15 @@ export const CurrentAssignmentView: FunctionComponent<
<FormattedMessage id="ui-calendar.currentAssignmentView.column.endDate" />
),
currentStatus: intl.formatMessage({
id: 'ui-calendar.currentAssignmentView.column.currentStatus',
}),
id: 'ui-calendar.currentAssignmentView.column.currentStatus'
})
}}
contentData={rows}
rowMetadata={[
'servicePointId',
'calendar',
'startDateObj',
'endDateObj',
'endDateObj'
]}
isSelected={({ item }) => {
return (
Expand Down Expand Up @@ -202,7 +192,7 @@ export const CurrentAssignmentView: FunctionComponent<
<CreateEditCalendarLayer
dataRepository={dataRepository}
initialValue={dataRepository.getCalendar(
new URLSearchParams(location.search).get('source'),
new URLSearchParams(location.search).get('source')
)}
onClose={(id = '') => {
history.push(`/settings/calendar/active/${id}`);
Expand Down
Loading

0 comments on commit 0b36f6f

Please sign in to comment.