Skip to content
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
46 changes: 37 additions & 9 deletions src/renderer/src/components/AssignSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ import { AddRecord, UpdateRelatedRecord } from '../model/baseModel';
import { AltButton, GrowingSpacer, PriButton } from '../control';
import { useOrbitData } from '../hoc/useOrbitData';
import { useSelector } from 'react-redux';
import { assignSectionSelector, sharedSelector } from '../selector';
import {
assignSectionSelector,
assignmentSelector,
sharedSelector,
} from '../selector';
import { useSnackBar } from '../hoc/SnackBar';
import { IAssignmentTableStrings } from '../model';
import GroupOrUserAssignment from '../control/GroupOrUserAssignment';
import { OrganizationSchemeD } from '../model/organizationScheme';
import { waitForIt } from '../utils/waitForIt';
Expand Down Expand Up @@ -68,7 +74,12 @@ function AssignSection(props: IProps) {
assignSectionSelector,
shallowEqual
);
const tAssign: IAssignmentTableStrings = useSelector(
assignmentSelector,
shallowEqual
);
const ts: ISharedStrings = useSelector(sharedSelector, shallowEqual);
const { showMessage } = useSnackBar();
const allOrgSteps = useOrbitData<OrgWorkflowStepD[]>('orgworkflowstep');
const schemes = useOrbitData<OrganizationSchemeD[]>('organizationscheme');
const steps = useOrbitData<OrganizationSchemeStepD[]>(
Expand Down Expand Up @@ -274,9 +285,15 @@ function AssignSection(props: IProps) {
return schemeRec.id as string;
};

const doAssign = async (schemeId: string) => {
if (!sections.some((s) => related(s, 'organizationScheme') !== schemeId))
return;
const doAssign = async (schemeId: string): Promise<boolean> => {
if (sections.length === 0) {
showMessage(tAssign.selectRowsToAssign);
return false;
}
Comment thread
gtryus marked this conversation as resolved.
const needsLink = sections.some(
(s) => related(s, 'organizationScheme') !== schemeId
);
if (!needsLink) return true;
const ids = sections.map(
(s) => remoteId('section', s.id, memory.keyMap as RecordKeyMap) as string
);
Expand All @@ -286,8 +303,11 @@ function AssignSection(props: IProps) {
'organizationscheme',
schemeId
) as OrganizationSchemeD;
const id = await waitForRemoteId(schemeRec, memory.keyMap as RecordKeyMap);
try {
const id = await waitForRemoteId(
schemeRec,
memory.keyMap as RecordKeyMap
);
await axiosPatch(`sections/assign/${id}/${list}`, undefined, token);
await pullTableList(
'section',
Expand All @@ -297,8 +317,11 @@ function AssignSection(props: IProps) {
backup,
errorReporter
);
return true;
} catch (err) {
logError(Severity.error, errorReporter, err as Error);
showMessage((err as Error).message);
return false;
}
};

Expand Down Expand Up @@ -351,10 +374,15 @@ function AssignSection(props: IProps) {
const confirmClose = async () => {
setSaving(true);
setBusy(true);
const schemeId = await handleAdd();
await doAssign(schemeId);
setBusy(false);
justClose();
try {
const schemeId = await handleAdd();
const ok = await doAssign(schemeId);
if (!ok) return;
justClose();
} finally {
setBusy(false);
setSaving(false);
}
};

const handleClose = async () => {
Expand Down
32 changes: 11 additions & 21 deletions src/renderer/src/components/AssignmentTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
} from '@mui/x-data-grid';
import { TreeDataGrid } from './TreeDataGrid';
import { pad2 } from '../utils/pad2';
import { resolveSelectedSections } from './resolveSectionForRecId';

const AssignmentDiv = styled('div')(() => ({
display: 'flex',
Expand Down Expand Up @@ -353,17 +354,9 @@ export function AssignmentTable() {
if (check.length === 0) {
showMessage(t.selectRowsToRemove);
} else {
let count = 0;
check.forEach((recId) => {
const row = data.find((r) => r.recId === recId);
if (!row) return;
const sectId = row.scheme as string;
if (!sectId) return;
const section = sections.find((s) => s.id === sectId);
if (!section) return;
const schemeId = related(section, 'organizationScheme');
if (schemeId) count++;
});
const count = selectedSections.filter((s) =>
related(s, 'organizationScheme')
).length;
if (count === 0) {
showMessage(t.selectRowsToRemove);
} else {
Expand All @@ -387,7 +380,7 @@ export function AssignmentTable() {
t,
s as RecordIdentity,
'organizationScheme',
'user',
'organizationscheme',
''
),
...UpdateLastModifiedBy(
Expand All @@ -413,7 +406,7 @@ export function AssignmentTable() {
setCheck([]);
setSelectedSections([]);
setSelectedRows({ type: 'include', ids: new Set() });
setRefresh(refresh + 1);
setRefresh((n) => n + 1);
};
const handleRemoveAssignmentsRefused = () => setConfirmAction('');

Expand Down Expand Up @@ -478,13 +471,10 @@ export function AssignmentTable() {
]);

useEffect(() => {
const selected = Array<SectionD>();
check.forEach((recId) => {
const section = sections.find((s) => s.id === recId);
if (section !== undefined) selected.push(section);
});
setSelectedSections(selected);
}, [check, sections]);
setSelectedSections(
resolveSelectedSections(check, data, sections, passages)
);
}, [check, sections, data, passages]);

const sortModel: GridSortModel = [{ field: 'sort', sort: 'asc' }];
const columnVisibilityModel: GridColumnVisibilityModel = { sort: false };
Expand Down Expand Up @@ -568,7 +558,7 @@ export function AssignmentTable() {
scheme={assignSectionVisible}
visible={assignSectionVisible != null}
closeMethod={handleCloseAssignSection}
refresh={() => setRefresh(refresh + 1)}
refresh={() => setRefresh((n) => n + 1)}
readOnly={readOnly}
inChange={hasAssignmentChange(assignSectionVisible)}
/>
Expand Down
11 changes: 2 additions & 9 deletions src/renderer/src/components/PlanTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
levScrColNames,
levGenColNames,
MediaFileD,
OrganizationD,
} from '../model';
import { AppBar, Tabs, Tab, Box } from '@mui/material';
import ScriptureTable from './Sheet/ScriptureTable';
Expand All @@ -24,7 +23,7 @@ import {
useOrganizedBy,
useMediaCounts,
useSectionCounts,
isPersonalTeam,
useShowAssignment,
} from '../crud';
import { HeadHeight } from '../App';
import { useMobile } from '../utils';
Expand Down Expand Up @@ -61,13 +60,7 @@ const ScrollableTabsButtonAuto = (props: IProps) => {
sections,
passages
);
const [team] = useGlobal('organization');
const teams = useOrbitData<OrganizationD[]>('organization');

const showAssign = useMemo(
() => !isPersonalTeam(team, teams) && !offlineOnly,
[team, teams, offlineOnly]
);
const showAssign = useShowAssignment();

const colNames = React.useMemo(() => {
return scripture && flat
Expand Down
112 changes: 102 additions & 10 deletions src/renderer/src/components/Sheet/PlanBar.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,39 @@ const createMockLiveQuery = () => ({
query: () => [],
});

const mockMemory = {
cache: {
query: () => [],
liveQuery: createMockLiveQuery,
const createMockMemory = (organizations: any[] = []) =>
({
cache: {
query: () => [],
liveQuery: (queryBuildFn: (q: any) => any) => {
const q = {
findRecords: (type: string) => {
if (type === 'organization') return organizations;
return [];
},
};
const records = queryBuildFn(q);
return {
subscribe: () => () => {},
query: () => records,
};
},
},
update: () => {},
}) as unknown as Memory;

let currentTestMemory: Memory = createMockMemory();

const personalTeamOrgs = [
{
id: 'org-1',
type: 'organization',
attributes: { name: '>Test User Personal<' },
},
update: () => {},
} as unknown as Memory;
];

const mockCoordinator = {
getSource: () => mockMemory,
getSource: () => currentTestMemory,
} as unknown as Coordinator;

// Mock Redux selectors
Expand Down Expand Up @@ -128,7 +151,7 @@ describe('PlanBar', () => {
coordinator: mockCoordinator,
errorReporter: bugsnagClient,
fingerprint: 'test-fingerprint',
memory: mockMemory,
memory: currentTestMemory,
lang: 'en',
latestVersion: '',
loadComplete: false,
Expand Down Expand Up @@ -253,8 +276,10 @@ describe('PlanBar', () => {
rowInfo: ISheet[];
},
planContextOverrides = {},
globalStateOverrides = {}
globalStateOverrides = {},
organizations: any[] = []
) => {
currentTestMemory = createMockMemory(organizations);
const initialState = createInitialState(globalStateOverrides);
const planContextState = createMockPlanContextState(planContextOverrides);
const unsavedState = {
Expand All @@ -264,7 +289,7 @@ describe('PlanBar', () => {
cy.mount(
<Provider store={mockStore}>
<GlobalProvider init={initialState}>
<DataProvider dataStore={mockMemory}>
<DataProvider dataStore={currentTestMemory}>
<PlanContext.Provider
value={{
state: planContextState as any,
Expand Down Expand Up @@ -766,4 +791,71 @@ describe('PlanBar', () => {
}
});
});

it('should not show assignedToMe filter for personal audio projects', () => {
const filterState = createMockFilterState();
const orgSteps = createMockOrgSteps();
const rowInfo = createMockRowInfo(2);

mountPlanBar(
{
publishingOn: false,
hidePublishing: true,
handlePublishToggle: mockHandlePublishToggle,
data: [1, 2],
canSetDefault: false,
filterState,
onFilterChange: mockOnFilterChange,
orgSteps,
minimumSection: 1,
maximumSection: 10,
filtered: true,
rowInfo,
},
{},
{ organization: 'org-1' },
personalTeamOrgs
);

cy.wait(100);
cy.get('#filterMenu', { timeout: 5000 }).click();
cy.get('#assignedToMe').should('not.exist');
});

it('should show assignedToMe filter for team projects', () => {
const filterState = createMockFilterState();
const orgSteps = createMockOrgSteps();
const rowInfo = createMockRowInfo(2);
const teamOrgs = [
{
id: 'org-1',
type: 'organization',
attributes: { name: 'My Team' },
},
];

mountPlanBar(
{
publishingOn: false,
hidePublishing: true,
handlePublishToggle: mockHandlePublishToggle,
data: [1, 2],
canSetDefault: false,
filterState,
onFilterChange: mockOnFilterChange,
orgSteps,
minimumSection: 1,
maximumSection: 10,
filtered: true,
rowInfo,
},
{},
{ organization: 'org-1' },
teamOrgs
);

cy.wait(100);
cy.get('#filterMenu', { timeout: 5000 }).click();
cy.get('#assignedToMe').should('exist');
});
});
11 changes: 2 additions & 9 deletions src/renderer/src/components/Sheet/PlanSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
ISheet,
OrgWorkflowStep,
SheetLevel,
OrganizationD,
} from '../../model';
import {
Box,
Expand Down Expand Up @@ -64,7 +63,7 @@ import {
useCheckOnline,
} from '../../utils';
import {
isPersonalTeam,
useShowAssignment,
PublishDestinationEnum,
remoteIdGuid,
usePublishDestination,
Expand All @@ -85,7 +84,6 @@ import { usePlanSheetFill } from './usePlanSheetFill';
import { useShowIcon } from './useShowIcon';
import { RecordKeyMap } from '@orbit/records';
import ConfirmPublishDialog from '../ConfirmPublishDialog';
import { useOrbitData } from '../../hoc/useOrbitData';
import { findPlanSheetRowFromReferenceQuery } from './findPlanSheetRowFromReferenceQuery';
import { useOrganizedBy } from '../../crud/useOrganizedBy';

Expand Down Expand Up @@ -353,15 +351,10 @@ export function PlanSheet(props: IProps) {
const moveUp = true;
const moveDown = false;
const moveToNewSection = true;
const [org] = useGlobal('organization');
const getGlobal = useGetGlobal();
const teams = useOrbitData<OrganizationD[]>('organization');
const checkOnline = useCheckOnline('PlanSheet');

const showAssign = useMemo(
() => !isPersonalTeam(org, teams) && !offlineOnly,
[org, teams, offlineOnly]
);
const showAssign = useShowAssignment();

useEffect(() => {
if (!goToOpen) return;
Expand Down
Loading
Loading