Skip to content

Commit

Permalink
Fix coding issues on the grid UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hisorange committed Oct 23, 2022
1 parent 85c88b2 commit e9b2b98
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/modules/admin/view/style/antd.less
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@notification-bg: transparent;
@layout-body-background: transparent;

@btn-default-bg: #263238;
@btn-default-bg: #25272b;

.ant-notification > div {
@apply bg-midnight-800;
Expand Down
96 changes: 43 additions & 53 deletions src/modules/content/component/grid.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default function GridComponent({
setTriggerShowCreate,
}: Props) {
// Global state
const httpClient = useHttpClientSimple();
const [browserParams, setBrowserParams] = useSearchParams();
const client = useHttpClientSimple();
const [searchParams, setSearchParams] = useSearchParams();
const [schemas, setSchemas] = useRecoilState(schemasAtom);

const [apiUrl, setApiUrl] = useState(null);
Expand All @@ -82,11 +82,11 @@ export default function GridComponent({
// Grid content state
const [rows, setRows] = useState<RowLike[]>([]);
const [sorters, setSorters] = useState<[string, 'asc' | 'desc'][]>([]);
const [loading, setLoading] = useState(true);
const [isLoading, setIsLoading] = useState(true);
const [refetch, doRefetch] = useState<number>(() => Date.now());
const [fields, setFields] = useState<IField[]>([]);
const [selected, setSelected] = useState<RowLike[]>([]);
const [selectedKey, setSelectedKey] = useState<React.Key[]>([]);
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [filter, setFilter] = useState<string>(null);

// Auto refresh
Expand All @@ -103,10 +103,10 @@ export default function GridComponent({
}, [triggerShowCreate]);

useEffect(() => {
if (browserParams.has('page')) {
setPageCurr(parseInt(browserParams.get('page'), 10));
if (searchParams.has('page')) {
setPageCurr(parseInt(searchParams.get('page'), 10));
}
}, [browserParams]);
}, [searchParams]);

useEffect(() => {
if (refreshTimer) {
Expand All @@ -128,24 +128,17 @@ export default function GridComponent({

// Reset states
useEffect(() => {
setFields(cloneDeep(schema).fields.sort(GridTools.sortFields));
setFilter(null);
setShowFilter(false);
setSorters([]);
setSelected([]);
setRows([]);

setFieldWidth(schema.fields.map(f => [f.reference, 280]));

return () => {
setFilter(null);
setShowFilter(false);
setSorters([]);
setSelected([]);
};
}, [schema]);

useEffect(() => {
const _fields = cloneDeep(schema).fields;

let apiUrl = toRestRoute(schema, qb => {
// Pagination limit
qb.top(pageSize);
Expand All @@ -154,14 +147,14 @@ export default function GridComponent({
qb.skip(pageCurr * pageSize - pageSize);

// Sync with the pagination param
browserParams.set('page', pageCurr.toString());
searchParams.set('page', pageCurr.toString());
}

if (sorters) {
const orderBy = sorters
// Remove the hidden fields from sorting
.filter(
s => !_fields.find(FieldTool.fReference(s[0])).meta.grid.hidden,
s => !fields.find(FieldTool.fReference(s[0])).meta.grid.hidden,
)
.map(s => s.join(' '))
.join(', ');
Expand All @@ -172,7 +165,7 @@ export default function GridComponent({
}

qb.select(
_fields
fields
.filter(f => FieldTool.isPrimary(f) || !f.meta.grid.hidden)
.map(f => {
let fieldRef = f.reference;
Expand All @@ -185,8 +178,6 @@ export default function GridComponent({
// Query the replacement with the field value too.
if (relation) {
fieldRef = `${fieldRef},${relation.name}/${f.meta.grid.replace}`;
} else {
console.error('Missing relation?!', f);
}
}

Expand All @@ -202,21 +193,19 @@ export default function GridComponent({
apiUrl += `&${filter.substring(1)}`;
}

setBrowserParams(browserParams);

setFields(_fields.sort(GridTools.sortFields));
setSearchParams(searchParams);
setApiUrl(apiUrl + `&--artgen-no-cache=${refetch}`);
}, [pageCurr, pageSize, sorters, schema, refetch, filter]);
}, [pageCurr, pageSize, sorters, fields, refetch, filter]);

useEffect(() => {
if (apiUrl) {
setLoading(true);
setIsLoading(true);

const pks = schema.fields
.filter(FieldTool.isPrimary)
.map(f => f.reference);

httpClient
client
.get<IFindResponse>(apiUrl)
.then(reply => {
setRows(
Expand All @@ -232,15 +221,15 @@ export default function GridComponent({
message.error('Invalid request!');
})
.finally(() => {
setLoading(false);
setIsLoading(false);
});
}
}, [apiUrl]);

const doUpdate = record => {
setLoading(true);
setIsLoading(true);

httpClient
client
.patch<RowLike>(toRestRecordRoute(schema, record), record)
.then(() => {
doRefetch(Date.now());
Expand All @@ -250,7 +239,7 @@ export default function GridComponent({

return (
<>
<div className="flex my-2 bg-midnight-600 rounded-sm">
<div className="flex my-2 bg-midnight-700 rounded-sm">
<div className="shrink">
<Button.Group>
<Button
Expand Down Expand Up @@ -322,30 +311,28 @@ export default function GridComponent({
/>
}
icon={<DownOutlined />}
loading={loading}
disabled={loading}
loading={isLoading}
disabled={isLoading}
onClick={() => doRefetch(Date.now())}
>
{refreshInterval ? (
<ClockCircleOutlined className="text-green-500" />
) : undefined}
Refresh
</Dropdown.Button>
<Button
icon={<DatabaseOutlined />}
onClick={() => setEditSchema(schema)}
>
Schemantics
</Button>
</Button.Group>
</div>

<div className="shink ml-1">
<Button
icon={<DatabaseOutlined />}
onClick={() => setEditSchema(schema)}
>
Schemantics
</Button>
</div>

<div className="grow ml-1 text-right">
<Button.Group>
<Button
disabled
icon={<DownloadOutlined />}
onClick={() => {
message.warning('To be implemented');
Expand All @@ -355,6 +342,7 @@ export default function GridComponent({
</Button>

<Button
disabled
icon={<UploadOutlined />}
onClick={() => {
message.warning('To be implemented');
Expand Down Expand Up @@ -396,12 +384,12 @@ export default function GridComponent({
icon={<QuestionCircleOutlined />}
onConfirm={() => {
// Lock the interactions
setLoading(true);
setIsLoading(true);

// Concurrent delete
Promise.all(
selected.map(r =>
httpClient.delete(toRestRecordRoute(schema, r)),
client.delete(toRestRecordRoute(schema, r)),
),
).then(() => {
notification.warn({
Expand All @@ -411,7 +399,7 @@ export default function GridComponent({

doRefetch(Date.now());
setSelected([]);
setSelectedKey([]);
setSelectedRowKeys([]);
});
}}
>
Expand All @@ -437,7 +425,7 @@ export default function GridComponent({
rowKey="__ag_rowkey"
dataSource={rows}
pagination={false}
loading={loading}
loading={isLoading}
onRow={(record, idx) => {
return {
onDoubleClick: () => setShowEdit(record),
Expand All @@ -446,10 +434,10 @@ export default function GridComponent({
rowSelection={{
type: 'checkbox',
fixed: 'left',
selectedRowKeys: selectedKey,
selectedRowKeys: selectedRowKeys,
onChange: (keys, selectedRows) => {
setSelected(selectedRows);
setSelectedKey(keys);
setSelectedRowKeys(keys);
},
selections: [
Table.SELECTION_ALL,
Expand Down Expand Up @@ -489,7 +477,8 @@ export default function GridComponent({
}}
bordered
>
{fields
{cloneDeep(schema)
.fields.sort(GridTools.sortFields)
.filter(f => !f.meta.grid.hidden)
.map((field, idx) => {
let dataIndex: string | string[] = field.reference;
Expand All @@ -509,8 +498,6 @@ export default function GridComponent({
r.reference === relation.target,
)
.fields.find(r => r.reference == field.meta.grid.replace);
} else {
console.error('Missing relation x2?!', field);
}
}

Expand Down Expand Up @@ -540,7 +527,10 @@ export default function GridComponent({
align = 'center';
}

const width = fieldWidth.find(r => r[0] === field.reference)[1];
const _fieldWidth = fieldWidth.find(
r => r[0] === field.reference,
);
const width = _fieldWidth ? _fieldWidth[1] : 120;

return (
<Column
Expand Down Expand Up @@ -748,7 +738,7 @@ export default function GridComponent({
)}
</div>

<div className="mt-4 w-full bg-midnight-600 py-1 px-4 rounded-md text-right">
<div className="mt-4 w-full bg-midnight-700 py-1 px-4 rounded-md text-right">
<Pagination
total={total}
defaultCurrent={pageCurr}
Expand Down
4 changes: 0 additions & 4 deletions src/modules/content/util/relation-lookup.form-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export const createCustomRelationLookupFormWidget = (
remoteSchema: ISchema,
) => {
return props => {
console.log('Calling with props', relationName, props);

const httpClient = useHttpClientSimple();
const [options, setOptions] = useState<{ label: string; value: string }[]>(
[],
Expand Down Expand Up @@ -63,8 +61,6 @@ export const createCustomRelationLookupFormWidget = (
});
};

console.log('Set auto complete to ---->', props.value);

return (
<Select
options={options}
Expand Down
7 changes: 0 additions & 7 deletions src/modules/flow/components/flowboard/flowboard.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,11 @@ export default function FlowBoardComponent() {
const onDragOver = event => {
event.preventDefault();
event.dataTransfer.dropEffect = 'move';

console.log('Drag over');
};

const onDrop = (event: DragEvent) => {
const bounds = wrapper.current.getBoundingClientRect();

console.log('Drop over');

if (event.dataTransfer.getData('application/reactflow')) {
event.preventDefault();

Expand Down Expand Up @@ -324,9 +320,6 @@ export default function FlowBoardComponent() {
setFocusedElementId(null);
}
}}
onChange={() => {
console.log('Changed');
}}
nodeTypes={customNodes}
defaultZoom={1.5}
edgeTypes={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ export default function FlowBoardNodeConfig({

return newElements;
});

console.log('node config changed');
}}
/>
</Descriptions.Item>
Expand Down Expand Up @@ -232,8 +230,6 @@ export default function FlowBoardNodeConfig({

return newElements;
});

console.log('node config changed');
}}
>
<></>
Expand Down
2 changes: 0 additions & 2 deletions src/modules/http/lambda/http-request.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ export class HttpRequestLambda implements ILambda {
timeout: config.timeout,
};

console.log(request);

const response = await client.request(request);

return {
Expand Down
7 changes: 1 addition & 6 deletions src/modules/page/component/editor.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default function PageEditorComponent() {
if (editor) {
editor.StorageManager.add('artgen-storage', {
load(keys, onDone, onErr) {
console.log('Loading page', keys);
const defaultObject = {};

for (const key of keys) {
Expand All @@ -54,8 +53,6 @@ export default function PageEditorComponent() {
.catch(err => onErr(err));
},
store(content, onDone, onErr) {
console.log('Storing page', content);

setPage(oldState => {
const newState = cloneDeep(oldState);
newState.content = content;
Expand All @@ -73,9 +70,7 @@ export default function PageEditorComponent() {
});

editor.load();
editor.on('update', ar => {
console.log('update', ar);
});
editor.on('update', ar => {});

document.getElementById('page-editor').style.height = '100vh';
}
Expand Down

0 comments on commit e9b2b98

Please sign in to comment.