Skip to content

Commit

Permalink
Make dropdown go up for last item in list
Browse files Browse the repository at this point in the history
  • Loading branch information
farhatahmad committed Nov 2, 2023
1 parent 29c3a6f commit cc8df3e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ input.search-bar {
box-shadow: 0 0 0 0.25rem var(--brand-color-light) !important;
}
&::after {
display: none;
display: none !important;
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/javascript/components/recordings/RecordingRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import SimpleSelect from '../shared_components/utilities/SimpleSelect';

// TODO: Amir - Refactor this.
export default function RecordingRow({
recording, visibilityMutation: useVisibilityAPI, deleteMutation: useDeleteAPI, adminTable,
recording, visibilityMutation: useVisibilityAPI, deleteMutation: useDeleteAPI, adminTable, dropUp,
}) {
const { t } = useTranslation();

Expand Down Expand Up @@ -104,6 +104,7 @@ export default function RecordingRow({
<td className="border-0">
<SimpleSelect
defaultValue={recording.visibility}
dropUp={dropUp}
>
<Dropdown.Item
key="Public/Protected"
Expand Down Expand Up @@ -205,6 +206,7 @@ export default function RecordingRow({

RecordingRow.defaultProps = {
adminTable: false,
dropUp: false,
};

RecordingRow.propTypes = {
Expand All @@ -227,4 +229,5 @@ RecordingRow.propTypes = {
visibilityMutation: PropTypes.func.isRequired,
deleteMutation: PropTypes.func.isRequired,
adminTable: PropTypes.bool,
dropUp: PropTypes.bool,
};
12 changes: 9 additions & 3 deletions app/javascript/components/recordings/RecordingsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ export default function RecordingsList({
)))
}
{
(recordings?.data?.length > 0 && recordings?.data?.map((recording) => (
<RoomsRecordingRow key={recording.id} recording={recording} adminTable={adminTable} />
(recordings?.data?.length > 0 && recordings?.data?.map((recording, idx) => (
<RoomsRecordingRow
key={recording.id}
recording={recording}
adminTable={adminTable}
dropUp={(recordings?.meta?.page || 0) * (recordings?.meta?.items || 0) - 1 === idx}
/>
)))
}
</tbody>
Expand All @@ -99,7 +104,7 @@ export default function RecordingsList({
}

RecordingsList.defaultProps = {
recordings: { data: [], meta: { page: 1, pages: 1 } },
recordings: { data: [], meta: { page: 1, pages: 1, items: 3 } },
recordingsProcessing: 0,
searchInput: '',
adminTable: false,
Expand All @@ -125,6 +130,7 @@ RecordingsList.propTypes = {
meta: PropTypes.shape({
page: PropTypes.number,
pages: PropTypes.number,
items: PropTypes.number,
}),
}),
isLoading: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,21 @@ import useUpdateRecordingVisibility from '../../../hooks/mutations/recordings/us
import useDeleteRecording from '../../../hooks/mutations/recordings/useDeleteRecording';
import RecordingRow from '../RecordingRow';

export default function RoomsRecordingRow({ recording, adminTable }) {
export default function RoomsRecordingRow({ recording, adminTable, dropUp }) {
return (
<RecordingRow
adminTable={adminTable}
recording={recording}
visibilityMutation={useUpdateRecordingVisibility}
deleteMutation={useDeleteRecording}
dropUp={dropUp}
/>
);
}

RoomsRecordingRow.defaultProps = {
adminTable: false,
dropUp: false,
};

RoomsRecordingRow.propTypes = {
Expand All @@ -51,4 +53,5 @@ RoomsRecordingRow.propTypes = {
map: PropTypes.func,
}).isRequired,
adminTable: PropTypes.bool,
dropUp: PropTypes.bool,
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import React from 'react';
import PropTypes from 'prop-types';
import { ChevronDownIcon } from '@heroicons/react/20/solid';

export default function SimpleSelect({ defaultValue, children }) {
export default function SimpleSelect({ defaultValue, dropUp, children }) {
// Get the currently selected option and set the dropdown toggle to that value
const defaultString = children?.filter((item) => item.props.value === defaultValue)[0];

return (
<Dropdown className="simple-select">
<Dropdown className="simple-select" drop={dropUp ? 'up' : undefined}>
<Dropdown.Toggle>
{ defaultString?.props?.children }
<ChevronDownIcon className="hi-s float-end" />
Expand All @@ -38,10 +38,12 @@ export default function SimpleSelect({ defaultValue, children }) {

SimpleSelect.defaultProps = {
defaultValue: '',
dropUp: false,
children: undefined,
};

SimpleSelect.propTypes = {
defaultValue: PropTypes.string,
dropUp: PropTypes.bool,
children: PropTypes.arrayOf(PropTypes.element),
};

0 comments on commit cc8df3e

Please sign in to comment.