Skip to content

Commit

Permalink
Merge pull request #1438 from cityofaustin/18176-data-grid-files
Browse files Browse the repository at this point in the history
Migrate Files table to data grid
  • Loading branch information
chiaberry authored Oct 10, 2024
2 parents c053358 + fd1ce13 commit a50f7da
Show file tree
Hide file tree
Showing 6 changed files with 472 additions and 281 deletions.
3 changes: 2 additions & 1 deletion moped-editor/src/queries/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ export const PROJECT_ACTIVITY_LOG_DETAILS = gql`
export const PROJECT_FILE_ATTACHMENTS = gql`
query MopedProjectFiles($projectId: Int!) {
moped_project_files(
order_by: { created_at: desc }
where: { project_id: { _eq: $projectId }, is_deleted: { _eq: false } }
) {
project_file_id
Expand Down Expand Up @@ -682,7 +683,7 @@ export const PROJECT_FILE_ATTACHMENTS_UPDATE = gql`
$fileId: Int!
$fileName: String!
$fileType: Int!
$fileDescription: String!
$fileDescription: String
$fileUrl: String
) {
update_moped_project_files(
Expand Down
11 changes: 11 additions & 0 deletions moped-editor/src/utils/activityLogFormatters/mopedFilesActivity.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import AttachFileOutlined from "@mui/icons-material/AttachFileOutlined";
import { ProjectActivityLogTableMaps } from "../../views/projects/projectView/ProjectActivityLogTableMaps";

/** Fields which do not need to be rendered in the activity log */
const CHANGE_FIELDS_TO_IGNORE = [
"updated_by_user_id",
"created_by_user_id",
"created_at",
"updated_at",
];

export const formatFilesActivity = (change) => {
const entryMap = ProjectActivityLogTableMaps["moped_project_files"];

Expand Down Expand Up @@ -44,6 +52,9 @@ export const formatFilesActivity = (change) => {
// loop through fields to check for differences, push label onto changes Array
Object.keys(newRecord).forEach((field) => {
if (newRecord[field] !== oldRecord[field]) {
if (CHANGE_FIELDS_TO_IGNORE.includes(field)) {
return;
}
changes.push(entryMap.fields[field]?.label);
}
});
Expand Down
14 changes: 13 additions & 1 deletion moped-editor/src/views/projects/projectView/DataGridTextField.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import { useGridApiContext } from "@mui/x-data-grid-pro";
* @param {Integer} id - Data Grid row id
* @param {String} value - field value
* @param {String} field - name of field
* @param {Boolean} hasFocus - does this field have focus
* @param {String} helperText - optional helper text
* @param {Boolean} error - toggles error style in textfield
* @return {JSX.Element}
*/
const DataGridTextField = ({ id, value, field, hasFocus }) => {
const DataGridTextField = ({
id,
value,
field,
hasFocus,
helperText,
error,
}) => {
const apiRef = useGridApiContext();
const ref = React.useRef(null);

Expand Down Expand Up @@ -38,6 +48,8 @@ const DataGridTextField = ({ id, value, field, hasFocus }) => {
type="text"
value={value ?? ""}
onChange={handleChange}
helperText={!!helperText && helperText}
error={error}
/>
);
};
Expand Down
Loading

0 comments on commit a50f7da

Please sign in to comment.