Skip to content

Commit

Permalink
Merge pull request #20 from knovator/sequencing-redesign_style-updates
Browse files Browse the repository at this point in the history
Sequencing redesign and Style updates
  • Loading branch information
chavda-bhavik committed Jul 27, 2022
2 parents a794ee8 + bd27fe2 commit 9148847
Show file tree
Hide file tree
Showing 21 changed files with 448 additions and 250 deletions.
12 changes: 6 additions & 6 deletions dts.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
const postcss = require('rollup-plugin-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
// const cssnano = require('cssnano');

module.exports = {
rollup(config, options) {
config.plugins.push(
postcss({
plugins: [
autoprefixer(),
cssnano({
preset: 'default',
}),
// cssnano({
// preset: 'default',
// }),
],
// inject: false,
// only write out CSS for the first bundle (avoids pointless extra files):
extract: !!options.writeMeta,
})
);
}),
)
return config;
},
};
5 changes: 3 additions & 2 deletions example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const App = () => {
baseUrl="http://localhost:8080"
token="ABCD" // token={getToken()}
>
<h2>Master</h2>
{/* <h2>Master</h2>
<Master
explicitForm
permissions={{ add: false, list: true, update: true, destroy: true }}
Expand All @@ -21,18 +21,19 @@ const App = () => {
<Master.Table />
<Master.Pagination />
</Master> */}
{/* <Master.FormWrapper>
{(data) => (
data.open ? <p onClick={data.onClose}>Drawer</p> : null
)}
</Master.FormWrapper> */}
</Master>

<h2>Sub-Master</h2>
<Master>
<Master.Lister />
<SubMaster>
<SubMaster.Table />
<SubMaster.Pagination />
</SubMaster>
</Master>
</Provider>
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
},
"jest": {
"testEnvironment": "jsdom",
"setupFilesAfterEnv": ["./jest.setup.ts"]
"setupFilesAfterEnv": [
"./jest.setup.ts"
]
},
"devDependencies": {
"@knovator/api": "^0.0.10",
Expand All @@ -63,7 +65,6 @@
"@testing-library/react": "^13.3.0",
"@tsconfig/create-react-app": "^1.0.2",
"@tsconfig/recommended": "^1.0.1",
"@types/react-beautiful-dnd": "^13.1.2",
"@types/react-dom": "^18.0.6",
"@types/react-dropzone": "^5.1.0",
"@types/react-table": "^7.7.12",
Expand All @@ -75,7 +76,6 @@
"msw": "^0.42.3",
"postcss": "^8.4.14",
"react": "^18.2.0",
"react-beautiful-dnd": "^13.1.0",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.1",
"react-hook-form": "^7.32.2",
Expand Down Expand Up @@ -105,5 +105,9 @@
"react-dom": ">=17.0.1",
"react-hook-form": "^7.32.2",
"react-table": "^7.8.0"
},
"dependencies": {
"@types/react-beautiful-dnd": "^13.1.2",
"react-beautiful-dnd": "^13.1.0"
}
}
8 changes: 4 additions & 4 deletions src/api/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const apiList = {
}),
IMAGE_REMOVE: ({ id }: API_INPUT_TYPE) => ({
url: `files/${id}/delete`,
method: 'DELETE'
method: "DELETE",
}),
LIST: ({ module }: API_INPUT_TYPE) => ({
url: `admin/${module}/list`,
Expand All @@ -24,10 +24,10 @@ const apiList = {
url: `admin/${module}/soft-delete`,
method: "PUT",
}),
SEQUENCE: ({ module, id }: API_INPUT_TYPE) => ({
url: `admin/${module}/partial-update/sequence/${id}`,
SEQUENCE: ({ module }: API_INPUT_TYPE) => ({
url: `admin/${module}/partial-update/sequence`,
method: "PATCH",
})
}),
}

export default apiList
29 changes: 14 additions & 15 deletions src/components/Common/DNDTable/DNDTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ const DNDTable = ({
loader,
loading,
onMove,
dragEnable = false,
}: TableProps) => {
const getSortConfigClassName = useCallback(
(accessor: string, up = true) => {
if (!sortConfig || accessor !== sortConfig[0]) return "kms_sort-inactive"
if (!sortConfig || accessor !== sortConfig[0] || dragEnable) return "kms_sort-inactive"
else {
if (up && sortConfig[1] === SORT_ASCENDING) return ""
else if (!up && sortConfig[1] === SORT_DESCENDING) return ""
else return "kms_sort-inactive"
}
},
[sortConfig],
[sortConfig, dragEnable],
)
const sortConfigRenderer = useCallback(
(accessor: string) => {
if (!sortable || EXCLUDE_SORT_COLUMNS.includes(String(accessor).toLocaleLowerCase())) return null
if (!sortable || EXCLUDE_SORT_COLUMNS.includes(String(accessor).toLocaleLowerCase()) || dragEnable)
return null
return (
<div className="kms_sort-wrapper">
<span data-testid className={getSortConfigClassName(accessor, true)}>
Expand All @@ -49,13 +51,8 @@ const DNDTable = ({
[setSortConfig, sortConfig],
)
const handleDragEnd = (results: DropResult) => {
if (!results.destination) return
const temporaryData = [...data]
const [selectedRow] = temporaryData.splice(results.source.index, 1)
// const [row] = data.splice(results.destination.index, 1)
const seq = results.destination.index + 1
// temporaryData.splice(results.destination.index, 0, selectedRow)
if (typeof onMove === "function") onMove(selectedRow.id || selectedRow._id, seq)
if (!results.destination || !onMove) return
onMove(results.source.index, results.destination.index)
}
const { getTableProps, getTableBodyProps, headerGroups, prepareRow, rows } = useTable({
// @ts-ignore
Expand Down Expand Up @@ -96,15 +93,16 @@ const DNDTable = ({
{...getTableBodyProps()}
{...provided.droppableProps}
>
{rows.length > 0
? rows.map((row, i) => {
{rows.length > 0 ? (
rows.map((row, i) => {
prepareRow(row)
return (
// @ts-ignore
<Draggable
draggableId={row.original.id || row.original._id || row.id}
key={row.original.id || row.original._id}
index={i}
isDragDisabled={!dragEnable}
>
{(provided) => (
<tr
Expand All @@ -128,10 +126,11 @@ const DNDTable = ({
</Draggable>
)
})
: (<tr>
) : (
<tr>
<td colSpan={columns?.length || 0}>No data found</td>
</tr>)
}
</tr>
)}
</tbody>
)}
</Droppable>
Expand Down
12 changes: 6 additions & 6 deletions src/components/Common/DeleteModal/DeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ const DeleteModal = ({
}, [formState])
return (
<Modal open={formState === "DELETE"} onClose={onClose} title="Confirmation Required">
<div className="py-2 px-4 rounded-lg flex items-center gap-3 text-black text-sm bg-red-200">
<div className="kms_delete-header">
<p>
{permanentlyDelete} <b>{itemData?.name}</b>
</p>
</div>
<div className="mt-3 text-black text-sm">
<div className="kms_delete-content">
<p>{lossOfData}</p>
<p className="mt-3">
<p className="kms_delete-note">
{pleaseType} <b className="text-black font-bold">{itemData?.name}</b> {toProceedOrCancel}
</p>
</div>
<div className="mt-3 flex flex-row gap-3">
<div className="kms_delete-actions">
<Input
placeholder="Type Here"
className="w-full flex-grow"
className="kms_delete-input"
value={userInput}
onChange={(e) => setUserInput(e.target.value)}
/>
<div className="col-span-3">
<div className="kms_delete-buttons">
<Button label={confirm} disabled={userInput !== itemData?.name} onClick={onConfirmDelete} />
</div>
</div>
Expand Down
166 changes: 82 additions & 84 deletions src/components/Common/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,84 +1,82 @@
import React from "react"
import Button from "../Button"

const Pagination = ({
totalPages,
currentPage,
pageSize,
setPageSize,
setCurrentPage,
totalRecords,
limits,
pageLabel = "Page",
nextLabel = "Next",
previousLabel = "Previous",
}: PaginationProps) => {
const pageHandler = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
// @ts-ignore
setCurrentPage(Number.parseInt(e.target.value, 10) || 1)
}
}
const handleNumbers = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (["e", "+", "-"].includes(e.key)) {
e.preventDefault()
}
}
const pageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value && Number(e.target.value) <= totalPages && e.target.value !== "0") {
setCurrentPage(Number.parseInt(e.target.value, 10))
}
}
return (
<div className="kms_pagination">
<div>
{(currentPage - 1) * pageSize + 1} - {Math.min(currentPage * pageSize, totalRecords)} of {totalRecords}
</div>
<div className="kms_pagination-actions">
<Button
size="sm"
label={previousLabel}
onClick={() => setCurrentPage(currentPage - 1)}
disabled={currentPage - 1 === 0}
/>
<div className="kms_pagination-pager">
{pageLabel}
<input
className="kms_input kms_input-sm w-10"
maxLength={3}
pattern="([0-9]|[0-9]|[0-9])"
type="number"
onKeyDown={handleNumbers}
onKeyPress={pageHandler}
value={currentPage}
onChange={pageChange}
/>
/ {totalPages}
</div>
{Array.isArray(limits) ? (
<select
value={pageSize}
className="kms_input kms_input-sm"
onChange={(e) => setPageSize(Number(e.target.value))}
>
{limits.map((pageSize) => (
<option key={pageSize} value={pageSize}>
Show {pageSize}
</option>
))}
</select>
) : null}
<Button
size="sm"
label={nextLabel}
onClick={() => setCurrentPage(currentPage + 1)}
disabled={currentPage === totalPages}
/>
</div>
</div>
)
}

Pagination.type = "Pagination"

export default Pagination
import React from "react"
import Button from "../Button"

const Pagination = ({
totalPages,
currentPage,
pageSize,
setPageSize,
setCurrentPage,
totalRecords,
limits,
pageLabel = "Page",
nextLabel = "Next",
previousLabel = "Previous",
}: PaginationProps) => {
const pageHandler = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter") {
// @ts-ignore
setCurrentPage(Number.parseInt(e.target.value, 10) || 1)
}
}
const handleNumbers = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (["e", "+", "-"].includes(e.key)) {
e.preventDefault()
}
}
const pageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.value && Number(e.target.value) <= totalPages && e.target.value !== "0") {
setCurrentPage(Number.parseInt(e.target.value, 10))
}
}
return (
<div className="kms_pagination">
<div>
{(currentPage - 1) * pageSize + 1} - {Math.min(currentPage * pageSize, totalRecords)} of {totalRecords}
</div>
<div className="kms_pagination-actions">
<Button
label={previousLabel}
onClick={() => setCurrentPage(currentPage - 1)}
disabled={currentPage - 1 === 0}
/>
<div className="kms_pagination-pager">
{pageLabel}
<input
className="kms_input kms_input-sm w-10"
maxLength={3}
pattern="([0-9]|[0-9]|[0-9])"
type="number"
onKeyDown={handleNumbers}
onKeyPress={pageHandler}
value={currentPage}
onChange={pageChange}
/>
/ {totalPages}
</div>
{Array.isArray(limits) ? (
<select
value={pageSize}
className="kms_input kms_input-sm"
onChange={(e) => setPageSize(Number(e.target.value))}
>
{limits.map((pageSize) => (
<option key={pageSize} value={pageSize}>
Show {pageSize}
</option>
))}
</select>
) : null}
<Button
label={nextLabel}
onClick={() => setCurrentPage(currentPage + 1)}
disabled={currentPage === totalPages}
/>
</div>
</div>
)
}

Pagination.type = "Pagination"

export default Pagination
Loading

0 comments on commit 9148847

Please sign in to comment.