Skip to content

Commit

Permalink
fix: lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed Oct 7, 2024
1 parent 26b4467 commit 5f5ae2b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 42 deletions.
46 changes: 23 additions & 23 deletions src/library-authoring/component-info/ManageCollections.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { useContext, useEffect, useState } from 'react';
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';
import { Button, Icon, Scrollable, SelectableBox, Stack, useCheckboxSetValues } from '@openedx/paragon';
import {
Button, Icon, Scrollable, SelectableBox, Stack, useCheckboxSetValues,
} from '@openedx/paragon';
import { Folder } from '@openedx/paragon/icons';

import {
Expand Down Expand Up @@ -41,8 +43,8 @@ const CollectionsSelectableBox = ({ contentHit, onClose }: CollectionsDrawerProp

return () => {
clear();
}
}, [contentHit])
};
}, [contentHit]);

const updateCollectionsMutation = useUpdateComponentCollections(contentHit.contextKey, contentHit.usageKey);

Expand All @@ -53,15 +55,13 @@ const CollectionsSelectableBox = ({ contentHit, onClose }: CollectionsDrawerProp
}).catch(() => {
showToast(intl.formatMessage(messages.manageCollectionsToComponentFailed));
});
}

const handleChange = (e) => {
e.target.checked ? add(e.target.value) : remove(e.target.value);
};

const handleChange = (e) => (e.target.checked ? add(e.target.value) : remove(e.target.value));

return (
<Stack gap={4}>
<Scrollable className="mt-3 p-1 border-bottom border-gray-100" style={{ 'height': '25vh' }}>
<Scrollable className="mt-3 p-1 border-bottom border-gray-100" style={{ height: '25vh' }}>
<SelectableBox.Set
value={selectedCollections}
type={type}
Expand All @@ -70,24 +70,24 @@ const CollectionsSelectableBox = ({ contentHit, onClose }: CollectionsDrawerProp
columns={1}
ariaLabelledby={intl.formatMessage(messages.manageCollectionsSelectionLabel)}
>
{collectionHits.map((contentHit) => (
{collectionHits.map((collectionHit) => (
<SelectableBox
className="d-inline-flex align-items-center shadow-none border border-gray-100"
value={contentHit.blockId}
key={contentHit.blockId}
value={collectionHit.blockId}
key={collectionHit.blockId}
inputHidden={false}
type={type}
aria-label={contentHit.displayName}
aria-label={collectionHit.displayName}
>
<Stack className="ml-2" direction="horizontal" gap={2}>
<Icon src={Folder} />
<span>{contentHit.displayName}</span>
<span>{collectionHit.displayName}</span>
</Stack>
</SelectableBox>
))}
</SelectableBox.Set>
</Scrollable>
<Stack direction='horizontal' gap={2}>
<Stack direction="horizontal" gap={2}>
<Button
onClick={onClose}
variant="outline-primary"
Expand All @@ -104,7 +104,7 @@ const CollectionsSelectableBox = ({ contentHit, onClose }: CollectionsDrawerProp
</Stack>
</Stack>
);
}
};

const AddToCollectionsDrawer = ({ contentHit, onClose }: CollectionsDrawerProps) => {
const intl = useIntl();
Expand Down Expand Up @@ -138,8 +138,8 @@ const AddToCollectionsDrawer = ({ contentHit, onClose }: CollectionsDrawerProps)
/>
</Stack>
</SearchContextProvider>
)
}
);
};

const ComponentCollections = ({ collections, onManageClick }: {
collections?: string[];
Expand All @@ -164,7 +164,7 @@ const ComponentCollections = ({ collections, onManageClick }: {
}

return (
<Stack gap={4} className='mt-2'>
<Stack gap={4} className="mt-2">
{collections.map((collection) => (
<Stack
className="border-bottom pb-4 border-gray-100"
Expand All @@ -184,17 +184,17 @@ const ComponentCollections = ({ collections, onManageClick }: {
</Button>
</Stack>
);
}
};

const ManageCollections = ({ contentHit }: ManageCollectionsProps) => {
const { data, isLoading } = useGetDocumentByBlockId(
contentHit.contextKey,
contentHit.blockId
) as { data: ContentHit, isLoading: boolean};
contentHit.blockId,
) as { data: ContentHit, isLoading: boolean };
const [editing, setEditing] = useState(false);

if (isLoading) {
return <Loading />
return <Loading />;
}

if (editing) {
Expand All @@ -212,6 +212,6 @@ const ManageCollections = ({ contentHit }: ManageCollectionsProps) => {
onManageClick={() => setEditing(true)}
/>
);
}
};

export default ManageCollections;
6 changes: 2 additions & 4 deletions src/library-authoring/data/apiHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,7 @@ export const useUpdateCollectionComponents = (libraryId?: string, collectionId?:
export const useUpdateComponentCollections = (libraryId: string, usageKey: string) => {
const queryClient = useQueryClient();
return useMutation({
mutationFn: async (collectionKeys: string[]) => {
return updateComponentCollections(usageKey, collectionKeys);
},
mutationFn: async (collectionKeys: string[]) => updateComponentCollections(usageKey, collectionKeys),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onSettled: (_data, _error, _variables) => {
queryClient.invalidateQueries({ predicate: (query) => libraryQueryPredicate(query, libraryId) });
Expand All @@ -334,7 +332,7 @@ export const useUpdateComponentCollections = (libraryId: string, usageKey: strin
return false;
}
return queryLibId === libraryId;
}
},
});
},
});
Expand Down
23 changes: 12 additions & 11 deletions src/search-manager/SearchManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export const SearchContextProvider: React.FC<{
closeSearchModal?: () => void,
overrideQueries?: OverrideQueries,
skipUrlUpdate?: boolean,
}> = ({ overrideSearchSortOrder, overrideQueries, skipUrlUpdate, ...props }) => {
}> = ({
overrideSearchSortOrder, overrideQueries, skipUrlUpdate, ...props
}) => {
const [searchKeywords, setSearchKeywords] = React.useState('');
const [blockTypesFilter, setBlockTypesFilter] = React.useState<string[]>([]);
const [problemTypesFilter, setProblemTypesFilter] = React.useState<string[]>([]);
Expand All @@ -105,16 +107,15 @@ export const SearchContextProvider: React.FC<{
// E.g. ?sort=display_name:desc maps to SearchSortOption.TITLE_ZA.
// Default sort by Most Relevant if there's search keyword(s), else by Recently Modified.
const defaultSearchSortOrder = searchKeywords ? SearchSortOption.RELEVANCE : SearchSortOption.RECENTLY_MODIFIED;
var sortStateManager: [SearchSortOption, React.Dispatch<React.SetStateAction<SearchSortOption>>];
if (skipUrlUpdate) {
sortStateManager = React.useState<SearchSortOption>(defaultSearchSortOrder);
} else {
sortStateManager = useStateWithUrlSearchParam<SearchSortOption>(
defaultSearchSortOrder,
'sort',
(value: string) => Object.values(SearchSortOption).find((enumValue) => value === enumValue),
(value: SearchSortOption) => value.toString(),
);
let sortStateManager = React.useState<SearchSortOption>(defaultSearchSortOrder);
const sortUrlStateManager = useStateWithUrlSearchParam<SearchSortOption>(
defaultSearchSortOrder,
'sort',
(value: string) => Object.values(SearchSortOption).find((enumValue) => value === enumValue),
(value: SearchSortOption) => value.toString(),
);
if (!skipUrlUpdate) {
sortStateManager = sortUrlStateManager;
}
const [searchSortOrder, setSearchSortOrder] = sortStateManager;
// SearchSortOption.RELEVANCE is special, it means "no custom sorting", so we
Expand Down
6 changes: 3 additions & 3 deletions src/search-manager/SearchSortWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { useIntl } from '@edx/frontend-platform/i18n';
import { Icon, Dropdown } from '@openedx/paragon';
import { Check, SwapVert } from '@openedx/paragon/icons';

import classNames from 'classnames';
import messages from './messages';
import { SearchSortOption } from './data/api';
import { useSearchContext } from './SearchManager';
import classNames from 'classnames';

export const SearchSortWidget = ({ iconOnly = false }: { iconOnly?: boolean }) => {
const intl = useIntl();
Expand Down Expand Up @@ -83,8 +83,8 @@ export const SearchSortWidget = ({ iconOnly = false }: { iconOnly?: boolean }) =
title={intl.formatMessage(messages.searchSortWidgetAltTitle)}
alt={intl.formatMessage(messages.searchSortWidgetAltTitle)}
variant="outline-primary"
className={classNames("dropdown-toggle-menu-items d-flex", {
"border-0": iconOnly
className={classNames('dropdown-toggle-menu-items d-flex', {
'border-0': iconOnly,
})}
size="sm"
>
Expand Down
1 change: 0 additions & 1 deletion src/search-manager/data/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ export const fetchContentByBlockId = async (
libraryKey: string,
blockId: string,
): Promise<CollectionHit | ContentHit> => {

const { results } = await client.multiSearch({
queries: [{
indexUid: indexName,
Expand Down

0 comments on commit 5f5ae2b

Please sign in to comment.